-
Notifications
You must be signed in to change notification settings - Fork 4
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
Conversation
There was a problem hiding this 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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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>
add toInt and toNumber
add new tests