fable-compiler / Fable

F# to JavaScript, TypeScript, Python, Rust and Dart Compiler
http://fable.io/
MIT License
2.9k stars 295 forks source link

min and max occasionally return the wrong value #3884

Closed mattgallagher92 closed 3 weeks ago

mattgallagher92 commented 3 weeks ago

Description

max sometimes, but not always, returns the smaller rather than bigger value. So does min.

Repro code

max 9m 300m

Expected and actual results

Expected: 300 Actual: 9

Related information

mattgallagher92 commented 3 weeks ago

In case it's not obvious, an easy workaround is to run the check yourself: if x < y then y else x

MangelMaxime commented 3 weeks ago

Looking at the generated code, it seems like when using if x < y then y else x then Fable will call the Decimal.cmp functions instead on relying on > or < operators.

It is possible that because Decimal is a custom implementation via Big.js then > or < operators don't works on it.

ncave commented 3 weeks ago

@mattgallagher92 It's not just occasionally, it's consistently wrong :)

Thanks for reporting, fixed in #3885.

mattgallagher92 commented 3 weeks ago

Thanks @ncave!

Actually, max 0.1m 300m seemed to work fine 🤷🏼 so there was some level of inconsistency

ncave commented 3 weeks ago

Using operators directly was comparing their internal string representation, so "01" < "300", but "9" > "300". Should be fixed in the next release.