JRS: In article <
[email protected]>,
dated Thu, 29 Sep 2005 18:25:19, seen in Tony
Using Math.pow(10000000,10) or Math.pow(10000*1000,10) returns:
9.999999999999999e+69 (Mozilla 0.8)
1e+70 (Opera 8 & Explorer 6)
Is this a Mozilla bug? Ten million is a power of ten, isn't it?
I can think of three ways of implementing Math.pow(X, N) for integer N :
The method used for Math.pow(X, Y) for non-integer Y
Squaring A and halving N until N=0
Multiplying 1 by A, N times
They are likely to give different rounding errors.
A smart implementer will consider both accuracy and speed in choosing a
method; but not all implementers are smart.
Calculations in which all intermediates and results are integers of
magnitude <= 2^53 should be exact; others should be expected to be
approximated.