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

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

P: n/a
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?

Sep 30 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.

Sep 30 '05 #2

P: n/a
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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Sep 30 '05 #3

P: n/a
Tony wrote:
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?

Pretty much every number can be expressed as a power of 10, logarithms
wouldn't be very useful otherwise. :-)

You may find this useful:

<URL:http://www.merlyn.demon.co.uk/js-maths.htm#Float>
--
Rob
Sep 30 '05 #4

P: n/a
JRS: In article <11*********************@z14g2000cwz.googlegroups. com>,
dated Thu, 29 Sep 2005 18:25:19, seen in news:comp.lang.javascript, Tony
<an************@yahoo.co.uk> posted :
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.

--
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.
Oct 1 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.