summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2008-10-01 11:53:57 +0000
committerPascal Rigaux <pixel@mandriva.com>2008-10-01 11:53:57 +0000
commit11632a1a585339ab1da9c39291fb964f9442290e (patch)
tree1163388bcb6fb01ed730f6f214a446106bc62c2d
parent3dbc55dbd7834394529cc9a0473389129e7572b3 (diff)
downloadperl-MDK-Common-11632a1a585339ab1da9c39291fb964f9442290e.tar
perl-MDK-Common-11632a1a585339ab1da9c39291fb964f9442290e.tar.gz
perl-MDK-Common-11632a1a585339ab1da9c39291fb964f9442290e.tar.bz2
perl-MDK-Common-11632a1a585339ab1da9c39291fb964f9442290e.tar.xz
perl-MDK-Common-11632a1a585339ab1da9c39291fb964f9442290e.zip
- round_up(), round_down(): workaround "Illegal modulus zero" (#43165)
-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 }