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
{{ message }}
Repository navigation
Cast IntegerNode to float32 in operations like f32 == 1.5 #609
and that is not the case for expr (please refer to my initial example) and that's why I opened issue. I believe Expr internally always cast number to flat64
changed the title [-]Floating number comparison returns incorrect result[/-][+]Cast IntegerNode to float32 in operations like `f32 == 1.5`[/+]on May 25, 2024
Activity
[-]Floating number comparison[/-][+]Floating number comparison returns incorrect result[/+]antonmedv commentedon Apr 15, 2024
This is how float comparison works:
https://go.dev/play/p/XsvrQ66pfrX
daisy1754 commentedon May 23, 2024
@antonmedv I think example I gave is more like below. It is true in golang but false in expr
https://go.dev/play/p/Z9SwZHGSi_J
antonmedv commentedon May 24, 2024
In golang
f32 == 12.34, right hand side12.34will be interpreted as float32, i.e.float32(12.34). IN Expr 12.34 is a float64.daisy1754 commentedon May 24, 2024
well in golang literals are automatically casted to proper type right? in below example both float32 and float64 comparison returns true.
antonmedv commentedon May 24, 2024
Yes, type in inherited from left.
daisy1754 commentedon May 24, 2024
and that is not the case for expr (please refer to my initial example) and that's why I opened issue. I believe Expr internally always cast number to flat64
antonmedv commentedon May 24, 2024
In your example number is float32
daisy1754 commentedon May 24, 2024
Is this example more clear? I expect all to be true
result is
https://go.dev/play/p/GH9DSp3YFHF
antonmedv commentedon May 25, 2024
In first example expr does this
which is false.
daisy1754 commentedon May 25, 2024
yeah I understand internal - that's why I sent out #610
Don't you think it's confusing though? As shown above
expr expression is false and golang expression is true in this case
antonmedv commentedon May 25, 2024
Yes! I think we can work on a proper solution for this. The solution in #610 is not correct.
What we need is to cast type to float32 only in case of lhs is float32. This should be done in patcher.
[-]Floating number comparison returns incorrect result[/-][+]Cast IntegerNode to float32 in operations like `f32 == 1.5`[/+]breml commentedon Mar 25, 2026
My comment about a patcher for built in types (including float32 and float64) might be relevant here as well.