blib/lib/Math/BigInt/FastCalc.pm

filter: Statementstmt 87.5% 35 / 40 Branchbran 28.5% 4 / 14 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 55.9% 47 / 84 CC 13 SCAR 36.7
CC
13
Cov
57%
_base_len
76.1
BEGIN
4.1
BEGIN
1.0
CRAP 39.2
↑ Summary FastCalc.xs »
1 package Math::BigInt::FastCalc;
2  
3 10 ▶use 5.006001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 10 ▶use Carp qw< carp croak >;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 10 ▶use Math::BigInt::Calc 1.999801;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 10 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
12 10 our @ISA = qw< Math::BigInt::Calc >;
13 }
14  
15 10 our $VERSION = '0.5020';
16  
17 10 my $MAX_EXP_F; # the maximum possible base 10 exponent with "no integer"
18 my $MAX_EXP_I; # the maximum possible base 10 exponent with "use integer"
19 10 my $BASE_LEN; # the current base exponent in use
20 10 my $USE_INT; # whether "use integer" is used in the computations
21  
22 3 ▶sub _base_len {
Subroutine _base_len: called CC=10 SCAR=43.3
23 3 my $class = shift;
24  
25 3 ▶ if (@_) { # if called as setter ...
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 3 3
26 0 my ($base_len, $use_int) = @_;
27  
28 0 ▶ croak "The base length must be a positive integer"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $base_len and $base_len == int $base_len and $base_len > 0 0 0 0
Condition0%0/6
defined $base_len and $base_len == int $base_len and $base_len > 0
!ll&&!rl&&r
000
defined $base_len and $base_len == int $base_len
!ll&&!rl&&r
000
MC/DC0%0/3
defined $base_len and $base_len == int $base_len and $base_len > 0
defined $base_len $base_len == int $base_len $base_len > 0
Truth table0%0/4
A and B and C
A= defined $base_lenB= $base_len == int $base_lenC= $base_len > 0
ABCresult
0XX0
10X0
1100
1111
29 unless defined($base_len) && $base_len == int($base_len)
30 && $base_len > 0;
31  
32 0 ▶ if ( $use_int && ($base_len > $MAX_EXP_I) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($use_int and $base_len > $MAX_EXP_I or not $use_int and $base_len > $MAX_EXP_F) 0 0 0
Condition0%0/9
$use_int and $base_len > $MAX_EXP_I or not $use_int and $base_len > $MAX_EXP_F
l!l&&r!l&&!r
000
$use_int and $base_len > $MAX_EXP_I
!ll&&!rl&&r
000
not $use_int and $base_len > $MAX_EXP_F
!ll&&!rl&&r
000
MC/DC0%0/4
$use_int and $base_len > $MAX_EXP_I or not $use_int and $base_len > $MAX_EXP_F
$use_int $base_len > $MAX_EXP_I not $use_int $base_len > $MAX_EXP_F
Truth table0%0/7
A and B or not(C) and D
A= $use_intB= $base_len > $MAX_EXP_IC= not $use_intD= $base_len > $MAX_EXP_F
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
33 !$use_int && ($base_len > $MAX_EXP_F))
34 {
35 0 ▶ croak "The maximum base length (exponent) is $MAX_EXP_I with",
Branch: 1 branch
BranchTrueFalseTotal
$use_int ? : 0 0 0
36 " 'use integer' and $MAX_EXP_F without 'use integer'. The",
37 " requested settings, a base length of $base_len ",
38 $use_int ? "with" : "without", " 'use integer', is invalid.";
39 }
40  
41 0 return $class -> SUPER::_base_len($base_len, $use_int);
42 }
43  
44 3 return $class -> SUPER::_base_len();
45 }
46  
47 10 ▶BEGIN {
Subroutine BEGIN: called CC=4 SCAR=14.1
48  
49 10 my @params = Math::BigInt::FastCalc -> SUPER::_base_len();
50 10 $BASE_LEN = $params[0];
51 10 $MAX_EXP_F = $params[8];
52 10 $MAX_EXP_I = $params[9];
53  
54 # With quadmath support it should work with a base length of 17, because the
55 # maximum intermediate value used in the computations is less than 2**113.
56 # However, for some reason a base length of 17 doesn't work, but trial and
57 # error shows that a base length of 15 works for all methods except
58 # _is_odd() and _is_even(). These two methods determine whether the least
59 # significand component is odd or even by converting it to a UV and do a
60 # bitwise & operation. Because of this, we need to limit the base length to
61 # what fits inside an UV.
62  
63 10 require Config;
64 10 my $max_exp_i = int(8 * $Config::Config{uvsize} * log(2) / log(10));
65 10 ▶ $MAX_EXP_I = $max_exp_i if $max_exp_i < $MAX_EXP_I;
Branch: 1 branch
BranchTrueFalseTotal
if $max_exp_i < $MAX_EXP_I 0 10 10
66 10 ▶ $MAX_EXP_F = $MAX_EXP_I if $MAX_EXP_I < $MAX_EXP_F;
Branch: 1 branch
BranchTrueFalseTotal
if $MAX_EXP_I < $MAX_EXP_F 0 10 10
67  
68 10 ▶ ($BASE_LEN, $USE_INT) = $MAX_EXP_I > $MAX_EXP_F ? ($MAX_EXP_I, 1)
Branch: 1 branch
BranchTrueFalseTotal
$MAX_EXP_I > $MAX_EXP_F ? : 0 10 10
69 : ($MAX_EXP_F, 0);
70  
71 10 Math::BigInt::FastCalc -> SUPER::_base_len($BASE_LEN, $USE_INT);
72 }
73  
74 ##############################################################################
75 # global constants, flags and accessory
76  
77 # Announce that we are compatible with MBI v1.83 and up. This method has been
78 # made redundant. Each backend is now a subclass of Math::BigInt::Lib, which
79 # provides the methods not present in the subclasses.
80  
81 sub api_version () { 2; }
82  
83 10 require XSLoader;
84 10 XSLoader::load(__PACKAGE__, $VERSION, Math::BigInt::Calc->_base_len());
85  
86 ##############################################################################
87  
88 10 1;
89  
90 __END__
↑ Summary FastCalc.xs »