8 # 2s complement assumption. Won't break test, just makes the internals of
9 # the SVs less interesting if were not on 2s complement system.
11 my $uv_maxm1 = ~0 ^ 1;
13 $uv_big = ($uv_big - 20000) | 1;
14 my ($iv0, $iv1, $ivm1, $iv_min, $iv_max, $iv_big, $iv_small);
15 $iv_max = $uv_max; # Do copy, *then* divide
25 $iv_big = $iv_max - 3;
26 $iv_small = $iv_min + 2;
28 my $uv_bigi = $iv_big;
31 my @array = qw(perl rules);
33 # Seems one needs to perform the maths on 'Inf' to get the NV correctly primed.
34 @FOO = ('s', 'N/A', 'a', 'NaN', -1, undef, 0, 1, 3.14, 1e37, 0.632120558, -.5,
35 'Inf'+1, '-Inf'-1, 0x0, 0x1, 0x5, 0xFFFFFFFF, $uv_max, $uv_maxm1,
36 $uv_big, $uv_bigi, $iv0, $iv1, $ivm1, $iv_min, $iv_max, $iv_big,
37 $iv_small, \$array[0], \$array[0], \$array[1], \$^X);
39 $expect = 7 * ($#FOO+2) * ($#FOO+1);
43 my ($test, $left, $threeway, $right, $result, $i, $j, $boolean) = @_;
44 $result = defined $result ? "'$result'" : 'undef';
45 print "not ok $test # ($left <=> $right) gives: $result \$i=$i \$j=$j, $boolean disagrees\n";
49 for my $i (0..$#FOO) {
50 for my $j ($i..$#FOO) {
52 # Comparison routines may convert these internally, which would change
53 # what is used to determine the comparison on later runs. Hence copy
54 my ($i1, $i2, $i3, $i4, $i5, $i6, $i7, $i8, $i9, $i10,
55 $i11, $i12, $i13, $i14, $i15, $i16, $i17) =
56 ($FOO[$i], $FOO[$i], $FOO[$i], $FOO[$i], $FOO[$i], $FOO[$i],
57 $FOO[$i], $FOO[$i], $FOO[$i], $FOO[$i], $FOO[$i], $FOO[$i],
58 $FOO[$i], $FOO[$i], $FOO[$i], $FOO[$i], $FOO[$i]);
59 my ($j1, $j2, $j3, $j4, $j5, $j6, $j7, $j8, $j9, $j10,
60 $j11, $j12, $j13, $j14, $j15, $j16, $j17) =
61 ($FOO[$j], $FOO[$j], $FOO[$j], $FOO[$j], $FOO[$j], $FOO[$j],
62 $FOO[$j], $FOO[$j], $FOO[$j], $FOO[$j], $FOO[$j], $FOO[$j],
63 $FOO[$j], $FOO[$j], $FOO[$j], $FOO[$j], $FOO[$j]);
64 my $cmp = $i1 <=> $j1;
65 if (!defined($cmp) ? !($i2 < $j2)
66 : ($cmp == -1 && $i2 < $j2 ||
67 $cmp == 0 && !($i2 < $j2) ||
68 $cmp == 1 && !($i2 < $j2)))
73 nok ($ok, $i3, '<=>', $j3, $cmp, $i, $j, '<');
76 if (!defined($cmp) ? !($i4 == $j4)
77 : ($cmp == -1 && !($i4 == $j4) ||
78 $cmp == 0 && $i4 == $j4 ||
79 $cmp == 1 && !($i4 == $j4)))
84 nok ($ok, $i3, '<=>', $j3, $cmp, $i, $j, '==');
87 if (!defined($cmp) ? !($i5 > $j5)
88 : ($cmp == -1 && !($i5 > $j5) ||
89 $cmp == 0 && !($i5 > $j5) ||
90 $cmp == 1 && ($i5 > $j5)))
95 nok ($ok, $i3, '<=>', $j3, $cmp, $i, $j, '>');
98 if (!defined($cmp) ? !($i6 >= $j6)
99 : ($cmp == -1 && !($i6 >= $j6) ||
100 $cmp == 0 && $i6 >= $j6 ||
101 $cmp == 1 && $i6 >= $j6))
106 nok ($ok, $i3, '<=>', $j3, $cmp, $i, $j, '>=');
109 # OK, so the docs are wrong it seems. NaN != NaN
110 if (!defined($cmp) ? ($i7 != $j7)
111 : ($cmp == -1 && $i7 != $j7 ||
112 $cmp == 0 && !($i7 != $j7) ||
113 $cmp == 1 && $i7 != $j7))
118 nok ($ok, $i3, '<=>', $j3, $cmp, $i, $j, '!=');
121 if (!defined($cmp) ? !($i8 <= $j8)
122 : ($cmp == -1 && $i8 <= $j8 ||
123 $cmp == 0 && $i8 <= $j8 ||
124 $cmp == 1 && !($i8 <= $j8)))
129 nok ($ok, $i3, '<=>', $j3, $cmp, $i, $j, '<=');
132 my $pmc = $j16 <=> $i16; # cmp it in reverse
133 # Should give -ve of other answer, or undef for NaNs
134 # a + -a should be zero. not zero is truth. which avoids using ==
135 if (defined($cmp) ? !($cmp + $pmc) : !defined $pmc)
140 nok ($ok, $i3, '<=>', $j3, $cmp, $i, $j, '<=> transposed');
147 if ($cmp == -1 && $i10 lt $j10 ||
148 $cmp == 0 && !($i10 lt $j10) ||
149 $cmp == 1 && !($i10 lt $j10))
154 nok ($ok, $i3, 'cmp', $j3, $cmp, $i, $j, 'lt');
157 if ($cmp == -1 && !($i11 eq $j11) ||
158 $cmp == 0 && ($i11 eq $j11) ||
159 $cmp == 1 && !($i11 eq $j11))
164 nok ($ok, $i3, 'cmp', $j3, $cmp, $i, $j, 'eq');
167 if ($cmp == -1 && !($i12 gt $j12) ||
168 $cmp == 0 && !($i12 gt $j12) ||
169 $cmp == 1 && ($i12 gt $j12))
174 nok ($ok, $i3, 'cmp', $j3, $cmp, $i, $j, 'gt');
177 if ($cmp == -1 && $i13 le $j13 ||
178 $cmp == 0 && ($i13 le $j13) ||
179 $cmp == 1 && !($i13 le $j13))
184 nok ($ok, $i3, 'cmp', $j3, $cmp, $i, $j, 'le');
187 if ($cmp == -1 && ($i14 ne $j14) ||
188 $cmp == 0 && !($i14 ne $j14) ||
189 $cmp == 1 && ($i14 ne $j14))
194 nok ($ok, $i3, 'cmp', $j3, $cmp, $i, $j, 'ne');
197 if ($cmp == -1 && !($i15 ge $j15) ||
198 $cmp == 0 && ($i15 ge $j15) ||
199 $cmp == 1 && ($i15 ge $j15))
204 nok ($ok, $i3, 'cmp', $j3, $cmp, $i, $j, 'ge');
207 $pmc = $j17 cmp $i17; # cmp it in reverse
208 # Should give -ve of other answer
209 # a + -a should be zero. not zero is truth. which avoids using ==
215 nok ($ok, $i3, '<=>', $j3, $cmp, $i, $j, 'cmp transposed');