use Exporter; # just for use to be happy
@ISA = (Exporter);
+$VERSION = '0.01'; # never had version before
use overload
'+' => sub {new Math::BigFloat &fadd},
sub new {
my ($class) = shift;
my ($foo) = fnorm(shift);
- panic("Not a number initialized to Math::BigFloat") if $foo eq "NaN";
bless \$foo, $class;
}
+
sub numify { 0 + "${$_[0]}" } # Not needed, additional overhead
# comparing to direct compilation based on
# stringify
sub fnorm { #(string) return fnum_str
local($_) = @_;
s/\s+//g; # strip white space
+ no warnings; # $4 and $5 below might legitimately be undefined
if (/^([+-]?)(\d*)(\.(\d*))?([Ee]([+-]?\d+))?$/ && "$2$4" ne '') {
&norm(($1 ? "$1$2$4" : "+$2$4"),(($4 ne '') ? $6-length($4) : $6));
} else {
# normalize number -- for internal use
sub norm { #(mantissa, exponent) return fnum_str
local($_, $exp) = @_;
+ $exp = 0 unless defined $exp;
if ($_ eq 'NaN') {
'NaN';
} else {
} else {
local($cmp) = Math::BigInt::bcmp(Math::BigInt::bmul($r,'+2'),$base);
if ( $cmp < 0 ||
- ($cmp == 0 &&
- ( $rnd_mode eq 'zero' ||
+ ($cmp == 0 && (
+ ($rnd_mode eq 'zero' ) ||
($rnd_mode eq '-inf' && (substr($q,$[,1) eq '+')) ||
($rnd_mode eq '+inf' && (substr($q,$[,1) eq '-')) ||
- ($rnd_mode eq 'even' && $q =~ /[24680]$/) ||
- ($rnd_mode eq 'odd' && $q =~ /[13579]$/) )) ) {
+ ($rnd_mode eq 'even' && $q =~ /[13579]$/ ) ||
+ ($rnd_mode eq 'odd' && $q =~ /[24680]$/ ) )
+ )
+ ) {
$q; # round down
} else {
Math::BigInt::badd($q, ((substr($q,$[,1) eq '-') ? '-1' : '+1'));
if ($x eq "NaN" || $y eq "NaN") {
undef;
} else {
- ord($y) <=> ord($x)
- ||
- ( local($xm,$xe,$ym,$ye) = split('E', $x."E$y"),
- (($xe <=> $ye) * (substr($x,$[,1).'1')
- || Math::BigInt::cmp($xm,$ym))
- );
+ local($xm,$xe,$ym,$ye) = split('E', $x."E$y");
+ if ($xm eq '+0' || $ym eq '+0') {
+ return $xm <=> $ym;
+ }
+ if ( $xe < $ye ) # adjust the exponents to be equal
+ {
+ $ym .= '0' x ($ye - $xe);
+ $ye = $xe;
+ }
+ elsif ( $ye < $xe ) # same here
+ {
+ $xm .= '0' x ($xe - $ye);
+ $xe = $ye;
+ }
+ return Math::BigInt::cmp($xm,$ym);
}
}