Skip to content
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

min and max occasionally return the wrong value #3884

Closed
mattgallagher92 opened this issue Sep 3, 2024 · 5 comments
Closed

min and max occasionally return the wrong value #3884

mattgallagher92 opened this issue Sep 3, 2024 · 5 comments

Comments

@mattgallagher92
Copy link

mattgallagher92 commented Sep 3, 2024

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
Copy link
Author

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

@MangelMaxime
Copy link
Member

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
Copy link
Collaborator

ncave commented Sep 3, 2024

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

Thanks for reporting, fixed in #3885.

@mattgallagher92
Copy link
Author

Thanks @ncave!

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

@ncave
Copy link
Collaborator

ncave commented Sep 4, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants