modBy crashes if given a zero
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 48
- Forks
- 14
- Avg merge
- 4h 14m
- Merged PRs (30d)
- 1
Description
modBy 0 x crashes with a Debug.crash (https://github.com/gren-lang/core/blob/098cca86e948f018cea9ca3b10a256b8c89917ba/src/Gren/Kernel/Math.js#L14).
I suggest that there be two functions:
modBy : Int -> Int -> Maybe Int
which returns Nothing on a zero input, and:
modByWithDefault : Int -> Int -> Int -> Int
modByWithDefault modulus default x =
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked src/Gren/Kernel/Math.js implementation and read the issue discussion about zero-modulus behavior and performance. Identify the existing tests and documentation for modBy, then confirm the agreed API and semantics before changing anything; done means zero input no longer crashes and the selected behavior is documented and covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100