Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 1
    theta isn't exactly half-pi, which is why there is no Infinity in the output - NaN/InF is not "stored as" 1.633123935319537E16, which is still a finite number. Commented Mar 5, 2014 at 5:18
  • 1
    See tan(PI/2) for why you don't get Infinity. However, I don't know of a way to get tan to "accept values close to PI/2" as PI/2, and all the environments seem to produce a value. Commented Mar 5, 2014 at 5:22
  • @user2864740 Thanks, that tells me why... But can u tell me how to fix it? Commented Mar 5, 2014 at 5:24
  • 1
    The only immediate solution I can think of is to special-case the input before calling tan. If it's "close enough to PI/2" for your liking, simply return Inf/-Inf (or whatever you are expecting) instead of calling tan. If you need to do "trigonometrical correct" math, there may be a library that can can deal with the exact mathematical concepts. (I think "symbolic math" may be a useful search term). Commented Mar 5, 2014 at 5:29
  • @user2864740 thanks, i'll see to it. Commented Mar 5, 2014 at 5:29