-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
modBy crashes if given a zero #85
Comments
I started a discussion on the elm #language-design channel about this. It seems several other languages specialcase I was also made aware that Are there math-functions, other than |
I find it very annoying that I get crashes for divide by zero in python but I also think that just returning zero would cause even more subtle bugs that would be difficult to track down. I would for example also like to be able to set it so that any production of NaN in python would raise instead. Much nicer than a garbage value that pollutes the execution flow dowstream some arbitrary amount until it is (hopefully!) caught. Same here with divide by zero and mod. Yea it's annoying but the right thing and the easy thing should be aligned. That's why I would be against "checked" versions: it makes it opt in to do the right thing. You could call that broken by default too. |
I would like to propose the following… intDivBy : Int -> Int -> Maybe Int
modBy : Int -> Int -> Maybe Int
remainderBy : Int -> Int -> Maybe Int
unsafeIntDivBy : Int -> Int -> Int
unsafeModBy : Int -> Int -> Int
unsafeRemainderBy : Int -> Int -> Int
…with the The
Please, no. I was bitten by an unexpected |
modBy 0 x
crashes with aDebug.crash
(core/src/Gren/Kernel/Math.js
Line 14 in 098cca8
I suggest that there be two functions:
which returns
Nothing
on a zero input, and:which does returns a default value on zero.
The reason for the second method is that there is some overhead from the
Maybe
handling which would be a problem in performance sensitive code, as @robinheghan pointed out on zulip. The docs should point out the performance characteristics.I think this is a fairly easy change, but I am a bit scared of touching kernel code of course :P
The text was updated successfully, but these errors were encountered: