Solved

Large number arithmetic

Posted on 2002-07-07
54
440 Views
Last Modified: 2010-05-02
Is there any way of doing large number arithmetic in VB, apart from using singles, doubles, etc? I'm thinking of some sort of set of library functions or something...I need to do some simple arithmetic (addition, multiplication, subtraction) on numbers that are larger than 32 bits, and I don't want to use singles, doubles, etc. Any ideas?
0
Comment
Question by:toff_in_sydney
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
54 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7136317
None that I know of (unless you want to use .NET), but you may want to consider using the Currency data type.  This is essentially a 8 byte integer (albeit scaled) and so does not use the floating-point processor.

Anthony
0
 

Author Comment

by:toff_in_sydney
ID: 7136323
What is .NET?
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7136325
Also, when you get a chance please maintain these open questions:
PaintPicture Date: 04/30/2002 05:02AM PST  
http://www.experts-exchange.com/visualbasic/Q_20295350.html
BitBlt in VB Date: 04/30/2002 03:24AM PST
http://www.experts-exchange.com/visualbasic/Q_20295317.html

Anthony
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7136328
>>What is .NET? <<
As in Microsoft's Visual Studio.NET.  Surely you have hear of this, even in Australia <g>?

Anthony
0
 
LVL 15

Accepted Solution

by:
ameba earned 400 total points
ID: 7136342
The most efficient math type is Double - 64-bits of precision.  That's 15-16 correct digits.
Sometimes it can be even 80-bits, if you use "Allow Unrounded Floating Point Operations" compiler option.

Here is how to use Decimal subtype of Variant, which gives 128-bits precission:

Private Sub Form_Click()
    Dim x As Double, y As Variant
    y = CDec(0) ' make variant a Decimal subtype
   
    x = 1.0000001000001
    y = CDec(x)
    Print "Double:  " & x * x
    Print "Decimal: " & y * y
End Sub
0
 
LVL 15

Expert Comment

by:ameba
ID: 7136382
And yes, finalize your questions!!!

If something is not clear, ask for more info.
0
 

Author Comment

by:toff_in_sydney
ID: 7136445
Sorry, I thought they all WERE finalized...they should be now.

ameba, the Decimal subtype is a 128 bit number? ie, it can handle numbers up to 2^128? Without rounding? How efficient are calculations using it, compared to Double?
0
 
LVL 45

Expert Comment

by:aikimark
ID: 7137679
toff,

One more thing about Decimal datatypes...they are only 96-bit entities, not 128-bits (as the selected answer states).

From the online help:
Decimal variables are stored as 96-bit (12-byte) unsigned integers scaled by a variable power of 10. The power of 10 scaling factor specifies the number of digits to the right of the decimal point, and ranges from 0 to 28. With a scale of 0 (no decimal places), the largest possible value is +/-79,228,162,514,264,337,593,543,950,335. With a 28 decimal places, the largest value is +/-7.9228162514264337593543950335 and the smallest, non-zero value is +/-0.0000000000000000000000000001.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question