On Sun 2009-05-24 09:53:36 UTC-0700, Jos Timanta Tarigan ([email protected]) wrote:
> im currently having a problem try to calculate this: > directionZ = -cos((angleX+90)*PI_RADIAN); > most of the time it works but when im in the boundary of the > coordinate, it gives me a little error that im not expecting if > calculated correctly. i notice that when my angleX is 90, and my > directionZ should be 0. but the problem that it is not since the > precision given when multiplied by PI_RADIAN is not exactly 0. i track > it and it seem to be a floating point precision error. instead of > having exactly 0, i got 0.000xxx.? any advice to avoid this error? how > can i limit eg: remove everything from third decimal? first thing come > up to my mind is to multiply by 1000, convert to int, divide by 1000, > but thats too long imo. http://c-faq.com/fp/printfprec.html http://c-faq.com/fp/round.html
