X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Fbigfloat.pl;h=032dfe6fb52b3227e05bd7f2cf3bdf2e4fd4b278;hb=4802d5d799ab971f97d7df94b7f1637c213350a8;hp=d687c784f1caef2135613d509969af7dad9153fb;hpb=afea815c58c54233979716dd5770b69df2df51f8;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/bigfloat.pl b/lib/bigfloat.pl index d687c78..032dfe6 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);