473,395 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Large numbers in javascript

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
3 8179
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: koray | last post by:
hi, i need to show large numbers seperated by commas. since i'm using variables from speedscript, i cannot know their values, since the user should enter them. how should i code to show these...
3
by: Alex Vinokur | last post by:
Dann Corbit has implemented function int ilog2 (unsigned long) at http://groups.google.com/groups?selm=lkPa4.2165%24I41.1498%40client Is exist a similar C++-function for very large numbers,...
10
by: Tuvas | last post by:
I've been thinking about writing a program to generate the world's largest prime numbers, just for the fun of it. This would require being able to hold an 8000000 digit number into memory (25...
1
by: Jonathan | last post by:
My app is trying to multiply and add some very large numbers. Here is the line that I am am having problems with: Seconds = CDbl(PartB) * CDbl(16777216) Seconds is a double and PartB is a...
17
by: Sri | last post by:
How do you add an n-bit number in C? Regards, Sri
22
by: Frinton | last post by:
Hi, I am trying to do some calculations on large numbers (ie 7,768,489,957,892,578,474,792,094 / 12,280) and no matter what I do it doesn't get it quite right. Its always somewhere between 10...
24
by: Frank Swarbrick | last post by:
We have a batch process that inserts large numbers (100,000 - 1,000,000) of records into a database each day. (DL/I database.) We're considering converting it to a DB2 table. Currently we have...
2
by: Todd.Branchflower | last post by:
Hey everyone, I am new to c++ and the group and would appreciate your help. I was doing a problem on projecteuler.net in which you had to find the largest factor of an extremely large number. ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.