Precision Problem
-
Hi...I'm working with trigonometric functions in visual C++ V6.0. I have this program that converts degrees to radians, applies some direct trigonometric functions, and then some inverse functions. The inverse function I'm using is the ATAN2(y,x). I have checked the function and it uses the definition of pi=3.141592653589793116E00. The examples given in the MSN documentation uses pi=3.1415926535 giving the correct results. Then, I was using the last definition of pi to convert degrees to radians and viceversa, but using also the atan2(y,x) function, and I'm getting that: cos(90. degrees)=-3.4914833611094e-15 Then, because the definition of pi is different in the conversion and the function, I have decided to make it uniform, as I cannot change the definition of pi in the atan2() function, I decided to change the definition of pi used for the conversions, however, I ave got the following: cos(90. degrees)=-6.1230317691119e-017 Which is less than the previous result, but still is not correct. Is there anyway to avoid this situation? Thanks, Eric Manuel Rosales Pena Alfaro PhD student Unversity of Essex Wivenhoe Park Colchester, CO4 3SQ Essex, Uk email: emrosa@essex.ac.uk tel: +44-01206-87311
-
Hi...I'm working with trigonometric functions in visual C++ V6.0. I have this program that converts degrees to radians, applies some direct trigonometric functions, and then some inverse functions. The inverse function I'm using is the ATAN2(y,x). I have checked the function and it uses the definition of pi=3.141592653589793116E00. The examples given in the MSN documentation uses pi=3.1415926535 giving the correct results. Then, I was using the last definition of pi to convert degrees to radians and viceversa, but using also the atan2(y,x) function, and I'm getting that: cos(90. degrees)=-3.4914833611094e-15 Then, because the definition of pi is different in the conversion and the function, I have decided to make it uniform, as I cannot change the definition of pi in the atan2() function, I decided to change the definition of pi used for the conversions, however, I ave got the following: cos(90. degrees)=-6.1230317691119e-017 Which is less than the previous result, but still is not correct. Is there anyway to avoid this situation? Thanks, Eric Manuel Rosales Pena Alfaro PhD student Unversity of Essex Wivenhoe Park Colchester, CO4 3SQ Essex, Uk email: emrosa@essex.ac.uk tel: +44-01206-87311
emrosa wrote: cos(90. degrees)=-3.4914833611094e-15 cos(90. degrees)=-6.1230317691119e-017 You should never expect to get exactly 0. Floating-point numbers and operations are not exact. It seems to me that
-0.0000000000000034914833611094
and-0.000000000000000061230317691119
are pretty close to 0.