?
Solved

Large number arithmetic

Posted on 2002-07-07
54
Medium Priority
?
449 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 1600 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 46

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

770 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