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