Skip to content

Fix HugeNum comparison #20

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

Merged

Conversation

eviefp
Copy link
Member

@eviefp eviefp commented Nov 2, 2020

Description of the change
This PR fixes comparing negative numbers. This was also causing the problem mentioned in #10 because HugeInt.toInt was using HugeNum comparison internally.


Checklist:

  • Added the change to the changelog's "Unreleased" section with a link to this PR and your username
  • Linked any existing issues or proposals that this pull request should close
  • Updated or added relevant documentation in the README and/or documentation directory
  • Added a test for the contribution (if applicable)

Comment on lines +66 to +70
toFromNumIsIdentity :: Number -> Boolean
toFromNumIsIdentity n = HN.toNumber (HN.fromNumber n) == n

toFromIntIsIdentity :: Int -> Boolean
toFromIntIsIdentity n = HI.toInt (HI.fromInt n) == Just n

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding these tests! Do these fail without the change you added?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think only the Int one fails.

Comment on lines +105 to +106
| r1.decimal > r2.decimal = if r1.sign == Minus then LT else GT
| r1.decimal < r2.decimal = if r1.sign == Minus then GT else LT

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅 Thanks for fixing this.

@thomashoneyman thomashoneyman changed the title Fix HugeNum comparsion Fix HugeNum comparison Nov 2, 2020
@thomashoneyman thomashoneyman merged commit 18fb35c into purescript-contrib:main Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants