It's not sloppy, it's just how floating point numbers work.  Try the same
thing in other programming languages and you still will not get zero (unless
they round the output).  For example, .NET reports the result as 
6.12303176911189E-17.  
 
Sam

-------------------------------------------
We're Hiring! Seeking a passionate developer to join our team building Flex
based products. Position is in the Washington D.C. metro area. If interested
contact [EMAIL PROTECTED]
  

 

  _____  

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Mike Krotscheck
Sent: Sunday, September 16, 2007 5:19 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Math.cos...?



The documentation's actually fairly clear on this: "The cosine of a 90
degree angle is zero, but because of the inherent inaccuracy of decimal
calculations using binary numbers, Flash Player will report a number
extremely close to, but not exactly equal to, zero."

 

Nevertheless, it seems. sloppy to me.

 

Michael Krotscheck

Senior Developer

 


  _____  

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Troy Gilbert
Sent: Sunday, September 16, 2007 5:15 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Math.cos...?

 

> Why does Math.cos(Math.PI/2) not return zero?

Round-off error in the Math libs? It does return a value very close to
0 (1.7xe-17).

Troy.

Reply via email to