From e3c7ef20866011e0e98de5b78863094f34fd2bd6 Mon Sep 17 00:00:00 2001 From: "M. J. T. Guy" Date: Fri, 24 Jul 1998 19:29:53 +0100 Subject: [PATCH] fix behavior of <=> on bigints Message-Id: Subject: [PATCH] Re: Math::BigInt <=> op is not correct. p4raw-id: //depot/maint-5.005/perl@1652 --- lib/Math/BigInt.pm | 8 ++++---- t/lib/bigintpm.t | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/Math/BigInt.pm b/lib/Math/BigInt.pm index bbd15e4..ef4af61 100644 --- a/lib/Math/BigInt.pm +++ b/lib/Math/BigInt.pm @@ -82,8 +82,8 @@ sub external { #(int_num_array) return num_str # Negate input value. sub bneg { #(num_str) return num_str local($_) = &bnorm(@_); - vec($_,0,8) ^= ord('+') ^ ord('-') unless $_ eq '+0'; - s/^H/N/; + return $_ if $_ eq '+0' or $_ eq 'NaN'; + vec($_,0,8) ^= ord('+') ^ ord('-'); $_; } @@ -106,7 +106,7 @@ sub bcmp { #(num_str, num_str) return cond_code } elsif ($y eq 'NaN') { undef; } else { - &cmp($x,$y); + &cmp($x,$y) <=> 0; } } @@ -393,7 +393,7 @@ are not numbers, as well as the result of dividing by zero. =head1 Autocreating constants After C all the integer decimal constants -in the given scope are converted to C. This convertion +in the given scope are converted to C. This conversion happens at compile time. In particular diff --git a/t/lib/bigintpm.t b/t/lib/bigintpm.t index ebaecac..4357975 100755 --- a/t/lib/bigintpm.t +++ b/t/lib/bigintpm.t @@ -10,7 +10,7 @@ use Math::BigInt; $test = 0; $| = 1; -print "1..246\n"; +print "1..247\n"; while () { chop; if (s/^&//) { @@ -116,6 +116,7 @@ abc:+0:NaN +124:+123:+1 -123:-124:+1 -124:-123:-1 ++100:+5:+1 &badd abc:abc:NaN abc:+0:NaN -- 2.7.4