By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,086 Members | 1,442 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,086 IT Pros & Developers. It's quick & easy.

Large numbers in javascript

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

var bigpi =
12345678901234567890123456789012345678901234567890 12345678901234567890;
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

Apr 3 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
CF*******@gmail.com wrote:
I was wondering if there is any way to store large numbers in a
variable? With this simple script:

var bigpi =
12345678901234567890123456789012345678901234567890 12345678901234567890;
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.

news:11*********************@j33g2000cwa.googlegro ups.com

(I am currently working on a Float prototype that allows for almost
infinite precision.)
PointedEars
Apr 3 '06 #2

P: n/a
VK

CF*******@gmail.com wrote:
I was wondering if there is any way to store large numbers in a
variable? With this simple script:

var bigpi =
12345678901234567890123456789012345678901234567890 12345678901234567890;
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.lang.javascript/browse_frm/thread/38d21acb4d4509ce/75a560a269f6f2dd>

In the particular read the summary of default options at:
<http://groups.google.com/group/comp.lang.javascript/tree/browse_frm/thread/38d21acb4d4509ce/605c4236958ed554?rnum=31&_done=%2Fgroup%2Fcomp.lan g.javascript%2Fbrowse_frm%2Fthread%2F38d21acb4d450 9ce%2F75a560a269f6f2dd%3F#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.lang.javascript/tree/browse_frm/thread/38d21acb4d4509ce/75a560a269f6f2dd?rnum=21&q=BigInt&_done=%2Fgroup%2 Fcomp.lang.javascript%2Fbrowse_frm%2Fthread%2F38d2 1acb4d4509ce%2F75a560a269f6f2dd%3Fq%3DBigInt%26rnu m%3D1%26#doc_75a560a269f6f2dd>

Apr 3 '06 #3

P: n/a
JRS: In article <11*********************@i40g2000cwc.googlegroups. com>,
dated Mon, 3 Apr 2006 13:28:21 remote, seen in
news:comp.lang.javascript, CF*******@gmail.com 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.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Apr 4 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.