[C++] math.h sin(M_PI) problem.

Started by
7 comments, last by TheUnbeliever 14 years, 1 month ago
It's returning a weird number that's not zero. What's wrong?
Please point my english mistakes everytime you can.
Advertisement
Is the number practically zero? Maybe you need to read this
M_PI is not exactly pi, because floating-point values cannot represent pi exactly. Therefore, the sine of M_PI is not 0.

Quote:Original post by WindScar
It's returning a weird number that's not zero. What's wrong?
Probably just a precision issue. Can you post the number that you're getting?

[Too slow...]
Link favorited for future reading. The number I'm getting is 6.12303e-17. I suppose it's very close to 0 but I don't know how to read it.
Please point my english mistakes everytime you can.
The `e-17' part means `times 10^(-17)', in other words, the number is 0.0000000000000000612303.

Quote:The number I'm getting is 6.12303e-17. I suppose it's very close to 0 but I don't know how to read it.
It's scientific notation.
It seems a bit weird to have such a small number in my console instead of 0, but I suppose that's too small to be a problem. Thank you.
Please point my english mistakes everytime you can.
Quote:Original post by WindScar
It seems a bit weird to have such a small number in my console instead of 0, but I suppose that's too small to be a problem. Thank you.


Well, it's too small to be a problem unless you're doing things like testing thingThatShouldBeZero == 0 and getting strange bugs as a result (in case it's not clear, you should test for thingThatShouldBeZero < epsilon). Floating point computation has lots of gotchas that are well worth learning about. If you're just worried about pretty-printing, use setprecision to cut it off at a sensible point.
[TheUnbeliever]

This topic is closed to new replies.

Advertisement