1# -*- mode: perl; -*-
2
3# Note that this does not test Math::BigFloat upgrading.
4
5use strict;
6use warnings;
7
8use Test::More tests => 93;
9
10use Math::BigInt   upgrade   => 'Math::BigFloat';
11use Math::BigFloat downgrade => 'Math::BigInt';
12
13is(Math::BigFloat->downgrade(), 'Math::BigInt', 'Math::BigFloat->downgrade()');
14is(Math::BigInt->upgrade(), 'Math::BigFloat', 'Math::BigInt->upgrade()');
15
16# bug until v1.67:
17
18subtest 'Math::BigFloat->new("0.2E0")' => sub {
19    plan tests => 2;
20    my $x = Math::BigFloat->new("0.2E0");
21    is($x, "0.2", 'value of $x');
22    is(ref($x), "Math::BigFloat", '$x is a Math::BigFloat');
23};
24
25subtest 'Math::BigFloat->new("0.2E1")' => sub {
26    plan tests => 2;
27    my $x = Math::BigFloat->new("2");
28    is($x, "2", 'value of $x');
29    is(ref($x), "Math::BigInt", '$x is downgraded to a Math::BigInt');
30};
31
32subtest 'Math::BigFloat->new("0.2E2")' => sub {
33    plan tests => 2;
34    my $x = Math::BigFloat->new("20");
35    is($x, "20", 'value of $x');
36    is(ref($x), "Math::BigInt", '$x is downgraded to a Math::BigInt');
37};
38
39# $x is a downgraded to a Math::BigInt, but bpow() and bsqrt() upgrades to
40# Math::BigFloat.
41
42Math::BigFloat -> div_scale(20);        # make it a bit faster
43
44my ($x, $y, $z);
45subtest '$x = Math::BigFloat -> new(2);' => sub {
46    plan tests => 2;
47    $x = Math::BigFloat -> new(2);     # downgrades
48    is(ref($x), 'Math::BigInt', '$x is downgraded to a Math::BigInt');
49    cmp_ok($x, "==", 2, 'value of $x');
50};
51
52subtest '$y = Math::BigFloat -> bpow("2", "0.5");' => sub {
53    plan tests => 2;
54    $y = Math::BigFloat -> bpow("2", "0.5");
55    is(ref($y), 'Math::BigFloat', '$y is a Math::BigFloat');
56    cmp_ok($y, "==", "1.4142135623730950488", 'value of $y');
57};
58
59subtest '$z = $x -> bsqrt();' => sub {
60    plan tests => 2;
61    $z = $x -> bsqrt();
62    is(ref($z), 'Math::BigFloat', '$y is a Math::BigFloat');
63    cmp_ok($z, "==", "1.4142135623730950488", 'value of $z');
64};
65
66# log_2(16) = 4
67
68subtest '$x = Math::BigFloat -> new(16); $y = $x -> blog(2);' => sub {
69    plan tests => 4;
70    $x = Math::BigFloat -> new(16);
71    is(ref($x), 'Math::BigInt', '$x is downgraded to a Math::BigInt');
72    cmp_ok($x, "==", 16, 'value of $x');
73    $y = $x -> blog(2);
74    is(ref($y), 'Math::BigInt', '$y is downgraded to a Math::BigInt');
75    cmp_ok($y, "==", 4, 'value of $y');
76};
77
78# log_16(2) = 1/4
79
80subtest '$x = Math::BigFloat -> new(2); $y = $x -> blog(16);' => sub {
81    plan tests => 4;
82    $x = Math::BigFloat -> new(2);
83    is(ref($x), 'Math::BigInt', '$x is downgraded to a Math::BigInt');
84    cmp_ok($x, "==", 2, 'value of $x');
85    $y = $x -> blog(16);
86    is(ref($y), 'Math::BigFloat', '$y is a Math::BigFloat');
87    cmp_ok($y, "==", 0.25, 'value of $y');
88};
89
90################################################################################
91# Verify that constructors downgrade when they should.
92
93note("Enable downgrading, and see if constructors downgrade");
94
95note("testing new()");
96
97$x = Math::BigFloat -> new("0.5");
98subtest '$x = Math::BigFloat -> new("0.5")' => sub {
99    plan tests => 2;
100    cmp_ok($x, "==", 0.5, 'value of $x');
101    is(ref $x, "Math::BigFloat", "does not downgrade from Math::BigFloat");
102};
103
104$x = Math::BigFloat -> new("4");
105subtest '$x = Math::BigFloat -> new("4")' => sub {
106    plan tests => 2;
107    cmp_ok($x, "==", 4, 'value of $x');
108    is(ref $x, "Math::BigInt", "downgrades to Math::BigInt");
109};
110
111$x = Math::BigFloat -> new("0");
112subtest '$x = Math::BigFloat -> new("0")' => sub {
113    plan tests => 2;
114    cmp_ok($x, "==", 0, 'value of $x');
115    is(ref $x, "Math::BigInt", "downgrades to Math::BigInt");
116};
117
118$x = Math::BigFloat -> new("1");
119subtest '$x = Math::BigFloat -> new("1")' => sub {
120    plan tests => 2;
121    cmp_ok($x, "==", 1, 'value of $x');
122    is(ref $x, "Math::BigInt", "downgrades to Math::BigInt");
123};
124
125$x = Math::BigFloat -> new("Inf");
126subtest '$x = Math::BigFloat -> new("inf")' => sub {
127    plan tests => 2;
128    cmp_ok($x, "==", "Inf", 'value of $x');
129    is(ref $x, "Math::BigInt", "downgrades to Math::BigInt");
130};
131
132$x = Math::BigFloat -> new("NaN");
133subtest '$x = Math::BigFloat -> new("NaN")' => sub {
134    plan tests => 2;
135    is($x, "NaN", );
136    is(ref $x, "Math::BigInt", "downgrades to Math::BigInt");
137};
138
139note("testing bzero()");
140
141$x = Math::BigFloat -> bzero();
142subtest '$x = Math::BigFloat -> bzero()' => sub {
143    plan tests => 2;
144    cmp_ok($x, '==', 0, 'value of $x');
145    is(ref $x, 'Math::BigInt', 'downgrades to Math::BigInt');
146};
147
148note("testing bone()");
149
150$x = Math::BigFloat -> bone();
151subtest '$x = Math::BigFloat -> bone()' => sub {
152    plan tests => 2;
153    cmp_ok($x, '==', 1, 'value of $x');
154    is(ref $x, 'Math::BigInt', 'downgrades to Math::BigInt');
155};
156
157note("testing binf()");
158
159$x = Math::BigFloat -> binf();
160subtest '$x = Math::BigFloat -> binf()' => sub {
161    plan tests => 2;
162    cmp_ok($x, '==', 'Inf', 'value of $x');
163    is(ref $x, 'Math::BigInt', 'downgrades to Math::BigInt');
164};
165
166note("testing bnan()");
167
168$x = Math::BigFloat -> bnan();
169subtest '$x = Math::BigFloat -> bnan()' => sub {
170    plan tests => 2;
171    is($x, 'NaN', 'value of $x');
172    is(ref $x, 'Math::BigInt', 'downgrades to Math::BigInt');
173};
174
175note("testing from_dec()");
176
177$x = Math::BigFloat -> from_dec('3.14e2');
178subtest '$x = Math::BigFloat -> from_dec("3.14e2")' => sub {
179    plan tests => 2;
180    cmp_ok($x, '==', 314, 'value of $x');
181    is(ref $x, 'Math::BigInt', 'downgrades to Math::BigInt');
182};
183
184note("testing from_hex()");
185
186$x = Math::BigFloat -> from_hex('0x1.3ap+8');
187subtest '$x = Math::BigFloat -> from_hex("3.14e2")' => sub {
188    plan tests => 2;
189    cmp_ok($x, '==', 314, 'value of $x');
190    is(ref $x, 'Math::BigInt', 'downgrades to Math::BigInt');
191};
192
193note("testing from_oct()");
194
195$x = Math::BigFloat -> from_oct('0o1.164p+8');
196subtest '$x = Math::BigFloat -> from_oct("0o1.164p+8")' => sub {
197    plan tests => 2;
198    cmp_ok($x, '==', 314, 'value of $x');
199    is(ref $x, 'Math::BigInt', 'downgrades to Math::BigInt');
200};
201
202note("testing from_bin()");
203
204$x = Math::BigFloat -> from_bin('0b1.0011101p+8');
205subtest '$x = Math::BigFloat -> from_bin("0b1.0011101p+8")' => sub {
206    plan tests => 2;
207    cmp_ok($x, '==', 314, 'value of $x');
208    is(ref $x, 'Math::BigInt', 'downgrades to Math::BigInt');
209};
210
211note("testing from_ieee754()");
212
213$x = Math::BigFloat -> from_ieee754("\x43\x9d\x00\x00", "binary32");
214subtest '$x = Math::BigFloat -> from_ieee754("\x43\x9d\x00\x00", "binary32")' => sub {
215    plan tests => 2;
216    cmp_ok($x, "==", 314, 'value of $x');
217    is(ref $x, "Math::BigInt", 'downgrades to Math::BigInt');
218};
219
220note("Disable downgrading, and see if constructors downgrade");
221
222Math::BigFloat -> downgrade(undef);
223
224my $zero = Math::BigFloat -> bzero();
225my $half = Math::BigFloat -> new("0.5");
226my $one  = Math::BigFloat -> bone();
227my $four = Math::BigFloat -> new("4");
228my $inf  = Math::BigFloat -> binf();
229my $nan  = Math::BigFloat -> bnan();
230
231is(ref $zero, "Math::BigFloat", "Creating a 0 does not downgrade");
232is(ref $half, "Math::BigFloat", "Creating a 0.5 does not downgrade");
233is(ref $one,  "Math::BigFloat", "Creating a 1 does not downgrade");
234is(ref $four, "Math::BigFloat", "Creating a 4 does not downgrade");
235is(ref $inf,  "Math::BigFloat", "Creating an Inf does not downgrade");
236is(ref $nan,  "Math::BigFloat", "Creating a NaN does not downgrade");
237
238################################################################################
239# Verify that other methods downgrade when they should.
240
241Math::BigFloat -> downgrade("Math::BigInt");
242
243note("testing bneg()");
244
245$x = $zero -> copy() -> bneg();
246subtest '$x = $zero -> copy() -> bneg();' => sub {
247    plan tests => 2;
248    cmp_ok($x, '==', 0, '-(0) = 0');
249    is(ref($x), 'Math::BigInt', '-(0) => Math::BigInt');
250};
251
252$x = $four -> copy() -> bneg();
253subtest '$x = $four -> copy() -> bneg();' => sub {
254    plan tests => 2;
255    cmp_ok($x, '==', -4, '-(4) = -4');
256    is(ref($x), 'Math::BigInt', '-(4) => Math::BigInt');
257};
258
259$x = $inf -> copy() -> bneg();
260subtest '$x = $inf -> copy() -> bneg();' => sub {
261    plan tests => 2;
262    cmp_ok($x, '==', '-inf', '-(Inf) = -Inf');
263    is(ref($x), 'Math::BigInt', '-(Inf) => Math::BigInt');
264};
265
266$x = $nan -> copy() -> bneg();
267subtest '$x = $nan -> copy() -> bneg();' => sub {
268    plan tests => 2;
269    is($x, 'NaN', '-(NaN) = NaN');
270    is(ref($x), 'Math::BigInt', '-(NaN) => Math::BigInt');
271};
272
273note("testing bnorm()");
274
275$x = $zero -> copy() -> bnorm();
276subtest '$x = $zero -> copy() -> bnorm();' => sub {
277    plan tests => 2;
278    cmp_ok($x, '==', 0, 'value of $x');
279    is(ref($x), 'Math::BigInt', 'bnorm(0) => Math::BigInt');
280};
281
282$x = $four -> copy() -> bnorm();
283subtest '$x = $four -> copy() -> bnorm();' => sub {
284    plan tests => 2;
285    cmp_ok($x, '==', 4, 'value of $x');
286    is(ref($x), 'Math::BigInt', 'bnorm(4) => Math::BigInt');
287};
288
289$x = $inf -> copy() -> bnorm();
290subtest '$x = $inf -> copy() -> bnorm();' => sub {
291    plan tests => 2;
292    cmp_ok($x, '==', 'inf', 'value of $x');
293    is(ref($x), 'Math::BigInt', 'bnorm(Inf) => Math::BigInt');
294};
295
296$x = $nan -> copy() -> bnorm();
297subtest '$x = $nan -> copy() -> bnorm();' => sub {
298    plan tests => 2;
299    is($x, 'NaN', 'bnorm(NaN)');
300    is(ref($x), 'Math::BigInt', 'bnorm(NaN) => Math::BigInt');
301};
302
303note("testing binc()");
304
305$x = $zero -> copy() -> binc();
306subtest '$x = $zero -> copy() -> binc();' => sub {
307    plan tests => 2;
308    cmp_ok($x, '==', 1, 'binc(0)');
309    is(ref($x), 'Math::BigInt', 'binc(0) => Math::BigInt');
310};
311
312$x = $four -> copy() -> binc();
313subtest '$x = $four -> copy() -> binc();' => sub {
314    plan tests => 2;
315    cmp_ok($x, '==', 5, 'binc(4)');
316    is(ref($x), 'Math::BigInt', 'binc(4) => Math::BigInt');
317};
318
319$x = $inf -> copy() -> binc();
320subtest '$x = $inf -> copy() -> binc();' => sub {
321    plan tests => 2;
322    cmp_ok($x, '==', 'inf', 'binc(Inf)');
323    is(ref($x), 'Math::BigInt', 'binc(Inf) => Math::BigInt');
324};
325
326$x = $nan -> copy() -> binc();
327subtest '$x = $nan -> copy() -> binc();' => sub {
328    plan tests => 2;
329    is($x, 'NaN', 'binc(NaN)');
330    is(ref($x), 'Math::BigInt', 'binc(NaN) => Math::BigInt');
331};
332
333note("testing bdec()");
334
335$x = $zero -> copy() -> bdec();
336subtest '$x = $zero -> copy() -> bdec();' => sub {
337    plan tests => 2;
338    cmp_ok($x, '==', -1, 'bdec(0)');
339    is(ref($x), 'Math::BigInt', 'bdec(0) => Math::BigInt');
340};
341
342$x = $four -> copy() -> bdec();
343subtest '$x = $four -> copy() -> bdec();' => sub {
344    plan tests => 2;
345    cmp_ok($x, '==', 3, 'bdec(4)');
346    is(ref($x), 'Math::BigInt', 'bdec(4) => Math::BigInt');
347};
348
349$x = $inf -> copy() -> bdec();
350subtest '$x = $inf -> copy() -> bdec();' => sub {
351    plan tests => 2;
352    cmp_ok($x, '==', 'inf', 'bdec(Inf)');
353    is(ref($x), 'Math::BigInt', 'bdec(Inf) => Math::BigInt');
354};
355
356$x = $nan -> copy() -> bdec();
357subtest '' => sub {
358    plan tests => 2;
359    is($x, 'NaN', 'bdec(NaN)');
360    is(ref($x), 'Math::BigInt', 'bdec(NaN) => Math::BigInt');
361};
362
363note("testing badd()");
364
365$x = $half -> copy() -> badd($nan);
366subtest '$x = $half -> copy() -> badd($nan);' => sub {
367    plan tests => 2;
368    is($x, 'NaN', '0.5 + NaN = NaN');
369    is(ref($x), 'Math::BigInt', '0.5 + NaN => Math::BigInt');
370};
371
372$x = $half -> copy() -> badd($inf);
373subtest '$x = $half -> copy() -> badd($inf);' => sub {
374    plan tests => 2;
375    cmp_ok($x, '==', '+Inf', '0.5 + Inf = Inf');
376    is(ref($x), 'Math::BigInt', '2.5 + Inf => Math::BigInt');
377};
378
379$x = $half -> copy() -> badd($half);
380subtest '$x = $half -> copy() -> badd($half);' => sub {
381    plan tests => 2;
382    cmp_ok($x, '==', 1, '0.5 + 0.5 = 1');
383    is(ref($x), 'Math::BigInt', '0.5 + 0.5 => Math::BigInt');
384};
385
386$x = $half -> copy() -> badd($half -> copy() -> bneg());
387subtest '$x = $half -> copy() -> badd($half -> copy() -> bneg());' => sub {
388    plan tests => 2;
389    cmp_ok($x, '==', 0, '0.5 + -0.5 = 0');
390    is(ref($x), 'Math::BigInt', '0.5 + -0.5 => Math::BigInt');
391};
392
393$x = $four -> copy() -> badd($zero);
394subtest '$x = $four -> copy() -> badd($zero);' => sub {
395    plan tests => 2;
396    cmp_ok($x, '==', 4, '4 + 0 = 4');
397    is(ref($x), 'Math::BigInt', '4 + 0 => Math::BigInt');
398};
399
400$x = $zero -> copy() -> badd($four);
401subtest '$x = $zero -> copy() -> badd($four);' => sub {
402    plan tests => 2;
403    cmp_ok($x, '==', 4, '0 + 4 = 4');
404    is(ref($x), 'Math::BigInt', '0 + 4 => Math::BigInt');
405};
406
407$x = $inf -> copy() -> badd($four);
408subtest '$x = $inf -> copy() -> badd($four);' => sub {
409    plan tests => 2;
410    cmp_ok($x, '==', '+Inf', 'Inf + 4 = Inf');
411    is(ref($x), 'Math::BigInt', 'Inf + 4 => Math::BigInt');
412};
413
414$x = $nan -> copy() -> badd($four);
415subtest '$x = $nan -> copy() -> badd($four);' => sub {
416    plan tests => 2;
417    is($x, 'NaN', 'NaN + 4 = NaN');
418    is(ref($x), 'Math::BigInt', 'NaN + 4 => Math::BigInt');
419};
420
421note("testing bsub()");
422
423$x = $half -> copy() -> bsub($nan);
424subtest '$x = $half -> copy() -> bsub($nan);' => sub {
425    plan tests => 2;
426    is($x, 'NaN', '0.5 - NaN = NaN');
427    is(ref($x), 'Math::BigInt', '0.5 - NaN => Math::BigInt');
428};
429
430$x = $half -> copy() -> bsub($inf);
431subtest '$x = $half -> copy() -> bsub($inf);' => sub {
432    plan tests => 2;
433    cmp_ok($x, '==', '-Inf', '2.5 - Inf = -Inf');
434    is(ref($x), 'Math::BigInt', '2.5 - Inf => Math::BigInt');
435};
436
437$x = $half -> copy() -> bsub($half);
438subtest '$x = $half -> copy() -> bsub($half);' => sub {
439    plan tests => 2;
440    cmp_ok($x, '==', 0, '0.5 + 0.5 = 0');
441    is(ref($x), 'Math::BigInt', '0.5 - 0.5 => Math::BigInt');
442};
443
444$x = $half -> copy() -> bsub($half -> copy() -> bneg());
445subtest '$x = $half -> copy() -> bsub($half -> copy() -> bneg());' => sub {
446    plan tests => 2;
447    cmp_ok($x, '==', 1, '0.5 - -0.5 = 1');
448    is(ref($x), 'Math::BigInt', '0.5 - -0.5 => Math::BigInt');
449};
450
451$x = $four -> copy() -> bsub($zero);
452subtest '$x = $four -> copy() -> bsub($zero);' => sub {
453    plan tests => 2;
454    cmp_ok($x, '==', 4, '4 - 0 = 4');
455    is(ref($x), 'Math::BigInt', '4 - 0 => Math::BigInt');
456};
457
458$x = $zero -> copy() -> bsub($four);
459subtest '$x = $zero -> copy() -> bsub($four);' => sub {
460    plan tests => 2;
461    cmp_ok($x, '==', -4, '0 - 4 = -4');
462    is(ref($x), 'Math::BigInt', '0 - 4 => Math::BigInt');
463};
464
465$x = $inf -> copy() -> bsub($four);
466subtest '$x = $inf -> copy() -> bsub($four);' => sub {
467    plan tests => 2;
468    cmp_ok($x, '==', 'Inf', 'Inf - 4 = Inf');
469    is(ref($x), 'Math::BigInt', 'Inf - 4 => Math::BigInt');
470};
471
472$x = $nan -> copy() -> bsub($four);
473subtest '$x = $nan -> copy() -> bsub($four);' => sub {
474    plan tests => 2;
475    is($x, 'NaN', 'NaN - 4 = NaN');
476    is(ref($x), 'Math::BigInt', 'NaN - 4 => Math::BigInt');
477};
478
479note("testing bmul()");
480
481$x = $zero -> copy() -> bmul($four);
482subtest '$x = $zero -> copy() -> bmul($four);' => sub {
483    plan tests => 2;
484    cmp_ok($x, '==', 0, 'bmul(0, 4) = 0');
485    is(ref($x), 'Math::BigInt', 'bmul(0, 4) => Math::BigInt');
486};
487
488$x = $four -> copy() -> bmul($four);
489subtest '$x = $four -> copy() -> bmul($four);' => sub {
490    plan tests => 2;
491    cmp_ok($x, '==', 16, 'bmul(4, 4) = 16');
492    is(ref($x), 'Math::BigInt', 'bmul(4, 4) => Math::BigInt');
493};
494
495$x = $inf -> copy() -> bmul($four);
496subtest '$x = $inf -> copy() -> bmul($four);' => sub {
497    plan tests => 2;
498    cmp_ok($x, '==', 'inf', 'bmul(Inf, 4) = Inf');
499    is(ref($x), 'Math::BigInt', 'bmul(Inf, 4) => Math::BigInt');
500};
501
502$x = $nan -> copy() -> bmul($four);
503subtest '$x = $nan -> copy() -> bmul($four);' => sub {
504    plan tests => 2;
505    is($x, 'NaN', 'bmul(NaN, 4) = NaN');
506    is(ref($x), 'Math::BigInt', 'bmul(NaN, 4) => Math::BigInt');
507};
508
509$x = $four -> copy() -> bmul('0.5');
510subtest '' => sub {
511    plan tests => 2;
512    cmp_ok($x, '==', 2, 'bmul(4, 0.5) = 2');
513    is(ref($x), 'Math::BigInt', 'bmul(4, 0.5) => Math::BigInt');
514};
515
516note("testing bmuladd()");
517
518$x = $zero -> copy() -> bmuladd($four, $four);
519subtest '$x = $zero -> copy() -> bmuladd($four, $four);' => sub {
520    plan tests => 2;
521    cmp_ok($x, '==', 4, 'bmuladd(0, 4, 4) = 4');
522    is(ref($x), 'Math::BigInt', 'bmuladd(0, 4, 4) => Math::BigInt');
523};
524
525$x = $four -> copy() -> bmuladd($four, $four);
526subtest '$x = $four -> copy() -> bmuladd($four, $four);' => sub {
527    plan tests => 2;
528    cmp_ok($x, '==', 20, 'bmuladd(4, 4, 4) = 20');
529    is(ref($x), 'Math::BigInt', 'bmuladd(4, 4, 4) => Math::BigInt');
530};
531
532$x = $four -> copy() -> bmuladd($four, $inf);
533subtest '$x = $four -> copy() -> bmuladd($four, $inf);' => sub {
534    plan tests => 2;
535    cmp_ok($x, '==', 'inf', 'bmuladd(4, 4, Inf) = Inf');
536    is(ref($x), 'Math::BigInt', 'bmuladd(4, 4, Inf) => Math::BigInt');
537};
538
539$x = $inf -> copy() -> bmuladd($four, $four);
540subtest '$x = $inf -> copy() -> bmuladd($four, $four);' => sub {
541    plan tests => 2;
542    cmp_ok($x, '==', 'inf', 'bmuladd(Inf, 4, 4) = Inf');
543    is(ref($x), 'Math::BigInt', 'bmuladd(Inf, 4, 4) => Math::BigInt');
544};
545
546$x = $inf -> copy() -> bmuladd($four, $four);
547subtest '$x = $inf -> copy() -> bmuladd($four, $four);' => sub {
548    plan tests => 2;
549    cmp_ok($x, '==', 'inf', 'bmuladd(Inf, 4, 4) = Inf');
550    is(ref($x), 'Math::BigInt', 'bmuladd(Inf, 4, 4) => Math::BigInt');
551};
552
553$x = $nan -> copy() -> bmuladd($four, $four);
554subtest '$x = $nan -> copy() -> bmuladd($four, $four);' => sub {
555    plan tests => 2;
556    is($x, 'NaN', 'bmuladd(NaN, 4, 4) = NaN');
557    is(ref($x), 'Math::BigInt', 'bmuladd(NaN, 4, 4) => Math::BigInt');
558};
559
560$x = $four -> copy() -> bmuladd("0.5", $four);
561subtest '$x = $four -> copy() -> bmuladd("0.5", $four);' => sub {
562    plan tests => 2;
563    cmp_ok($x, '==', 6, 'bmuladd(4, 0.5, 4) = 6');
564    is(ref($x), 'Math::BigInt', 'bmuladd(4, 0.5, 4) => Math::BigInt');
565};
566
567note("testing bdiv()");
568
569$x = $zero -> copy() -> bdiv($one);
570subtest '$x = $zero -> copy() -> bdiv($one);' => sub {
571    plan tests => 2;
572    cmp_ok($x, '==', 0, 'bdiv(0, 1) = 0');
573    is(ref($x), 'Math::BigInt', 'bdiv(0, 1) => Math::BigInt');
574};
575
576note("testing bmod()");
577
578note("testing bmodpow()");
579
580note("testing bpow()");
581
582note("testing blog()");
583
584note("testing bexp()");
585
586note("testing bnok()");
587
588note("testing bsin()");
589
590note("testing bcos()");
591
592note("testing batan()");
593
594note("testing batan()");
595
596note("testing bsqrt()");
597
598note("testing broot()");
599
600note("testing bfac()");
601
602note("testing bdfac()");
603
604note("testing btfac()");
605
606note("testing bmfac()");
607
608note("testing blsft()");
609
610note("testing brsft()");
611
612note("testing band()");
613
614note("testing bior()");
615
616note("testing bxor()");
617
618note("testing bnot()");
619
620note("testing bround()");
621
622note("testing Add tests for rounding a non-integer to an integer. Fixme!");
623
624$x = $zero -> copy() -> bround();
625subtest '$x = $zero -> copy() -> bround();' => sub {
626    plan tests => 2;
627    cmp_ok($x, '==', 0, 'bround(0)');
628    is(ref($x), 'Math::BigInt', 'bround(0) => Math::BigInt');
629};
630
631$x = $four -> copy() -> bround();
632subtest '$x = $four -> copy() -> bround();' => sub {
633    plan tests => 2;
634    cmp_ok($x, '==', 4, 'bround(4)');
635    is(ref($x), 'Math::BigInt', 'bround(4) => Math::BigInt');
636};
637
638$x = $inf -> copy() -> bround();
639subtest '$x = $inf -> copy() -> bround();' => sub {
640    plan tests => 2;
641    cmp_ok($x, '==', 'inf', 'bround(Inf)');
642    is(ref($x), 'Math::BigInt', 'bround(Inf) => Math::BigInt');
643};
644
645$x = $nan -> copy() -> bround();
646subtest '$x = $nan -> copy() -> bround();' => sub {
647    plan tests => 2;
648    is($x, 'NaN', 'bround(NaN)');
649    is(ref($x), 'Math::BigInt', 'bround(NaN) => Math::BigInt');
650};
651
652note("testing bfround()");
653
654note("testing Add tests for rounding a non-integer to an integer. Fixme!");
655
656$x = $zero -> copy() -> bfround();
657subtest '$x = $zero -> copy() -> bfround();' => sub {
658    plan tests => 2;
659    cmp_ok($x, '==', 0, 'bfround(0)');
660    is(ref($x), 'Math::BigInt', 'bfround(0) => Math::BigInt');
661};
662
663$x = $four -> copy() -> bfround();
664subtest '$x = $four -> copy() -> bfround();' => sub {
665    plan tests => 2;
666    cmp_ok($x, '==', 4, 'bfround(4)');
667    is(ref($x), 'Math::BigInt', 'bfround(4) => Math::BigInt');
668};
669
670$x = $inf -> copy() -> bfround();
671subtest '$x = $inf -> copy() -> bfround();' => sub {
672    plan tests => 2;
673    cmp_ok($x, '==', 'inf', 'bfround(Inf)');
674    is(ref($x), 'Math::BigInt', 'bfround(Inf) => Math::BigInt');
675};
676
677$x = $nan -> copy() -> bfround();
678subtest '$x = $nan -> copy() -> bfround();' => sub {
679    plan tests => 2;
680    is($x, 'NaN', 'bfround(NaN)');
681    is(ref($x), 'Math::BigInt', 'bfround(NaN) => Math::BigInt');
682};
683
684note("testing bfloor()");
685
686$x = $half -> copy() -> bfloor();
687subtest '$x = $half -> copy() -> bfloor();' => sub {
688    plan tests => 2;
689    cmp_ok($x, '==', 0, 'bfloor(0)');
690    is(ref($x), 'Math::BigInt', 'bfloor(0) => Math::BigInt');
691};
692
693$x = $inf -> copy() -> bfloor();
694subtest '$x = $inf -> copy() -> bfloor();' => sub {
695    plan tests => 2;
696    cmp_ok($x, '==', 'Inf', 'bfloor(Inf)');
697    is(ref($x), 'Math::BigInt', 'bfloor(Inf) => Math::BigInt');
698};
699
700$x = $nan -> copy() -> bfloor();
701subtest '$x = $nan -> copy() -> bfloor();' => sub {
702    plan tests => 2;
703    is($x, 'NaN', 'bfloor(NaN)');
704    is(ref($x), 'Math::BigInt', 'bfloor(NaN) => Math::BigInt');
705};
706
707note("testing bceil()");
708
709$x = $half -> copy() -> bceil();
710subtest '$x = $half -> copy() -> bceil();' => sub {
711    plan tests => 2;
712    cmp_ok($x, '==', 1, 'bceil(0)');
713    is(ref($x), 'Math::BigInt', 'bceil(0) => Math::BigInt');
714};
715
716$x = $inf -> copy() -> bceil();
717subtest '$x = $inf -> copy() -> bceil();' => sub {
718    plan tests => 2;
719    cmp_ok($x, '==', 'Inf', 'bceil(Inf)');
720    is(ref($x), 'Math::BigInt', 'bceil(Inf) => Math::BigInt');
721};
722
723$x = $nan -> copy() -> bceil();
724subtest '$x = $nan -> copy() -> bceil();' => sub {
725    plan tests => 2;
726    is($x, 'NaN', 'bceil(NaN)');
727    is(ref($x), 'Math::BigInt', 'bceil(NaN) => Math::BigInt');
728};
729
730note("testing bint()");
731
732$x = $half -> copy() -> bint();
733subtest '$x = $half -> copy() -> bint();' => sub {
734    plan tests => 2;
735    cmp_ok($x, '==', 0, 'bint(0)');
736    is(ref($x), 'Math::BigInt', 'bint(0) => Math::BigInt');
737};
738
739$x = $inf -> copy() -> bint();
740subtest '$x = $inf -> copy() -> bint();' => sub {
741    plan tests => 2;
742    cmp_ok($x, '==', 'Inf', 'bint(Inf)');
743    is(ref($x), 'Math::BigInt', 'bint(Inf) => Math::BigInt');
744};
745
746$x = $nan -> copy() -> bint();
747subtest '$x = $nan -> copy() -> bint();' => sub {
748    plan tests => 2;
749    is($x, 'NaN', 'bint(NaN)');
750    is(ref($x), 'Math::BigInt', 'bint(NaN) => Math::BigInt');
751};
752
753note("testing bgcd()");
754
755note("testing blcm()");
756
757note("testing mantissa()");
758
759note("testing exponent()");
760
761note("testing parts()");
762
763note("testing sparts()");
764
765note("testing nparts()");
766
767note("testing eparts()");
768
769note("testing dparts()");
770
771note("testing fparts()");
772
773note("testing numerator()");
774
775note("testing denominator()");
776