diff options
author | Nicholas Clark <nick@ccl4.org> | 2001-11-20 21:59:51 +0000 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2001-11-21 00:40:09 +0000 |
commit | e61d22efbb00a7fa2de05bf2c594ec3b6f671baf (patch) | |
tree | 8af835f85dda1bc7fd9f6e1627e6b47d928be746 | |
parent | 9124316ee7cc50a30161a176ef51b0432a068a78 (diff) | |
download | perl-e61d22efbb00a7fa2de05bf2c594ec3b6f671baf.tar.gz |
spaceship and refs
Message-ID: <20011120215951.U62891@plum.flirble.org>
p4raw-id: //depot/perl@13147
-rw-r--r-- | pp.c | 7 | ||||
-rw-r--r-- | pp_hot.c | 3 | ||||
-rwxr-xr-x | t/op/cmp.t | 43 |
3 files changed, 42 insertions, 11 deletions
@@ -1759,7 +1759,8 @@ PP(pp_ne) dSP; tryAMAGICbinSET(ne,0); #ifndef NV_PRESERVES_UV if (SvROK(TOPs) && SvROK(TOPm1s)) { - SETs(boolSV(SvRV(TOPs) != SvRV(TOPm1s))); + SP--; + SETs(boolSV(SvRV(TOPs) != SvRV(TOPp1s))); RETURN; } #endif @@ -1830,7 +1831,9 @@ PP(pp_ncmp) dSP; dTARGET; tryAMAGICbin(ncmp,0); #ifndef NV_PRESERVES_UV if (SvROK(TOPs) && SvROK(TOPm1s)) { - SETi(PTR2UV(SvRV(TOPs)) - PTR2UV(SvRV(TOPm1s))); + UV right = PTR2UV(SvRV(POPs)); + UV left = PTR2UV(SvRV(TOPs)); + SETi((left > right) - (left < right)); RETURN; } #endif @@ -237,7 +237,8 @@ PP(pp_eq) dSP; tryAMAGICbinSET(eq,0); #ifndef NV_PRESERVES_UV if (SvROK(TOPs) && SvROK(TOPm1s)) { - SETs(boolSV(SvRV(TOPs) == SvRV(TOPm1s))); + SP--; + SETs(boolSV(SvRV(TOPs) == SvRV(TOPp1s))); RETURN; } #endif diff --git a/t/op/cmp.t b/t/op/cmp.t index c6d72f13eb..1eca8ab2b8 100755 --- a/t/op/cmp.t +++ b/t/op/cmp.t @@ -28,13 +28,15 @@ $iv_min = $iv_max; my $uv_bigi = $iv_big; $uv_bigi |= 0x0; +my @array = qw(perl rules); + # Seems one needs to perform the maths on 'Inf' to get the NV correctly primed. @FOO = ('s', 'N/A', 'a', 'NaN', -1, undef, 0, 1, 3.14, 1e37, 0.632120558, -.5, 'Inf'+1, '-Inf'-1, 0x0, 0x1, 0x5, 0xFFFFFFFF, $uv_max, $uv_maxm1, $uv_big, $uv_bigi, $iv0, $iv1, $ivm1, $iv_min, $iv_max, $iv_big, - $iv_small); + $iv_small, \$array[0], \$array[0], \$array[1], \$^X); -$expect = 6 * ($#FOO+2) * ($#FOO+1); +$expect = 7 * ($#FOO+2) * ($#FOO+1); print "1..$expect\n"; sub nok ($$$$$$$$) { @@ -50,14 +52,14 @@ for my $i (0..$#FOO) { # Comparison routines may convert these internally, which would change # what is used to determine the comparison on later runs. Hence copy my ($i1, $i2, $i3, $i4, $i5, $i6, $i7, $i8, $i9, $i10, - $i11, $i12, $i13, $i14, $i15) = - ($FOO[$i], $FOO[$i], $FOO[$i], $FOO[$i], $FOO[$i], - $FOO[$i], $FOO[$i], $FOO[$i], $FOO[$i], $FOO[$i], + $i11, $i12, $i13, $i14, $i15, $i16, $i17) = + ($FOO[$i], $FOO[$i], $FOO[$i], $FOO[$i], $FOO[$i], $FOO[$i], + $FOO[$i], $FOO[$i], $FOO[$i], $FOO[$i], $FOO[$i], $FOO[$i], $FOO[$i], $FOO[$i], $FOO[$i], $FOO[$i], $FOO[$i]); my ($j1, $j2, $j3, $j4, $j5, $j6, $j7, $j8, $j9, $j10, - $j11, $j12, $j13, $j14, $j15) = - ($FOO[$j], $FOO[$j], $FOO[$j], $FOO[$j], $FOO[$j], - $FOO[$j], $FOO[$j], $FOO[$j], $FOO[$j], $FOO[$j], + $j11, $j12, $j13, $j14, $j15, $j16, $j17) = + ($FOO[$j], $FOO[$j], $FOO[$j], $FOO[$j], $FOO[$j], $FOO[$j], + $FOO[$j], $FOO[$j], $FOO[$j], $FOO[$j], $FOO[$j], $FOO[$j], $FOO[$j], $FOO[$j], $FOO[$j], $FOO[$j], $FOO[$j]); my $cmp = $i1 <=> $j1; if (!defined($cmp) ? !($i2 < $j2) @@ -127,6 +129,20 @@ for my $i (0..$#FOO) { nok ($ok, $i3, '<=>', $j3, $cmp, $i, $j, '<='); } $ok++; + my $pmc = $j16 <=> $i16; # cmp it in reverse + # Should give -ve of other answer, or undef for NaNs + # a + -a should be zero. not zero is truth. which avoids using == + if (defined($cmp) ? !($cmp + $pmc) : !defined $pmc) + { + print "ok $ok\n"; + } + else { + nok ($ok, $i3, '<=>', $j3, $cmp, $i, $j, '<=> transposed'); + } + + + # String comparisons + $ok++; $cmp = $i9 cmp $j9; if ($cmp == -1 && $i10 lt $j10 || $cmp == 0 && !($i10 lt $j10) || @@ -187,5 +203,16 @@ for my $i (0..$#FOO) { else { nok ($ok, $i3, 'cmp', $j3, $cmp, $i, $j, 'ge'); } + $ok++; + $pmc = $j17 cmp $i17; # cmp it in reverse + # Should give -ve of other answer + # a + -a should be zero. not zero is truth. which avoids using == + if (!($cmp + $pmc)) + { + print "ok $ok\n"; + } + else { + nok ($ok, $i3, '<=>', $j3, $cmp, $i, $j, 'cmp transposed'); + } } } |