You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be great if RationalNode was changed to have a numerator and denominator field, then we wouldn't need to manually reparse the number.
It could also potentially save an unnecessary conversion from string to double, since the double value in this case should not be used anyway.
The text was updated successfully, but these errors were encountered:
eregon
changed the title
Parse RationalNode value to make it directly usable
RationalNode numerator & denominator fields to make it directly usable
Feb 28, 2024
@kddnewton Should this be addressed for 1.0, since it will likely be a breaking change for consumers?
Although maybe it's feasible to define a numeric method for compatibility.
Sweet! @andrykonchin Could you adopt this in TruffleRuby? It should simplify a bunch of logic.
It also looks (from the docs) that Prism does the canonicalization, so we could skip that when creating the Rational from the literal.
Rational literals are either:
123r
12.34r
(
12ri
/12.34ri
is just ImaginaryNode of RationalNode, so a trivial variant)These are actually quite different, the first is the same as
Rational(123, 1)
but the second isRational(1234, 100)
, notRational(12.34)
:So right now to handle this we have to manually parse the number, e.g. TruffleRuby does it like this:
https://github.com/oracle/truffleruby/blob/5096dddf6c3adc7edbae0938efc4fb4913b62bba/src/main/java/org/truffleruby/parser/YARPTranslator.java#L2905-L2927
It would be great if RationalNode was changed to have a numerator and denominator field, then we wouldn't need to manually reparse the number.
It could also potentially save an unnecessary conversion from string to
double
, since thedouble
value in this case should not be used anyway.cc @andrykonchin
The text was updated successfully, but these errors were encountered: