Skip to content

add toInt and toNumber #7

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
merged 8 commits into from
Apr 8, 2023
Merged

add toInt and toNumber #7

merged 8 commits into from
Apr 8, 2023

Conversation

gbagan
Copy link
Contributor

@gbagan gbagan commented Mar 23, 2023

add toInt and toNumber

add new tests

Copy link
Collaborator

@sigma-andex sigma-andex left a comment

Choose a reason for hiding this comment

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

Sorry forgot to push "submit review"

@@ -19,6 +19,8 @@ export const fromInt = (n) => BigInt(n);

export const fromTypeLevelInt = (str) => BigInt(str);

export const toNumber = (n) => Number(n);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this check whether n is in range?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not quite sure about this point but I think checking is not necessary because Number() returns +infinity or -infinity (which are valid Purescript numbers) if the bounds are not checked.
By the way, no function in Data.Number (like pow or acos) does checking.
Neither does purescript-bigints' toNumber function.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's okay to return +infinity or -infinity but that should be documented. The toNumber export should say “If the BigInt is too positive then the result will be +Infinity. If the BigInt is too negative, then the result will be -Infinity.” or something like that.

gbagan and others added 5 commits April 4, 2023 12:14
Co-authored-by: James Brock <jamesbrock@gmail.com>
Co-authored-by: James Brock <jamesbrock@gmail.com>
Co-authored-by: James Brock <jamesbrock@gmail.com>
Co-authored-by: James Brock <jamesbrock@gmail.com>
@f-f f-f merged commit e026a78 into purescript-contrib:main Apr 8, 2023
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.

4 participants