Skip to content

modBy crashes if given a zero #85

@boxed

Description

@boxed

modBy 0 x crashes with a Debug.crash (

var _Math_modBy = F2(function (modulus, x) {
).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions