-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimizer does not account for INF and NAN #16
Labels
bug
Something isn't working
Comments
Muqsit
added a commit
that referenced
this issue
Nov 1, 2022
…ls (address #16) Constant folding will resolve this on its next visit by executing the operation instead of direct substitution
Muqsit
added a commit
that referenced
this issue
Nov 3, 2022
Muqsit
added a commit
that referenced
this issue
Nov 3, 2022
Muqsit
added a commit
that referenced
this issue
Nov 3, 2022
Muqsit
added a commit
that referenced
this issue
Nov 3, 2022
Muqsit
added a commit
that referenced
this issue
Nov 3, 2022
NhanAZ
added a commit
to nhanaz-pm-pl/Calculator
that referenced
this issue
Nov 4, 2022
Introduced `Parser::getOperatorManager()` ([`4ff725f`](Muqsit/arithmexp@4ff725f)) Replaced `Parser::getBinaryOperatorRegistry()` with `Parser::getOperatorManager()->getBinaryRegistry()` Replaced `Parser::getUnaryOperatorRegistry()` with `Parser::getOperatorManager()->getUnaryRegistry()` Fixed a few cases where optimizers did not account for INF and NAN ([#16](Muqsit/arithmexp#16)) ([`1ef49eb`](Muqsit/arithmexp@1ef49eb), [`db1df91`](Muqsit/arithmexp@db1df91), [`03440ab`](Muqsit/arithmexp@03440ab), [`b9dd31e`](Muqsit/arithmexp@b9dd31e), [`3c9b8a0`](Muqsit/arithmexp@3c9b8a0), [`14442ca`](Muqsit/arithmexp@14442ca), [`082ccf3`](Muqsit/arithmexp@082ccf3)) Fixed operator precedence of unary operators being greater than exponentiation ([#17](Muqsit/arithmexp#17)) ([`4ff725f`](Muqsit/arithmexp@4ff725f)) Fixed division by zero with zero `0 / 0` returning `int(0)` with optimizations ([`1672970`](Muqsit/arithmexp@1672970)) Function properties (commutativity and determinism) are governed by function flags instead of boolean properties (3e34845) See newer examples on the [wiki](https://github.com/Muqsit/arithmexp/wiki) about how to register custom binary operators, unary operators, and functions Implemented idempotent functions ([`bd08609`](Muqsit/arithmexp@bd08609))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
Operator Strength Reduction optimizer directly substitutes a sub-expression
x - x
with0
, not accounting forINF
orNAN
values being supplied tox
(inf - inf
andnan - nan
must producenan
). Other affected cases include0 * inf
returning0
instead ofNAN
, andsqrt(-1) / sqrt(-1)
getting substituted for1
despitesqrt(-1) === NAN
(NAN / NAN === NAN
).As variable resolution occurs during evaluation,
x - x
cannot be resolved during parsing although1 - 1
andinf - inf
can. One way to address this would be to resolve operations between numeric literal operands during parsing and implement a mechanism to toggle optimizations that disregardINF
andNAN
(like GCC's FloatingPointMath flags).Workarounds
ExpressionOptimizerRegistry
$parser = Parser::createUnoptimized();
The text was updated successfully, but these errors were encountered: