diff options
author | P. J. McDermott <pj@pehjota.net> | 2017-01-05 17:24:35 (EST) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2017-01-05 17:24:35 (EST) |
commit | 95de0f40d6059cc62c7d3fb8295e12a74c128a95 (patch) | |
tree | 2717175b14427c0600f1384b6272171dd7f1cd2b | |
parent | 88f8a42f78b7d010294b26e9130c3ffa12ed46e4 (diff) | |
download | Math-Decimal-FastPP-95de0f40d6059cc62c7d3fb8295e12a74c128a95.zip Math-Decimal-FastPP-95de0f40d6059cc62c7d3fb8295e12a74c128a95.tar.gz Math-Decimal-FastPP-95de0f40d6059cc62c7d3fb8295e12a74c128a95.tar.bz2 |
drhtz(), drhfz(): Properly handle negative significands
-rw-r--r-- | lib/Math/Decimal/FastPP.pm | 12 |
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/; |