1/0 returns Infinity
akpi816218 opened this issue · comments
Describe the bug
dividing by zero gives Infinity, should be undefined or NaN
To Reproduce
import { evaluate } from 'mathjs';
console.log(evaluate('1/0'));
The current behavior matches built-in JavaScript behavior for arithmetic operations.
console.log(1/0);
// => Infinity
While that may be, it's mathematically incorrect not as common as undefined or NaN.
That is not strictly true. While a common convention is to define division-by-zero as undefined, this is not a mathematical law, and, in different domains, defining division-by-zero to be infinity, zero, or signed infinity is perfectly valid.
We can discuss about what the best result would be for 1/0
, there are various valid choices: Infinity, NaN, undefined, or throwing an exception. We simply have to make a choice. For mathjs
we did choose to return Infinity
(similar to JavaScript, Mathematica, Matlab). At this point I think it's just fine to keep it like that, OK @akpi816218?
all right then, closing this issue