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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
# -*- mode: perl; -*-
use strict;
use warnings;
use Test::More tests => 792;
use Math::BigInt;
while (<DATA>) {
s/#.*$//; # remove comments
s/\s+$//; # remove trailing whitespace
next unless length; # skip empty lines
my ($x_str, $mant_str, $expo_str) = split /:/;
note(qq|\n\$x = Math::BigInt -> new("$x_str");|,
qq| (\$m, \$e) = \$x -> sparts();\n\n|);
{
my $x = Math::BigInt -> new($x_str);
my ($mant_got, $expo_got) = $x -> sparts();
isa_ok($mant_got, "Math::BigInt");
isa_ok($expo_got, "Math::BigInt");
is($mant_got, $mant_str, "value of mantissa");
is($expo_got, $expo_str, "value of exponent");
is($x, $x_str, "input is unmodified");
}
note(qq|\n\$x = Math::BigInt -> new("$x_str");|,
qq| \$m = \$x -> sparts();\n\n|);
{
my $x = Math::BigInt -> new($x_str);
my $mant_got = $x -> sparts();
isa_ok($mant_got, "Math::BigInt");
is($mant_got, $mant_str, "value of mantissa");
is($x, $x_str, "input is unmodified");
}
}
# Verify that the accuracy of the significand and the exponent depends on the
# accuracy of the invocand, if set, not the class.
note(qq|\nVerify that accuracy depends on invocand, not class.\n\n|);
{
Math::BigInt -> accuracy(20);
my $x = Math::BigInt -> new("3"); # accuracy is 20
$x -> accuracy(10); # reduce accuracy to 10
my ($mant, $expo) = $x -> sparts();
cmp_ok($mant, '==', 3, "value of significand");
cmp_ok($expo, '==', 0, "value of exponent");
cmp_ok($mant -> accuracy(), '==', 10, "accuracy of significand");
cmp_ok($expo -> accuracy(), '==', 20, "accuracy of exponent");
}
note(qq|\nVerify that precision depends on invocand, not class.\n\n|);
{
Math::BigInt -> precision(20);
my $x = Math::BigInt -> new("3"); # precision is 20
$x -> precision(10); # reduce precision to 10
my ($mant, $expo) = $x -> sparts();
cmp_ok($mant, '==', 3, "value of significand");
cmp_ok($expo, '==', 0, "value of exponent");
cmp_ok($mant -> precision(), '==', 10, "precision of significand");
cmp_ok($expo -> precision(), '==', 20, "precision of exponent");
}
__DATA__
NaN:NaN:NaN
inf:inf:inf
-inf:-inf:inf
0:0:0
# positive numbers
1:1:0
10:1:1
100:1:2
1000:1:3
10000:1:4
100000:1:5
1000000:1:6
10000000:1:7
100000000:1:8
1000000000:1:9
10000000000:1:10
100000000000:1:11
1000000000000:1:12
12:12:0
120:12:1
1200:12:2
12000:12:3
120000:12:4
1200000:12:5
12000000:12:6
120000000:12:7
1200000000:12:8
12000000000:12:9
120000000000:12:10
1200000000000:12:11
123:123:0
1230:123:1
12300:123:2
123000:123:3
1230000:123:4
12300000:123:5
123000000:123:6
1230000000:123:7
12300000000:123:8
123000000000:123:9
1230000000000:123:10
1234:1234:0
12340:1234:1
123400:1234:2
1234000:1234:3
12340000:1234:4
123400000:1234:5
1234000000:1234:6
12340000000:1234:7
123400000000:1234:8
1234000000000:1234:9
3141592:3141592:0
# negativ: numbers
-1:-1:0
-10:-1:1
-100:-1:2
-1000:-1:3
-10000:-1:4
-100000:-1:5
-1000000:-1:6
-10000000:-1:7
-100000000:-1:8
-1000000000:-1:9
-10000000000:-1:10
-100000000000:-1:11
-1000000000000:-1:12
-12:-12:0
-120:-12:1
-1200:-12:2
-12000:-12:3
-120000:-12:4
-1200000:-12:5
-12000000:-12:6
-120000000:-12:7
-1200000000:-12:8
-12000000000:-12:9
-120000000000:-12:10
-1200000000000:-12:11
-123:-123:0
-1230:-123:1
-12300:-123:2
-123000:-123:3
-1230000:-123:4
-12300000:-123:5
-123000000:-123:6
-1230000000:-123:7
-12300000000:-123:8
-123000000000:-123:9
-1230000000000:-123:10
-1234:-1234:0
-12340:-1234:1
-123400:-1234:2
-1234000:-1234:3
-12340000:-1234:4
-123400000:-1234:5
-1234000000:-1234:6
-12340000000:-1234:7
-123400000000:-1234:8
-1234000000000:-1234:9
-3141592:-3141592:0
|