Example Suggestion: Safe Arithmetic
Just going through the examples, thank you so much for the effort you are making here.
I am reading through the Arithmetic example and I think there's the obvious edge case about dividing by zero.
According to roc's current div documentation:
Division by zero is undefined in mathematics. As such, you should make sure never to pass zero as the denomaintor to this function! Calling div on a Dec denominator of zero will cause a panic.
Possible solutions:
-
Adjust the example text to state that if the second argument is
0, we can skip theinteger quotientoperation; -
Adjust the example text to state that zero is not a valid input for the second argument, and add an explicit check on the
readArgsfunction for this case -
Adjust the example text to state that an input of 0 on the second argument is allowed to crash with a
Floating point exception
My preference would be between solution 1 or 2, or a smarter one :)
Let me know your thoughts and once again, thank you for this amazing effort!
Thanks for bringing this up @fdbeirao, I propose we call the current Arithmetic example ArithmeticUnsafe and create additional examples DivisionSafe, AdditionSafe (with an overflow check), MultiplicationSafe,...
What do you think?
I think I can take a stab at it later today if that would be okay with you. Even if my modifications wouldn't be approved at least it would be a great learning exercise for me :)
I think we would add the zero case to the README.md of the existing Arithmetic (and rename it to ArithmeticUnsafe). Not sure we would need to worry about overflow for the unsafe, since we do the bounds check from -1000 to 1000. If we let go of the bounds check, we can then also use the unsafe to showcase what happens with overflows.
What do you think, Anton?
I think I can take a stab at it later today if that would be okay with you.
Sounds great :)
If we let go of the bounds check [...]
Yes indeed, along with #40 I wanted to remove the bounds check.
I think we would add the zero case to the README.md of the existing Arithmetic
:+1:
we can then also use the unsafe to showcase what happens with overflows
Sounds good!
As previously discussed, I think it would be great to have an example that demonstrates a realistic use of checked math. A good case would be to calculate the statistical variance of a list of numbers in a safe way.