Math.pow() variation between Opera/Explorer & Moz?

T

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?
 
L

Lee

Tony said:
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?

A bug? Do you realize how small the percentage difference is?
The two values are identical for all practical purposes.
 
R

Randy Webb

Tony said the following on 9/29/2005 9:25 PM:
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?
No.

Ten million is a power of ten, isn't it?


Yes. But, computers do not do calculations in base 10. They do it in
floating point base 2 math. Convert to base 2, do calculations, convert
back to base 10.

What you are seeing is a difference in implementation, not a bug.
 
D

Dr John Stockton

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.
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top