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 let
base' = abs base; base' = abs base;
number' = abs number; 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 in
if number' > base' then if number' > base'
base then base
else else
if base < 0 then if base < 0
-(result) then -(result)
else else result;
result;
/* Adds all of the given items on the list starting from a sum of zero. /* 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; expected = 39194.200000000186;
}; };
testMathMod8 = {
expr = self.math.mod' 567.5 3.5;
expected = 0.5;
};
testMathModBothPositive = { testMathModBothPositive = {
expr = self.math.mod' 54.5 20.5; expr = self.math.mod' 54.5 20.5;
expected = 13.5; expected = 13.5;