-
Notifications
You must be signed in to change notification settings - Fork 15
Fix overflows in randomInt #12
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
|
||
-- | Safely convert a Number into an Int, by first flooring and then clamping | ||
-- to the valid integer range. | ||
safeFromNumber :: Number -> Int |
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.
This shouldn't be exported, right? Can it go into a where
clause?
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, I should read your comments first :)
Yeah, let's put this into integers
as truncate
. Although, I guess it depends what we decide to do about bounds on integers for different backends.
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.
No, it shouldn't, but I didn't do that yet becaues I thought you might want to put this function into integers
instead. I can imagine it being useful in other contexts.
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.
Ah, just saw your second comment!
Regardless of what we do about different backends, top :: Int
should still work on any backend, right? Perhaps Prelude can get the maximum and minimum values for the Bounded Int
instance from FFI files, so that we can make them differ across backends?
What is this actually fixing? Since |
If you ask for
so |
Ah ok :) |
Now that |
Fixes #9
Fix overflows by turning everything into a
Number
first, and then converting it back at the end.I decided not to bother with the export list yet because I thought you might want
safeFromNumber
to go intopurescript-integers
instead, perhaps with a different name. (truncate
?) What do you think?