examples icon indicating copy to clipboard operation
examples copied to clipboard

Example Suggestion: Safe Arithmetic

Open fdbeirao opened this issue 1 year ago • 4 comments

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:

  1. Adjust the example text to state that if the second argument is 0, we can skip the integer quotient operation;

  2. Adjust the example text to state that zero is not a valid input for the second argument, and add an explicit check on the readArgs function for this case

  3. 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!

fdbeirao avatar May 25 '23 20:05 fdbeirao