Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ The `%` operator is used for modulus.

5 % 3
# => 2

-7 % 5
# => 3
```

~~~~exercism/caution
Expand All @@ -111,6 +114,13 @@ This is different from normal division.
1 % 0
# Error: Unhandled exception: Division by 0 (DivisionByZeroError)
```

Note that unlike some other programming languages crystal is using floored division to calculate modulus (in JavaScript this would yield -1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thing here is that, javascripts % isnt modulo, it is remainder, thereby another type of calculation.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is using the same operator so nomater what the type of calculation is it's still confusing for some people (as it was for me)


```crystal
-6 % 5
# => 4
```
~~~~

## Rounding
Expand Down