diff options
author | Steven Knight <knight@theopera.baldmt.citilink.com> | 1999-02-07 19:16:24 -0600 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 1999-02-15 05:30:13 +0000 |
commit | 5d7098d560a042a848a6e60f96567ce4b694c6c7 (patch) | |
tree | 2a59f016e74fb1b692e98c2ccca21c659929759e /lib/bigfloat.pl | |
parent | d050a71cca1645f880852f454e45f0b5cf02f6df (diff) | |
download | perl-5d7098d560a042a848a6e60f96567ce4b694c6c7.tar.gz |
fix bugs in the handling of negative numbers, among other things
Message-Id: <199902080716.BAA24652@theopera.baldmt.citilink.com>
Subject: Math::BigFloat and Math::BigInt
p4raw-id: //depot/perl@2934
Diffstat (limited to 'lib/bigfloat.pl')
-rw-r--r-- | lib/bigfloat.pl | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/bigfloat.pl b/lib/bigfloat.pl index d687c784f1..032dfe6fb5 100644 --- a/lib/bigfloat.pl +++ b/lib/bigfloat.pl @@ -6,7 +6,7 @@ require "bigint.pl"; # # number format # canonical strings have the form /[+-]\d+E[+-]\d+/ -# Input values can have inbedded whitespace +# Input values can have embedded whitespace # Error returns # 'NaN' An input parameter was "Not a Number" or # divide by zero or sqrt of negative number @@ -126,7 +126,7 @@ sub main'fdiv #(fnum_str, fnum_str[,scale]) return fnum_str $scale = length($xm)-1 if (length($xm)-1 > $scale); $scale = length($ym)-1 if (length($ym)-1 > $scale); $scale = $scale + length($ym) - length($xm); - &norm(&round(&'bdiv($xm.('0' x $scale),$ym),$ym), + &norm(&round(&'bdiv($xm.('0' x $scale),$ym),&'babs($ym)), $xe-$ye-$scale); } } @@ -186,7 +186,12 @@ sub main'ffround { #(fnum_str, scale) return fnum_str if ($xe < 1) { '+0E+0'; } elsif ($xe == 1) { - &norm(&round('+0',"+0".substr($xm,$[+1,1),"+10"), $scale); + # The first substr preserves the sign, which means that + # we'll pass a non-normalized "-0" to &round when rounding + # -0.006 (for example), purely so that &round won't lose + # the sign. + &norm(&round(substr($xm,$[,1).'0', + "+0".substr($xm,$[+1,1),"+10"), $scale); } else { &norm(&round(substr($xm,$[,$xe), "+0".substr($xm,$[+$xe,1),"+10"), $scale); |