Calculations on LARGE numbers

D

Dr John Stockton

JRS: In article <[email protected]>, dated Mon, 13
Mar 2006 17:50:35 remote, seen in
pt said:
I find that VBScript can represent 2^48 and 2^49 exactly, but not 2^50.

I see no way to even break up your number into high and low parts, much less
do math with them. For example, if I attempt to represent your large number
as:

x = a * (2^42) + b

I can possibly find a, but not b.

a = IntegerPart(x/(2^42))

where IntegerPart must be coded, since CInt has no chance of working. Then

b = x - a * (2^42)

but VBScript cannot represent a * (2^42) exactly, so b is wrong. I see no
chance of doing long division if I cannot even break up the number as above.
VBScript cannot do any math exactly where any intermediate value is greater
than about 2^48.


Eschew excessive quotation.


You have not thought the matter through sufficiently.

Clearly, given a need to calculate 123456789 * 987654321, one can break
those numbers into their individual digits, and long-multiply them as
you should have been taught at school. My longcalc.pas does that, using
digits base 2..16.

One can also split them as 123 456 789 * 987 654 321, effectively base
1000, to do the job quicker. AIUI, ordinary integers in VBscript are
held in IEEE Doubles, so that one could work to base 2^26 with digit-
products up to 2^52. Base 1000000 easily fits.

The large numbers cannot, of course, be supplied accurately as
individual VBS numbers; strings or arrays are needed.

There's a trick for speeding multiplication of large numbers; it's in
ALGORITHMICS by Brassard & Bratley, ISBN 0-13-023169-X
 
R

Richard Mueller

Dr John Stockton said:
JRS: In article <[email protected]>, dated Mon, 13
Mar 2006 17:50:35 remote, seen in


Eschew excessive quotation.


You have not thought the matter through sufficiently.

Clearly, given a need to calculate 123456789 * 987654321, one can break
those numbers into their individual digits, and long-multiply them as
you should have been taught at school. My longcalc.pas does that, using
digits base 2..16.

One can also split them as 123 456 789 * 987 654 321, effectively base
1000, to do the job quicker. AIUI, ordinary integers in VBscript are
held in IEEE Doubles, so that one could work to base 2^26 with digit-
products up to 2^52. Base 1000000 easily fits.

The large numbers cannot, of course, be supplied accurately as
individual VBS numbers; strings or arrays are needed.

There's a trick for speeding multiplication of large numbers; it's in
ALGORITHMICS by Brassard & Bratley, ISBN 0-13-023169-X


--
© John Stockton, Surrey, UK. [email protected] Delphi 3 Turnpike 4
©
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics &
links;
<URL:http://www.bancoems.com/CompLangPascalDelphiMisc-MiniFAQ.htm>
clpdmFAQ;
<URL:http://www.borland.com/newsgroups/guide.html> Guidelines

John,

I was saying I couldn't work it out breaking the number up into high and low
2^42 parts. I think you are correct that each "digit" must be 2^26. That is,
the number must be broken up into 26 bit parts (or less). In the poster's
example, it cannot be done in 2 parts or even 3. The big number would have
to be broken up into 4 26-bit parts. Rather than inventing that wheel, I'd
suggest your program.
 
D

de Graff

If it is a one-time thing you can download the free version of Dolphin
SmallTalk which handles numbers of any size. For example you can evaluate

1000 factorial.

in a fraction of a second. If you need to program something you can use Java
with the BigInteger class.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top