#### Archived

This topic is now archived and is closed to further replies.

# cos/sin acting strange?

This topic is 5486 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

This is probably something really obvious I''m overlooking, but I don''t see it. Is there some attribute of the c/c++ standard library trig functions? Heres the problem. Why does this: cosf(acosf(0)) Give me this: -4.37114e-08 cosf gives me that value when I feed in a right angle. Am I stupid or is cos(PI/2) not 0? I''ve tried this in linux and VCPP. Also if I do this: float HALFPI = M_PI / 2; float value = sinf( HALFPI - acosf(0) ); value will be 0. But if I do this: float value - sinf( (M_PI/2) - acosf(0) ); value will again be -4.37114e-08 Does this make any sense to anyone?

##### Share on other sites
It's caused by floating point inaccuracy. For more information, read up on the IEEE 754 standard floating-point format.

Don't worry though; for all intents and purposes, that number IS zero, except for the fact that its binary representation is not literally zero, so you'd have to check its absolute value against a suitable epsilon to see if it was small enough to be considered zero.

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//

[edited by - zealouselixir on July 8, 2003 12:21:24 AM]

##### Share on other sites
Why use float? Why not use double and use the sin and cos functions?
And yes, -4.37114e-08 is a very small number, close enough to zero.

##### Share on other sites
<a href="http://docs.sun.com/source/806-3568/ncg_goldberg.html">What Every Computer Scientist Should Know About Floating-Point Arithmetic</a>

1. 1
Rutin
19
2. 2
JoeJ
15
3. 3
4. 4
5. 5

• 24
• 20
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631700
• Total Posts
3001778
×