summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS2
-rw-r--r--lib/MDK/Common/Math.pm4
2 files changed, 4 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index 31c59f2..ef601ce 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,5 @@
+- round_up(), round_down(): workaround "Illegal modulus zero" (#43165)
+
Version 1.2.13 - 9 September 2008, by Pascal "Pixel" Rigaux
- export cat_utf8() and cat_utf8_or_die()
diff --git a/lib/MDK/Common/Math.pm b/lib/MDK/Common/Math.pm
index 5ed9a61..c738f71 100644
--- a/lib/MDK/Common/Math.pm
+++ b/lib/MDK/Common/Math.pm
@@ -126,8 +126,8 @@ sub odd { $_[0] % 2 == 1 }
sub sqr { $_[0] * $_[0] }
sub sign { $_[0] <=> 0 }
sub round { int($_[0] + 0.5) }
-sub round_up { my ($i, $r) = @_; $i = int $i; $i += $r - ($i + $r - 1) % $r - 1 }
-sub round_down { my ($i, $r) = @_; $i = int $i; $i -= $i % $r }
+sub round_up { my ($i, $r) = @_; $r ||= 1; $i = int $i; $i += $r - ($i + $r - 1) % $r - 1 }
+sub round_down { my ($i, $r) = @_; $r ||= 1; $i = int $i; $i -= $i % $r }
sub divide { my $d = int $_[0] / $_[1]; wantarray() ? ($d, $_[0] % $_[1]) : $d }
sub min { my $n = shift; $_ < $n and $n = $_ foreach @_; $n }
sub max { my $n = shift; $_ > $n and $n = $_ foreach @_; $n }