Incorrrect evaluation of cos (90 deg) #3040
Replies: 4 comments
-
This is the most asked question. It is a floating point round-off error. See docs: https://mathjs.org/docs/datatypes/numbers.html#roundoff-errors |
Beta Was this translation helpful? Give feedback.
-
But how about a bunch of simplification rules? For angles of |
Beta Was this translation helpful? Give feedback.
-
It would be possible to implement checks for that, but since we're dealing with floating point numbers, such rounding-off logic will not work flawlessly and creates inconsistencies. For floating point calculations I think it is simply best to just accept the fact that there are round-off errors involved in general. The only real solution is to use symbolic computation, like extend |
Beta Was this translation helpful? Give feedback.
-
It's because numbers in JavaScript uses 64-bit double precision numbers, so 90 degrees is pi/2 radians, since pi is an irrational number which cannot be expressed as a fraction and pi cannot be expressed in precise binary number as double precision numbers uses binary notation. |
Beta Was this translation helpful? Give feedback.
-
Tried evaluating cos (90 deg) in the demo notepad.
Showing some weird value.
It should return 0
Beta Was this translation helpful? Give feedback.
All reactions