From 11632a1a585339ab1da9c39291fb964f9442290e Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Wed, 1 Oct 2008 11:53:57 +0000 Subject: - round_up(), round_down(): workaround "Illegal modulus zero" (#43165) --- NEWS | 2 ++ lib/MDK/Common/Math.pm | 4 ++-- 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 } -- cgit v1.2.1