Solved

Large number arithmetic

Posted on 2002-07-07
54
432 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
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

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

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

856 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