473,388 Members | 1,277 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

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

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
4 1954
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Clueless Moron | last post by:
Why do they act differently with respect to complex numbers? Python 2.2.2 (#1, Feb 24 2003, 19:13:11) on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>...
1
by: limelight | last post by:
I have discovered a math error in the .NET framework's Log function. It returns incorrect results for varying powers of 2 that depend on whether the program is run from within the IDE or from the...
8
by: McKirahan | last post by:
How do I add floating point numbers accurately? The following adds the 4 numbers 46.57, 45.00, 45.00, and 54.83 to give 191.39999999999998 instead of 191.40. <html> <head>...
3
by: David | last post by:
Here is some code. I am trying to figure out how to raise, say, x to the yth power. I know that isn't explicitly what is in the code but that is the idea I am trying to solve. See the 2nd for...
33
by: Darius Fatakia | last post by:
Hi, I seem to be having trouble with some of my math functions (pow, sqrt, acos). They're the only ones I use in my code and they prevent the program from compiling. I get a "undefined reference...
7
by: a.dheeraj.kumar | last post by:
i know that there is a function to find the logarithm of a number, sin, cos, tan etc. but are there which can find sin^-1, cos^-1, tan^-1 and antilog of a given number? PS: sin^-1 means sin...
1
by: Andy | last post by:
Hi, I noticed when migrating a 2002 application to 2003 that the system changed to a different usage for pow(2,-15). In 2002, it used double pow(double,double). In 2003, it is using double...
5
by: Nondisclosure007 | last post by:
Hello. If this is the wrong group for this, please let me know. I'll post it somewhere else. I've been doing data imports into MS Excel (ver 2007) and using the CORREL function. What I was...
5
by: Tzury Bar Yochay | last post by:
What is the reason math.pow yields OverflowError while python itself can calculate these large numbers. e.g: 1e+308 Traceback (most recent call last): File "<stdin>", line 1, in <module>...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.