Hacker News new | past | comments | ask | show | jobs | submit login

Notice the following:

  > sin(pi)

  -3.73566e-20

  > sin(2*pi)

  7.47132e-20

  > sin(3*pi)

  -1.1207e-19

  > sin(4*pi)

  1.49426e-19
So

  abs(sin(n*pi)) 
is proportional to n, and

  sin(n*pi)
alternates in sign. This is because your "pi" is really a floating-point number which is slightly more than pi...

Is there a way around this without doing all computation symbolically?




You are absolutely right. I am afraid there is no good solution for the problem except for performing symbolic calculations or simplifications.

A hacky solution could be to round the output of sin(x) to a given internal precision. This would only hide the real internal numerical problem, though.

It seems that other calculators suffer from the same issue: https://www.google.de/search?q=sin(1e10*pi)

For now, I have increased the internal precision to 30 significant digits and updated the value of Pi to be more precise than that. Of course, this doesn't really solve the problem... just shifts it by a few orders of magnitude :-)

Edit: Also, note that everything is fine if the answer is not zero (due to the rounding in the output):

  > sin(pi)+1
  1




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: