0

I'm just wondering why is this line

MessageBox.Show(Math.Tan(Math.PI).ToString());

returning value = -1.22460635382238E-16 , shouldn't that be 0 ? or am I missing something here ?

Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431
Stefan Madlo
  • 53
  • 1
  • 2
  • 7
  • `int x = Convert.ToInt32(Math.Tan(Math.PI));`. It is. Just rounding, as in the duplicate. – Patrick Hofman Jan 07 '16 at 15:45
  • I wouldn't expect the truncated value of `Tan` to be much use as evidence here. – spender Jan 07 '16 at 15:55
  • Still a bit confused but should check back some old school math I guess :-). Thanks mates. – Stefan Madlo Jan 07 '16 at 16:00
  • 2
    The problem is `Math.PI` does not equal `π`. It is `3.14159265358979323846`. Because it is not ***exactly*** `π`, `Math.Tan(3.14159265358979323846)` is not 0. Also, tags should not be in the title, also I corrected the title as you are working with `Math.PI` not `180`. – Scott Chamberlain Jan 07 '16 at 16:06
  • Meh, Math.Tan() also can never produce a result that is accurate to more than 15 digits. Technically the roundoff error in Math.PI could be opposite of the roundoff error in Math.Tan() and you'd get a happy result. Low odds for that of course. The assumption that the result is not correct is just wrong. – Hans Passant Jan 07 '16 at 16:27

0 Answers0