diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2008-10-01 11:53:57 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2008-10-01 11:53:57 +0000 |
commit | 11632a1a585339ab1da9c39291fb964f9442290e (patch) | |
tree | 1163388bcb6fb01ed730f6f214a446106bc62c2d /lib/MDK/Common | |
parent | 3dbc55dbd7834394529cc9a0473389129e7572b3 (diff) | |
download | perl-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)
Diffstat (limited to 'lib/MDK/Common')
-rw-r--r-- | lib/MDK/Common/Math.pm | 4 |
1 files changed, 2 insertions, 2 deletions
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 } |