Trig Problems in VB

Klogg

Centurion
Joined
Oct 7, 2003
Messages
104
When I use trig in VB, I get inaccurate answers for some angles. For instance, it says that cos(90)=6.123E-17 instead of 0 and that tan(90)=1.633E+16 instead of undefined. Does anyone know a solution to this problem? Oh, and just in case you were wondering, my program does convert the input from degrees to radians.
 
Is there a way of solving this problem other than just telling it to show the correct answer if the user puts in one of the angles that is causing a problem?
 
It's probably a rounding error due to the data types being double. Could you not just use Math.round to restrict it to 8 or 9 decimal places?

Does seem strange that the values are returned with a rounding error though.
 
Math.Round() works for the ones where the answer should be zero, but not for the ones where it should be undefined. Unless someone knows of another way to fix this, it looks like I'll have to tell it which answer to give if it's one of the inaccurate angles.
 
Back
Top