Klogg Posted October 31, 2003 Posted October 31, 2003 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. Quote Take a look at my programs. Go to my web site.
Klogg Posted November 2, 2003 Author Posted November 2, 2003 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? Quote Take a look at my programs. Go to my web site.
Administrators PlausiblyDamp Posted November 2, 2003 Administrators Posted November 2, 2003 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Klogg Posted November 3, 2003 Author Posted November 3, 2003 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. Quote Take a look at my programs. Go to my web site.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.