bahaghari/lib: fix math.mod' implementation bug

This commit is contained in:
Gabriel Arazas 2024-06-15 15:55:24 +08:00
parent 3f8c59c399
commit da4a0b8826
No known key found for this signature in database
GPG Key ID: 62104B43D00AA360
2 changed files with 12 additions and 8 deletions

View File

@ -278,17 +278,16 @@ rec {
let
base' = abs base;
number' = abs number;
difference = number' * ((floor base' / (floor number')) + 1);
difference = number' * ((floor (base' / number')) + 1);
result = number' - (difference - base');
result = abs (number' - (difference - base'));
in
if number' > base' then
base
if number' > base'
then base
else
if base < 0 then
-(result)
else
result;
if base < 0
then -(result)
else result;
/* Adds all of the given items on the list starting from a sum of zero.

View File

@ -262,6 +262,11 @@ lib.runTests {
expected = 39194.200000000186;
};
testMathMod8 = {
expr = self.math.mod' 567.5 3.5;
expected = 0.5;
};
testMathModBothPositive = {
expr = self.math.mod' 54.5 20.5;
expected = 13.5;