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.