The Artima Developer Community
Sponsored Link

C# Answers Forum
tangent

1 reply on 1 page. Most recent reply: Apr 1, 2003 8:26 AM by Matt Gerrans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Thang Nguyen

Posts: 18
Nickname: thang
Registered: Apr, 2002

tangent Posted: Mar 31, 2003 7:22 PM
Reply to this message Reply
Advertisement
Hi,

Does anyone know how to validate if tan() is used legally.
Let say, at run-time the user enter something to be converted to tan. Then I would get that input and convert the input and display the result. The following code works as long as the user does not enter "illegal" input such as 90 or 270

double r = tan(usrInput * PI / 180);

tangent of usrInput is r - BUT only if usrInput is a valid input for tan() otherwise it is not the case to do such code above.

Any help would be great.
Thanks


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: tangent Posted: Apr 1, 2003 8:26 AM
Reply to this message Reply
I don't think it is a problem. Because pi is an irrational number, you cannot represent it exactly, therefore it is impossible to hit on the exact spot where the tangent would be infinite. Anyway, if you manage to find a value that is close enough, Math.Tan() will just return NaN instead of crashing the system, as in the old days with "divide by zero error."

If you want to avoid the possibility of even getting NaN, then it is also quite simple to calculate (you already know how) that the tangent will be infinite based on what value the user entered and inform the user without ever calling Tan(). If the values from the user are progressing in one way or the other, you can also tell the user whether it is negative or positive infinity.

Flat View: This topic has 1 reply on 1 page
Topic: c answers Previous Topic   Next Topic Topic: vsvars32.bat ineffective - what's up?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use