roc-lang / roc-lang/examples

Example Suggestion: Safe Arithmetic

Open
#36 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Shell
Stars
46
Forks
19
Avg merge
13h 38m
Merged PRs (30d)
19

Description

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!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the Arithmetic example and its readArgs function, then read the Roc div documentation linked in the issue to confirm the zero-denominator behavior. Decide whether the example should skip integer quotient, reject zero input, or document the crash; done means the example no longer presents an unsafe zero-denominator path without explanation.

Written by the indexing model from the issue text.

Assessment

Domain
documentation
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.