From fd436737e3c0d7c1d6a0ab04ddc5b8f0de2ef723 Mon Sep 17 00:00:00 2001 From: Hari Mohan Date: Mon, 1 Dec 2025 09:51:45 +0000 Subject: [PATCH] Make int.modulo and float.modulo docs clearer Specify difference between int.modulo and int.remainder / % --- src/gleam/float.gleam | 2 ++ src/gleam/int.gleam | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/gleam/float.gleam b/src/gleam/float.gleam index 83bfa6e6e..106cb6db1 100644 --- a/src/gleam/float.gleam +++ b/src/gleam/float.gleam @@ -456,6 +456,8 @@ pub fn random() -> Float /// Returns division of the inputs as a `Result`: If the given divisor equals /// `0`, this function returns an `Error`. /// +/// The computed value will always have the same sign as the `divisor`. +/// /// ## Examples /// /// ```gleam diff --git a/src/gleam/int.gleam b/src/gleam/int.gleam index fa8aaef8a..c0cd069e0 100644 --- a/src/gleam/int.gleam +++ b/src/gleam/int.gleam @@ -594,8 +594,8 @@ pub fn remainder(dividend: Int, by divisor: Int) -> Result(Int, Nil) { /// Returns division of the inputs as a `Result`: If the given divisor equals /// `0`, this function returns an `Error`. /// -/// Most the time you will want to use the `%` operator instead of this -/// function. +/// Note that this is different from `int.remainder` and `%` in that the +/// computed value will always have the same sign as the `divisor`. /// /// ## Examples /// @@ -624,6 +624,11 @@ pub fn remainder(dividend: Int, by divisor: Int) -> Result(Int, Nil) { /// // -> Ok(2) /// ``` /// +/// ```gleam +/// modulo(13, by: -3) +/// // -> Ok(-2) +/// ``` +/// pub fn modulo(dividend: Int, by divisor: Int) -> Result(Int, Nil) { case divisor { 0 -> Error(Nil)