From 82efd915cc188d3d95538b6d81fef850f249b949 Mon Sep 17 00:00:00 2001 From: Alexandru Duzsardi Date: Sun, 30 Mar 2025 21:25:47 +0300 Subject: [PATCH] Added negative dividend modulo example --- .../wellingtons-weather-station/.docs/introduction.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/exercises/concept/wellingtons-weather-station/.docs/introduction.md b/exercises/concept/wellingtons-weather-station/.docs/introduction.md index 8883926d..87a5027c 100644 --- a/exercises/concept/wellingtons-weather-station/.docs/introduction.md +++ b/exercises/concept/wellingtons-weather-station/.docs/introduction.md @@ -101,6 +101,9 @@ The `%` operator is used for modulus. 5 % 3 # => 2 + +-7 % 5 +# => 3 ``` ~~~~exercism/caution @@ -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) + +```crystal +-6 % 5 +# => 4 +``` ~~~~ ## Rounding