7 if ($Config::Config{'uvsize'} != 8) {
8 print "1..0 # Skip -- Perl configured with 32-bit ints\n";
14 use Test::More 'tests' => 100;
17 my $ii = 36028797018963971; # 2^55 + 3
20 ### Tests with numerifying large positive int
22 use overload '0+' => sub { ${$_[0]} += 1; $ii },
25 my $oo = bless(\do{my $x = 0}, 'Oobj');
28 is("$oo", "$ii", '0+ overload with stringification');
29 is($$oo, $cnt++, 'overload called once');
31 is($oo>>3, $ii>>3, '0+ overload with bit shift right');
32 is($$oo, $cnt++, 'overload called once');
34 is($oo<<2, $ii<<2, '0+ overload with bit shift left');
35 is($$oo, $cnt++, 'overload called once');
37 is($oo|0xFF00, $ii|0xFF00, '0+ overload with bitwise or');
38 is($$oo, $cnt++, 'overload called once');
40 is($oo&0xFF03, $ii&0xFF03, '0+ overload with bitwise and');
41 is($$oo, $cnt++, 'overload called once');
43 ok($oo == $ii, '0+ overload with equality');
44 is($$oo, $cnt++, 'overload called once');
46 is(int($oo), $ii, '0+ overload with int()');
47 is($$oo, $cnt++, 'overload called once');
49 is(abs($oo), $ii, '0+ overload with abs()');
50 is($$oo, $cnt++, 'overload called once');
52 is(-$oo, -$ii, '0+ overload with unary minus');
53 is($$oo, $cnt++, 'overload called once');
55 is(0+$oo, $ii, '0+ overload with addition');
56 is($$oo, $cnt++, 'overload called once');
57 is($oo+0, $ii, '0+ overload with addition');
58 is($$oo, $cnt++, 'overload called once');
59 is($oo+$oo, 2*$ii, '0+ overload with addition');
61 is($$oo, $cnt++, 'overload called once');
63 is(0-$oo, -$ii, '0+ overload with subtraction');
64 is($$oo, $cnt++, 'overload called once');
65 is($oo-99, $ii-99, '0+ overload with subtraction');
66 is($$oo, $cnt++, 'overload called once');
68 is(2*$oo, 2*$ii, '0+ overload with multiplication');
69 is($$oo, $cnt++, 'overload called once');
70 is($oo*3, 3*$ii, '0+ overload with multiplication');
71 is($$oo, $cnt++, 'overload called once');
73 is($oo/1, $ii, '0+ overload with division');
74 is($$oo, $cnt++, 'overload called once');
75 is($ii/$oo, 1, '0+ overload with division');
76 is($$oo, $cnt++, 'overload called once');
78 is($oo%100, $ii%100, '0+ overload with modulo');
79 is($$oo, $cnt++, 'overload called once');
80 is($ii%$oo, 0, '0+ overload with modulo');
81 is($$oo, $cnt++, 'overload called once');
83 is($oo**1, $ii, '0+ overload with exponentiation');
84 is($$oo, $cnt++, 'overload called once');
87 ### Tests with numerifying large negative int
89 use overload '0+' => sub { ${$_[0]} += 1; -$ii },
92 $oo = bless(\do{my $x = 0}, 'Oobj2');
95 is(int($oo), -$ii, '0+ overload with int()');
96 is($$oo, $cnt++, 'overload called once');
98 is(abs($oo), $ii, '0+ overload with abs()');
99 is($$oo, $cnt++, 'overload called once');
101 is(-$oo, $ii, '0+ overload with unary -');
102 is($$oo, $cnt++, 'overload called once');
104 is(0+$oo, -$ii, '0+ overload with addition');
105 is($$oo, $cnt++, 'overload called once');
106 is($oo+0, -$ii, '0+ overload with addition');
107 is($$oo, $cnt++, 'overload called once');
108 is($oo+$oo, -2*$ii, '0+ overload with addition');
110 is($$oo, $cnt++, 'overload called once');
112 is(0-$oo, $ii, '0+ overload with subtraction');
113 is($$oo, $cnt++, 'overload called once');
115 is(2*$oo, -2*$ii, '0+ overload with multiplication');
116 is($$oo, $cnt++, 'overload called once');
117 is($oo*3, -3*$ii, '0+ overload with multiplication');
118 is($$oo, $cnt++, 'overload called once');
120 is($oo/1, -$ii, '0+ overload with division');
121 is($$oo, $cnt++, 'overload called once');
122 is($ii/$oo, -1, '0+ overload with division');
123 is($$oo, $cnt++, 'overload called once');
125 is($oo%100, (-$ii)%100, '0+ overload with modulo');
126 is($$oo, $cnt++, 'overload called once');
127 is($ii%$oo, 0, '0+ overload with modulo');
128 is($$oo, $cnt++, 'overload called once');
130 is($oo**1, -$ii, '0+ overload with exponentiation');
131 is($$oo, $cnt++, 'overload called once');
133 ### Tests with overloading but no fallback
136 'int' => sub { ${$_[0]} += 1; $ii },
137 'abs' => sub { ${$_[0]} += 1; $ii },
138 'neg' => sub { ${$_[0]} += 1; -$ii },
141 my $res = (ref($_[0]) eq __PACKAGE__) ? $ii : $_[0];
142 $res += (ref($_[1]) eq __PACKAGE__) ? $ii : $_[1];
146 my ($l, $r) = ($_[2]) ? (1, 0) : (0, 1);
147 my $res = (ref($_[$l]) eq __PACKAGE__) ? $ii : $_[$l];
148 $res -= (ref($_[$r]) eq __PACKAGE__) ? $ii : $_[$r];
152 my $res = (ref($_[0]) eq __PACKAGE__) ? $ii : $_[0];
153 $res *= (ref($_[1]) eq __PACKAGE__) ? $ii : $_[1];
157 my ($l, $r) = ($_[2]) ? (1, 0) : (0, 1);
158 my $res = (ref($_[$l]) eq __PACKAGE__) ? $ii+1 : $_[$l];
159 $res /= (ref($_[$r]) eq __PACKAGE__) ? $ii+1 : $_[$r];
163 my ($l, $r) = ($_[2]) ? (1, 0) : (0, 1);
164 my $res = (ref($_[$l]) eq __PACKAGE__) ? $ii : $_[$l];
165 $res %= (ref($_[$r]) eq __PACKAGE__) ? $ii : $_[$r];
169 my ($l, $r) = ($_[2]) ? (1, 0) : (0, 1);
170 my $res = (ref($_[$l]) eq __PACKAGE__) ? $ii : $_[$l];
171 $res **= (ref($_[$r]) eq __PACKAGE__) ? $ii : $_[$r];
174 $oo = bless(\do{my $x = 0}, 'Oobj3');
177 is(int($oo), $ii, 'int() overload');
178 is($$oo, $cnt++, 'overload called once');
180 is(abs($oo), $ii, 'abs() overload');
181 is($$oo, $cnt++, 'overload called once');
183 is(-$oo, -$ii, 'neg overload');
184 is($$oo, $cnt++, 'overload called once');
186 is(0+$oo, $ii, '+ overload');
187 is($$oo, $cnt++, 'overload called once');
188 is($oo+0, $ii, '+ overload');
189 is($$oo, $cnt++, 'overload called once');
190 is($oo+$oo, 2*$ii, '+ overload');
191 is($$oo, $cnt++, 'overload called once');
193 is(0-$oo, -$ii, '- overload');
194 is($$oo, $cnt++, 'overload called once');
195 is($oo-99, $ii-99, '- overload');
196 is($$oo, $cnt++, 'overload called once');
198 is($oo*2, 2*$ii, '* overload');
199 is($$oo, $cnt++, 'overload called once');
200 is(-3*$oo, -3*$ii, '* overload');
201 is($$oo, $cnt++, 'overload called once');
203 is($oo/2, ($ii+1)/2, '/ overload');
204 is($$oo, $cnt++, 'overload called once');
205 is(($ii+1)/$oo, 1, '/ overload');
206 is($$oo, $cnt++, 'overload called once');
208 is($oo%100, $ii%100, '% overload');
209 is($$oo, $cnt++, 'overload called once');
210 is($ii%$oo, 0, '% overload');
211 is($$oo, $cnt++, 'overload called once');
213 is($oo**1, $ii, '** overload');
214 is($$oo, $cnt++, 'overload called once');