On Thu, 23 Feb 2012 21:16:04 +0000, Tom Anderson
<twic@urchin.earth.li> wrote:
On Wed, 22 Feb 2012, Gene Wirchenko wrote:
[snip]
I have been working with fixed-point arithmetic in JavaScript so
that I can add dollar amounts exactly. Maybe OP has something similar
in mind, though with the number of digits of precision that he wants
before the decimal point, I hope it is not currency-related.
It is currency-related. What's wrong with that?
You are dealing with monstrously-large numbers. National debts
or something similar?
If you only needed up to fifteen [decimal] digits of precision total, you
could use IEEE 754 64-bit floating point format and store integers.
They will be stored exactly. IEEE 754 is the only number format that
JavaScript exposes for variable types (though it does use 32-bit
integers internally on some operations).
I had to experiment with this, but I got it working.
Looking up further, according to Wikipedia, there is a 128-bit
format that has 34.02 [decimal] digits of precision. If your target language
has this format as one of its number types, you could store integers
in such variables. You did state that you need 30 [decimal] digits of
precision, so this would fit. This would be a cheap, fairly simple
solution.
represent the calculation.
Scientist Should Know About Floating Point Arithmetic", by David Goldberg.
Honi soit qui mal y pense.