• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: problem with cos ( pi/2 )
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problem with cos ( pi/2 )


  • Subject: Re: problem with cos ( pi/2 )
  • From: Christopher Henrich <email@hidden>
  • Date: Fri, 16 Jun 2006 12:33:25 -0400


On Jun 16, 2006, at 11:07 AM, billmonk wrote:

Not sure if this is the right list...searching it hasn't turned up any likely entries...


When calling cos( pi/2 ), I'm getting a tiny number, rather than zero, for


cos( M_PI_2 ); // pi/2, 1.57079632679489661923 from <math.h>

I've added "-llibm" to "Other C flags", as alluded to here,

http://developer.apple.com/documentation/Darwin/Reference/ManPages/ man3/intro.3.html
Oops; if you're using C (C++, Obj-C, whatever) then I think you want the "-lm" flag.

but am still getting 2.6484540326036093e-14 instead of 0.


My old IM:PowerPC Numeric book, and the OS X pdf here

http://developer.apple.com/documentation/Performance/Conceptual/ Mac_OSX_Numerics/Mac_OSX_Numerics.pdf

say cos( pi/2 ) is a special case (for all the reasons given in PPCNumerics) but that an IEEE-compliant math lib should return -0.0, with the "inexact" flag set, for cos( pi/2 ).

So it looks like I'm not actually using the IEEE libm. What am I doing wrong?

As a data point, I notice Calculator.app in Degrees mode correctly gives 0 for cos( 90 ), but in Radians mode gives a tiny number for cos ( pi /2 ); a different one than I get for cos( M_PI_2 ). That's kind of weird...
"90" is an integer, exactly representable in almost any number format. So here's a case where the machine knows exactly what angle you want. Therefore it can give you exactly the cosine of it.

Chris Henrich
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: problem with cos ( pi/2 )
      • From: billmonk <email@hidden>
References: 
 >problem with cos ( pi/2 ) (From: billmonk <email@hidden>)

  • Prev by Date: problem with cos ( pi/2 )
  • Next by Date: RE: problem with cos ( pi/2 )
  • Previous by thread: problem with cos ( pi/2 )
  • Next by thread: Re: problem with cos ( pi/2 )
  • Index(es):
    • Date
    • Thread