xref: /openbsd-src/gnu/usr.bin/perl/cpan/bignum/t/bigint.t (revision eac174f2741a08d8deb8aae59a7f778ef9b5d770)
1# -*- mode: perl; -*-
2
3###############################################################################
4
5use strict;
6use warnings;
7
8use Test::More tests => 17;
9
10use bigint;
11
12###############################################################################
13# general tests
14
15my $x = 5;
16is(ref($x), 'Math::BigInt', '$x = 5 makes $x a Math::BigInt');
17
18$x = 2 + 3.5;
19is($x, 5.5, '2 + 3.5 = 5.5');
20is(ref($x), 'Math::BigInt', '$x = 2 + 3.5 makes $x a Math::BigInt');
21
22$x = 2 ** 255;
23is(ref($x), 'Math::BigInt', '$x = 2 ** 255 makes $x a Math::BigInt');
24
25is(12->bfac(), 479001600, '12->bfac() = 479001600');
26is(9/4, 2, '9/4 = 2');
27
28is(4.5 + 4.5, 8, '4.5 + 4.5 = 8');                         # truncate
29is(ref(4.5 + 4.5), 'Math::BigInt', '4.5 + 4.5 makes a Math::BigInt');
30
31###############################################################################
32# accuracy and precision
33
34is(bigint->accuracy(), undef, 'get accuracy');
35bigint->accuracy(12);
36is(bigint->accuracy(), 12, 'get accuracy again');
37bigint->accuracy(undef);
38is(bigint->accuracy(), undef, 'get accuracy again');
39
40is(bigint->precision(), undef, 'get precision');
41bigint->precision(12);
42is(bigint->precision(), 12, 'get precision again');
43bigint->precision(undef);
44is(bigint->precision(), undef, 'get precision again');
45
46is(bigint->round_mode(), 'even', 'get round mode');
47bigint->round_mode('odd');
48is(bigint->round_mode(), 'odd', 'get round mode again');
49bigint->round_mode('even');
50is(bigint->round_mode(), 'even', 'get round mode again');
51