File: bigfloat.t

package info (click to toggle)
perl 5.42.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 128,392 kB
  • sloc: perl: 534,963; ansic: 240,563; sh: 72,042; pascal: 6,934; xml: 2,428; yacc: 1,360; makefile: 1,197; cpp: 208; lisp: 1
file content (59 lines) | stat: -rw-r--r-- 1,775 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- mode: perl; -*-

###############################################################################

use strict;
use warnings;

use Test::More tests => 17;

use bigfloat;

###############################################################################
# general tests

my $x = 5;
is(ref($x), 'Math::BigFloat', '$x = 5 makes $x a Math::BigFloat');

$x = 2 + 3.5;
is($x, 5.5, '2 + 3.5 = 5.5');
is(ref($x), 'Math::BigFloat', '$x = 2 + 3.5 makes $x a Math::BigFloat');

$x = 2 ** 255;
is(ref($x), 'Math::BigFloat', '$x = 2 ** 255 makes $x a Math::BigFloat');

is(sqrt(12), '3.464101615137754587054892683011744733886',
   'sqrt(12)');

is(2/3, "0.6666666666666666666666666666666666666667", '2/3');

#is(2 ** 0.5, 'NaN');   # should be sqrt(2);

is(12->bfac(), 479001600, '12->bfac() = 479001600');

# see if Math::BigFloat constant works

#                     0123456789          0123456789    <- default 40
#           0123456789          0123456789
is(1/3, '0.3333333333333333333333333333333333333333', '1/3');

###############################################################################
# accuracy and precision

is(bigfloat->accuracy(), undef, 'get accuracy');
bigfloat->accuracy(12);
is(bigfloat->accuracy(), 12, 'get accuracy again');
bigfloat->accuracy(undef);
is(bigfloat->accuracy(), undef, 'get accuracy again');

is(bigfloat->precision(), undef, 'get precision');
bigfloat->precision(12);
is(bigfloat->precision(), 12, 'get precision again');
bigfloat->precision(undef);
is(bigfloat->precision(), undef, 'get precision again');

is(bigfloat->round_mode(), 'even', 'get round mode');
bigfloat->round_mode('odd');
is(bigfloat->round_mode(), 'odd', 'get round mode again');
bigfloat->round_mode('even');
is(bigfloat->round_mode(), 'even', 'get round mode again');