Open Groostav opened 4 years ago
my suspicion:
-2.0*2.718281828459045
is odd, this is clearly -2^e
, which can only be interpreted as -1*(2^e)
.-(x1-0.1)^2
, is a strange way to write this. Again, that should be -1*((x1-0.1)^2)
Ok so,
what is
-3^2
wolfram alpha, and MATLAB, both give -9
excel, and babel, both give +9
the question is about negation and exponentiation prescedence, and they relate to the complex and real planes.
question: will your language mostly deal with integer exponents or rational exponents?
if the former, you're with excel. If the latter, you're with matlab.
In other words
language | prescedence | -3^2 |
-3^2.718 (ie -3^e ) |
---|---|---|---|
Matlab/Mathmatica | FIRST: exponent THEN negate | -9 |
-19.812 |
Excel | FIRST: negate THEN exponent | 9 |
#NUM (java returns NaN) |
babel has chosen to act like the latter.
Still, its error handling system should flag this with a good error, so I'll leave this open
In this particular case, its really unfortunate that we write (complex-expr)^2.0
. What happens there is sign-confusion.
I think we can make this a compilation error: we we should look for an AST where:
base-expr
and expo-expr
base-expr
is-a negationexpo-expr
is-not a constant-integer expressionThen we raise an error:
cannot raise a
negative numbernegated-value to a non-integer power. Please rewrite as-(base-expr^expo-expr)
or(-base-expr)^expo-expr
.
TBD
From Cenk:
from george: