Large numbers in javascript

C

CFonville

I was wondering if there is any way to store large numbers in a
variable? With this simple script:

var bigpi =
1234567890123456789012345678901234567890123456789012345678901234567890;
alert(bigpi);

I only get the first 17 digits and an exponent. Is there any way to
save very large numbers to a variable? I would really like to be able
to manipulate pi to a large number of decimal places (say 1,000). Is
there any way to do that? Thank you in advance,
Chris
 
T

Thomas 'PointedEars' Lahn

I was wondering if there is any way to store large numbers in a
variable? With this simple script:

var bigpi =
1234567890123456789012345678901234567890123456789012345678901234567890;
alert(bigpi);

I only get the first 17 digits and an exponent. Is there any way to
save very large numbers to a variable? I would really like to be able
to manipulate pi to a large number of decimal places (say 1,000). Is
there any way to do that?

Please do research before you post here.


(I am currently working on a Float prototype that allows for almost
infinite precision.)


PointedEars
 
V

VK

I was wondering if there is any way to store large numbers in a
variable? With this simple script:

var bigpi =
1234567890123456789012345678901234567890123456789012345678901234567890;
alert(bigpi);

I only get the first 17 digits and an exponent. Is there any way to
save very large numbers to a variable? I would really like to be able
to manipulate pi to a large number of decimal places (say 1,000). Is
there any way to do that? Thank you in advance,

There is a throughout thread on the subject here:

<http://groups.google.com/group/comp..._frm/thread/38d21acb4d4509ce/75a560a269f6f2dd>

In the particular read the summary of default options at:
<http://groups.google.com/group/comp...4509ce/75a560a269f6f2dd?#doc_3833df1762d81fee>

If you reeeally need extensive BigMath operations for your project then
JavaScript is probably not the right tool for the job. Notice though:
<http://groups.google.com/group/comp...9f6f2dd?q=BigInt&rnum=1&#doc_75a560a269f6f2dd>
 
D

Dr John Stockton

JRS: In article <[email protected]>,
dated Mon, 3 Apr 2006 13:28:21 remote, seen in
news:comp.lang.javascript, (e-mail address removed) posted :
I was wondering if there is any way to store large numbers in a
variable? With this simple script:

Don't worry about Lahn's ravings; he has psychological problems. A
news-group is for discussion; and if everyone refers only to old
material there will never be any new ideas.

You have found (as reading the newsgroup FAQ and its links would have
told you) that values of type Number gave limited resolution : they are
IEEE Doubles.

Large numbers can be readily stored, in any base from 2 to 64 and
higher, in strings; but they are then hard to manipulate.

Large numbers can be stored as arrays of digits, in any base from 2 up
to 2^53, though 2^26 is the practical limit. One can then write readily
code to process them just as you learned in school, or should have.
I've implemented such a system, for integers, in Pascal/Delphi
(longcalc, via <URL:http://www.merlyn.demon.co.uk/programs.00index.htm>)
- and coded it to calculate pi using the BBP method.

Note that you'll probably get faster running in a language in which code
is compiled and optimised before delivery; you should try representative
code in various language implementations before deciding.
 

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

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,218
Latest member
JolieDenha

Latest Threads

Top