BruceDawson

Member
  • Content count

    1
  • Joined

  • Last visited

Community Reputation

109 Neutral

About BruceDawson

  • Rank
    Newbie
  1. [quote name='web383' timestamp='1337634063' post='4942004'] You're not calculating the sin of PI... you're calculating the sin of (float)pi, or (double)pi. PI, as a whole, can't be represented as a float or even a double. [/quote] That's correct, that he is not calculating cos(pi/2), he is calculating cos((float)(pi/2)). But what I think is really cool (and what my post on randomascii discusses) is exactly what *is* being calculated, because it turns out to be very meaningful. When you calculate sin((float)pi)) or cos((float)(pi/2)) then a bit of calculus or geometric reasoning shows that what you are actually calculating is the error in the value that you are passing in! Thus: sin((float)pi); equals pi-float(pi) -- the error in (float)pi cos((float)(pi/2)); equals pi/2-(float)(pi/2) - the error in (float)(pi/2) The Cos and sin functions are extremely accurate and the result is typically accurate to about seven significant digits, so the real meaning of the result is that (float)(pi/2) is about -4.37114e-008 away from pi/2. This happens to be close to FLT_EPSILON, but while that is probable it is not, in general, necessarily true. Cool! This claim is not generically true, It is true for cos/sin around these values because the derivative at those points is 1 and because the 'expected' value is zero.