summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Math/Decimal/FastPP.pm12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/Math/Decimal/FastPP.pm b/lib/Math/Decimal/FastPP.pm
index 9723013..d140132 100644
--- a/lib/Math/Decimal/FastPP.pm
+++ b/lib/Math/Decimal/FastPP.pm
@@ -166,7 +166,11 @@ sub drhtz
{
my ($ai, $af, $ad) = $_[0] =~ m/^(.*)\.(.{$_[1]})(.*)$/ or return;
my $as = $ai . $af;
- ++$as if $ad > "5" . "0" x (length($ad) - 1);
+ if ($as >= 0) {
+ ++$as if $ad > "5" . "0" x (length($ad) - 1);
+ } else {
+ --$as if $ad > "5" . "0" x (length($ad) - 1);
+ }
$as = sprintf("%0$_[1]i", $as);
# The substr() code is 400% faster than this regular expression code.
#$as =~ s/(.{$_[1]})$/.$1/;
@@ -196,7 +200,11 @@ sub drhfz
{
my ($ai, $af, $ad) = $_[0] =~ m/^(.*)\.(.{$_[1]})(.*)$/ or return;
my $as = $ai . $af;
- ++$as if $ad >= "5" . "0" x (length($ad) - 1);
+ if ($as >= 0) {
+ ++$as if $ad >= "5" . "0" x (length($ad) - 1);
+ } else {
+ --$as if $ad >= "5" . "0" x (length($ad) - 1);
+ }
$as = sprintf("%0$_[1]i", $as);
# The substr() code is 400% faster than this regular expression code.
#$as =~ s/(.{$_[1]})$/.$1/;