Solved

# Large number arithmetic

Posted on 2002-07-07
440 Views
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
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
• 3
• 2
• 2
• +1

LVL 75

Expert Comment

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

ID: 7136323
What is .NET?
0

LVL 75

Expert Comment

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

LVL 75

Expert Comment

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

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

ID: 7136382

0

Author Comment

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

ID: 7137679
toff,

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

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

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â€¦
###### Suggested Courses
Course of the Month8 days, left to enroll