Solved

Large number arithmetic

Posted on 2002-07-07
54
419 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
  • 3
  • 2
  • 2
  • +1
54 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
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
Comment Utility
What is .NET?
0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
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

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

Anthony
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 15

Accepted Solution

by:
ameba earned 400 total points
Comment Utility
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
Comment Utility
And yes, finalize your questions!!!

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

Author Comment

by:toff_in_sydney
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now