| 1 | # Checked against calculator at https://playcode.io/new | ||||||||||||||||||||||||||||||||||||||||||
| 2 | package Math::JS; | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use Config; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 5 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=12.7
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | $::bool = 0; | |||||||||||||||||||||||||||||||||||||||||
| 9 | 5 | eval {require Math::Ryu;}; | |||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | if(!$@ && $Math::Ryu::VERSION >= 0.06) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $@ and $Math::Ryu::VERSION >= "0.06"
MC/DC0%0/2
not $@ and $Math::Ryu::VERSION >= "0.06"
not $@
$Math::Ryu::VERSION >= "0.06"
Truth table33%1/3
not(A) and B
A= not $@B= $Math::Ryu::VERSION >= "0.06"
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 0 | $::bool = 1; | |||||||||||||||||||||||||||||||||||||||||
| 12 | } | ||||||||||||||||||||||||||||||||||||||||||
| 13 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use 5.030; # avoid buggy floating-point assignments | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | use overload | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 5 | ▶ | '+' => \&oload_add, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | '-' => \&oload_sub, | ||||||||||||||||||||||||||||||||||||||||||
| 19 | '*' => \&oload_mul, | ||||||||||||||||||||||||||||||||||||||||||
| 20 | '/' => \&oload_div, | ||||||||||||||||||||||||||||||||||||||||||
| 21 | '%' => \&oload_mod, | ||||||||||||||||||||||||||||||||||||||||||
| 22 | '**' => \&oload_pow, | ||||||||||||||||||||||||||||||||||||||||||
| 23 | '++' => \&oload_inc, | ||||||||||||||||||||||||||||||||||||||||||
| 24 | '--' => \&oload_dec, | ||||||||||||||||||||||||||||||||||||||||||
| 25 | '>=' => \&oload_gte, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | '<=' => \&oload_lte, | ||||||||||||||||||||||||||||||||||||||||||
| 27 | '==' => \&oload_equiv, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | '!=' => \&oload_not_equiv, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | '>' => \&oload_gt, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | '<' => \&oload_lt, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | '<=>' => \&oload_spaceship, | ||||||||||||||||||||||||||||||||||||||||||
| 32 | '""' => \&oload_stringify, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | '&' => \&oload_and, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | '|' => \&oload_ior, | ||||||||||||||||||||||||||||||||||||||||||
| 35 | '^' => \&oload_xor, | ||||||||||||||||||||||||||||||||||||||||||
| 36 | '~' => \&oload_not, | ||||||||||||||||||||||||||||||||||||||||||
| 37 | '<<' => \&oload_lshift, | ||||||||||||||||||||||||||||||||||||||||||
| 38 | '>>' => \&oload_rshift, | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 5 | ; | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 5 | ▶ | use constant MAX_ULONG => 4294967295; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 5 | ▶ | use constant MAX_SLONG => 2147483647; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 5 | ▶ | use constant MIN_ULONG => 2147483648; # 1<<31 (Lowest positive value that sets 32nd bit) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 5 | ▶ | use constant MIN_SLONG => -2147483648; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 5 | ▶ | use constant LOW_31BIT => 1073741824; # 1<<30 (Lowest 31 bit positive number) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 5 | ▶ | use constant MAX_NUM => 9007199254740991; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 5 | ▶ | use constant USE_RYU => $::bool; # set in BEGIN{} block | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 5 | ▶ | use constant IVSIZE => $Config{ivsize}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 5 | our $VERSION = '0.05'; | |||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 5 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 5 | *import = \&Exporter::import; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 5 | @Math::JS::EXPORT = (); | |||||||||||||||||||||||||||||||||||||||||
| 55 | 5 | @Math::JS::EXPORT_OK = qw(urs); | |||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 5 | require DynaLoader; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 5 | Math::JS->DynaLoader::bootstrap($VERSION); | |||||||||||||||||||||||||||||||||||||||||
| 59 | 5 | ▶ | sub dl_load_flags {0} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dl_load_flags: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | # The "type" of a Math::JS object's value will be either 'sint32', 'uint32' | ||||||||||||||||||||||||||||||||||||||||||
| 62 | # or 'number'. Roughly speaking, these types are (respectively) "unsigned | ||||||||||||||||||||||||||||||||||||||||||
| 63 | # 32-bit integer", "signed 32-bit integer" and "floating-point number". | ||||||||||||||||||||||||||||||||||||||||||
| 64 | # Hence, relying on the value returned by is_ok(), we have: | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 5 | my %classify = (2 => 'uint32', 3 => 'sint32', 4 => 'number'); | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 1484 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=17.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 1484 | ▶ | shift if(!ref($_[0]) && $_[0] eq "Math::JS"); # 'new' has been called as a method | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not ref $_[0] and $_[0] eq "Math::JS"
MC/DC0%0/2
not ref $_[0] and $_[0] eq "Math::JS"
not ref $_[0]
$_[0] eq "Math::JS"
Truth table33%1/3
not(A) and B
A= not ref $_[0]B= $_[0] eq "Math::JS"
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 1484 | my $val = shift; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 1484 | my $ok = is_ok($val); # returns 1 for Math::JS object, 2 for a 32-bit UV, | |||||||||||||||||||||||||||||||||||||||||
| 71 | # 3 for a 32-bit IV, 4 for an NV, and 0 (not ok) for anything else. | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 1484 | ▶ | die "Bad argument (or no argument) given to new" unless $ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 1483 | ▶ | if($ok == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | # return a copy of the given Math::JS object | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | my $ret = shift; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | return $ret; | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 1483 | my %h = ('val' => $val, 'type' => $classify{$ok}); | |||||||||||||||||||||||||||||||||||||||||
| 81 | 1483 | return bless(\%h, 'Math::JS'); | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | ########### + ########## | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 20 | ▶ | sub oload_add { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
oload_add: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 20 | ▶ | die "Wrong number of arguments given to oload_add()" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | if @_ > 3; | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 20 | my $ok = is_ok($_[1]); # check that 2nd arg is suitable. | |||||||||||||||||||||||||||||||||||||||||
| 90 | 20 | ▶ | die "Bad argument given to oload_add" unless $ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 20 | my $ret1 = $_[0]->{val}; | |||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | return Math::JS->new($ret1 + $_[1]->{val}) | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 20 | ▶ | if $ok == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 4 | return Math::JS->new($ret1 + $_[1]); | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | ########### * ########## | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 12 | ▶ | sub oload_mul { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
oload_mul: called CC=4 SCAR=14.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 12 | ▶ | die "Wrong number of arguments given to oload_mul()" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | if @_ > 3; | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 12 | my $ok = is_ok($_[1]); # check that 2nd arg is suitable. | |||||||||||||||||||||||||||||||||||||||||
| 106 | 12 | ▶ | die "Bad argument given to oload_mul" unless $ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 12 | my $ret1 = $_[0]->{val}; | |||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | return Math::JS->new($ret1 * $_[1]->{val}) | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 12 | ▶ | if $ok == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 12 | return Math::JS->new($ret1 * $_[1]); | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | ########### - ########## | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 3 | ▶ | sub oload_sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
oload_sub: called CC=5 SCAR=16.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 3 | ▶ | die "Wrong number of arguments given to oload_sub()" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | if @_ > 3; | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 3 | my $ok = is_ok($_[1]); # check that 2nd arg is suitable. | |||||||||||||||||||||||||||||||||||||||||
| 122 | 3 | ▶ | die "Bad argument given to oload_sub" unless $ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 3 | my $third_arg = $_[2]; | |||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 3 | my $ret0 = $_[0]->{val}; | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 3 | ▶ | if($ok == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | return Math::JS->new($ret0 - $_[1]->{val}); | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 3 | ▶ | return Math::JS->new($_[1] - $ret0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | if $third_arg; | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 2 | return Math::JS->new($ret0 - $_[1]); | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | ########### / ########## | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 9 | ▶ | sub oload_div { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
oload_div: called CC=7 SCAR=19.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 9 | ▶ | die "Wrong number of arguments given to oload_div()" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | if @_ > 3; | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 9 | my $ok = is_ok($_[1]); # check that 2nd arg is suitable. | |||||||||||||||||||||||||||||||||||||||||
| 143 | 9 | ▶ | die "Bad argument given to oload_div" unless $ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 9 | my $third_arg = $_[2]; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 9 | my ($num, $den, $ret); | |||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 9 | ▶ | if($ok == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $num = $_[0]->{val}; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | $den = $_[1]->{val}; | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | elsif($third_arg) { | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | $num = $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | $den = $_[0]->{val}; | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 8 | $num = $_[0]->{val}; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 8 | $den = $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 9 | ▶ | if($den == 0) { $ret = $num < 0 ? _get_ninf() : _get_pinf() } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 7 | else { $ret = $num / $den } | |||||||||||||||||||||||||||||||||||||||||
| 163 | 9 | return Math::JS->new($ret); | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | ########### % ########## | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 115 | ▶ | sub oload_mod { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
oload_mod: called CC=10 SCAR=23.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 115 | ▶ | die "Wrong number of arguments given to oload_mod()" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | if @_ > 3; | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 115 | my $ok = is_ok($_[1]); # check that 2nd arg is suitable. | |||||||||||||||||||||||||||||||||||||||||
| 172 | 115 | ▶ | die "Bad argument given to oload_mod" unless $ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 115 | my $third_arg = $_[2]; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 115 | my ($num, $den); | |||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 115 | ▶ | if($ok == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 32 | $num = $_[0]->{val}; | |||||||||||||||||||||||||||||||||||||||||
| 179 | 32 | $den = $_[1]->{val}; | |||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | elsif($third_arg) { | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 29 | $num = $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 29 | $den = $_[0]->{val}; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 54 | $num = $_[0]->{val}; | |||||||||||||||||||||||||||||||||||||||||
| 187 | 54 | $den = $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 115 | ▶ | return Math::JS->new(_get_nan()) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
_infnan($num) or _isnan($den) or $den == 0
_infnan($num) or _isnan($den)
MC/DC100%3/3
_infnan($num) or _isnan($den) or $den == 0
_infnan($num)
_isnan($den)
$den == 0
Truth table100%4/4
A or B or C
A= _infnan($num)B= _isnan($den)C= $den == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | if(_infnan($num) || _isnan($den) || $den == 0); | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 110 | ▶ | return Math::JS->new($num) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
_isinf($den) or $num == 0
MC/DC100%2/2
_isinf($den) or $num == 0
_isinf($den)
$num == 0
Truth table100%3/3
A or B
A= _isinf($den)B= $num == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | if(_isinf($den) || $num == 0); | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 106 | return Math::JS->new(_fmod($num, $den)); | |||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | ########### ** ########## | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 5 | ▶ | sub oload_pow { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
oload_pow: called CC=10 SCAR=34.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 5 | ▶ | die "Wrong number of arguments given to oload_pow()" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | if @_ > 3; | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 5 | my $ok = is_ok($_[1]); # check that 2nd arg is suitable. | |||||||||||||||||||||||||||||||||||||||||
| 203 | 5 | ▶ | die "Bad argument given to oload_div" unless $ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 5 | my $third_arg = $_[2]; | |||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 5 | my $val0 = $_[0]->{val}; | |||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 5 | ▶ | if($ok == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | if($third_arg) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | return Math::JS->new(_get_nan()) | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | if($_[1]->{val} < 0 && $val0 != int($val0)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_[1]{"val"} < 0 and $val0 != int $val0
MC/DC0%0/2
$_[1]{"val"} < 0 and $val0 != int $val0
$_[1]{"val"} < 0
$val0 != int $val0
Truth table0%0/3
A and B
A= $_[1]{"val"} < 0B= $val0 != int $val0
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | return Math::JS->new($_[1]->{val} ** $val0); | |||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | return Math::JS->new(_get_nan()) | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | if($val0 < 0 && $_[1]->{val} != int($_[1]->{val})); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$val0 < 0 and $_[1]{"val"} != int $_[1]{"val"}
MC/DC0%0/2
$val0 < 0 and $_[1]{"val"} != int $_[1]{"val"}
$val0 < 0
$_[1]{"val"} != int $_[1]{"val"}
Truth table0%0/3
A and B
A= $val0 < 0B= $_[1]{"val"} != int $_[1]{"val"}
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | return Math::JS->new($val0 ** $_[1]->{val}); | |||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 5 | ▶ | return Math::JS->new($_[1] ** $val0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | if $third_arg; | ||||||||||||||||||||||||||||||||||||||||||
| 223 | 4 | return Math::JS->new($val0 ** $_[1]); | |||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | ########### & ########## | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 36 | ▶ | sub oload_and { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
oload_and: called CC=7 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 36 | ▶ | die "Wrong number of arguments given to oload_and()" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | if @_ > 3; | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 36 | my $ok = is_ok($_[1]); # check that 2nd arg is suitable. | |||||||||||||||||||||||||||||||||||||||||
| 232 | 36 | ▶ | die "Bad argument given to oload_and" unless $ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 36 | my $val0 = $_[0]->{val}; | |||||||||||||||||||||||||||||||||||||||||
| 235 | $val0 = reduce($val0) | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 36 | ▶ | if $_[0]->{type} eq 'number'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 36 | my $retval; | |||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 36 | ▶ | if($ok == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 32 | my $val1 = $_[1]->{val}; | |||||||||||||||||||||||||||||||||||||||||
| 242 | $val1 = reduce($val1) | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 32 | ▶ | if $_[1]->{type} eq 'number'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 32 | $retval = ($val0 & 0xffffffff) & ($val1 & 0xffffffff); | |||||||||||||||||||||||||||||||||||||||||
| 246 | 32 | return Math::JS->new(unpack 'l', pack 'L', $retval); | |||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 4 | my $val1 = $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 250 | 4 | ▶ | $val1 = reduce($val1) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | if $ok == 4; | ||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | 4 | $retval = ($val0 & 0xffffffff) & ($val1 & 0xffffffff); | |||||||||||||||||||||||||||||||||||||||||
| 254 | 4 | return Math::JS->new(unpack 'l', pack 'L', $retval); | |||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | ########### | ########## | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 32 | ▶ | sub oload_ior { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
oload_ior: called CC=7 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 32 | ▶ | die "Wrong number of arguments given to oload_ior()" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | if @_ > 3; | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 32 | my $ok = is_ok($_[1]); # check that 2nd arg is suitable. | |||||||||||||||||||||||||||||||||||||||||
| 263 | 32 | ▶ | die "Bad argument given to oload_ior" unless $ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | 32 | my $val0 = $_[0]->{val}; | |||||||||||||||||||||||||||||||||||||||||
| 266 | $val0 = reduce($val0) | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 32 | ▶ | if $_[0]->{type} eq 'number'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | 32 | my $retval; | |||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 32 | ▶ | if($ok == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 28 | my $val1 = $_[1]->{val}; | |||||||||||||||||||||||||||||||||||||||||
| 273 | $val1 = reduce($val1) | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 28 | ▶ | if $_[1]->{type} eq 'number'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | 28 | $retval = ($val0 & 0xffffffff) | ($val1 & 0xffffffff); | |||||||||||||||||||||||||||||||||||||||||
| 277 | 28 | return Math::JS->new(unpack 'l', pack 'L', $retval); | |||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | 4 | my $val1 = $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 281 | 4 | ▶ | $val1 = reduce($val1) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | if $ok == 4; | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 4 | $retval = ($val0 & 0xffffffff) | ($val1 & 0xffffffff); | |||||||||||||||||||||||||||||||||||||||||
| 285 | 4 | return Math::JS->new(unpack 'l', pack 'L', $retval); | |||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | ########### ^ ########## | ||||||||||||||||||||||||||||||||||||||||||
| 289 | 41 | ▶ | sub oload_xor { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
oload_xor: called CC=7 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | 41 | ▶ | die "Wrong number of arguments given to oload_xor()" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | if @_ > 3; | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | 41 | my $ok = is_ok($_[1]); # check that 2nd arg is suitable. | |||||||||||||||||||||||||||||||||||||||||
| 294 | 41 | ▶ | die "Bad argument given to oload_xor" unless $ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 41 | my $val0 = $_[0]->{val}; | |||||||||||||||||||||||||||||||||||||||||
| 297 | $val0 = reduce($val0) | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 41 | ▶ | if $_[0]->{type} eq 'number'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 41 | my $retval; | |||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | 41 | ▶ | if($ok == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 37 | my $val1 = $_[1]->{val}; | |||||||||||||||||||||||||||||||||||||||||
| 304 | $val1 = reduce($val1) | ||||||||||||||||||||||||||||||||||||||||||
| 305 | 37 | ▶ | if $_[1]->{type} eq 'number'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 37 | $retval = ($val0 & 0xffffffff) ^ ($val1 & 0xffffffff); | |||||||||||||||||||||||||||||||||||||||||
| 308 | 37 | return Math::JS->new(unpack 'l', pack 'L', $retval); | |||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | 4 | my $val1 = $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 312 | 4 | ▶ | $val1 = reduce($val1) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | if $ok == 4; | ||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | 4 | $retval = ($val0 & 0xffffffff) ^ ($val1 & 0xffffffff); | |||||||||||||||||||||||||||||||||||||||||
| 316 | 4 | return Math::JS->new(unpack 'l', pack 'L', $retval); | |||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | ########### ~ ########## | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 21 | ▶ | sub oload_not { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
oload_not: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | 21 | ▶ | die "Wrong number of arguments given to oload_not()" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | if @_ > 3; | ||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | 21 | my $val = $_[0]->{val}; | |||||||||||||||||||||||||||||||||||||||||
| 325 | $val = reduce($val ) | ||||||||||||||||||||||||||||||||||||||||||
| 326 | 21 | ▶ | if $_[0]->{type} eq 'number'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 21 | ▶ | return Math::JS->new( MAX_ULONG - $val ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | if($val > MAX_SLONG); | ||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | 17 | return Math::JS->new( -$val - 1); | |||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | ########### ++ ########## | ||||||||||||||||||||||||||||||||||||||||||
| 335 | 3 | ▶ | sub oload_inc { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
oload_inc: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 3 | $_[0]->{val} += 1; | |||||||||||||||||||||||||||||||||||||||||
| 337 | # 'type' needs to be checked | ||||||||||||||||||||||||||||||||||||||||||
| 338 | 3 | $_[0]->{type} = $classify{is_ok($_[0]->{val})}; | |||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | ########### -- ########## | ||||||||||||||||||||||||||||||||||||||||||
| 342 | 3 | ▶ | sub oload_dec { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
oload_dec: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 3 | $_[0]->{val} -= 1; | |||||||||||||||||||||||||||||||||||||||||
| 344 | # 'type' needs to be checked | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 3 | $_[0]->{type} = $classify{is_ok($_[0]->{val})}; | |||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | ########### "" ########## | ||||||||||||||||||||||||||||||||||||||||||
| 349 | 346 | ▶ | sub oload_stringify { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
oload_stringify: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 350 | 346 | my $val = $_[0]->{val}; | |||||||||||||||||||||||||||||||||||||||||
| 351 | # "l" is signed 32-bit integer; "L" is unsigned 32-bit integer. | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 346 | my $ret; | |||||||||||||||||||||||||||||||||||||||||
| 353 | 346 | ▶ | if ($_[0]->{type} eq 'sint32') { $ret = unpack("l", pack("L", $val)) } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | elsif ($_[0]->{type} eq 'uint32') { $ret = unpack("L", pack("L", $val)) } | |||||||||||||||||||||||||||||||||||||||||
| 355 | elsif (_isinf($val)) { | ||||||||||||||||||||||||||||||||||||||||||
| 356 | 2 | ▶ | $ret = $val > 0 ? 'Infinity' : '-Infinity'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 358 | elsif(_isnan($val)) { | ||||||||||||||||||||||||||||||||||||||||||
| 359 | 1 | $ret = 'nan'; | |||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||
| 361 | ▶ | elsif ($val < 1e+21 && $val == int($val)) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$val < "1e+21" and $val == int $val
MC/DC100%2/2
$val < "1e+21" and $val == int $val
$val < "1e+21"
$val == int $val
Truth table100%3/3
A and B
A= $val < "1e+21"B= $val == int $val
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | 11 | $ret = sprintf "%.21g", $val; | |||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||
| 364 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 365 | 221 | if(USE_RYU) { | |||||||||||||||||||||||||||||||||||||||||
| 366 | $ret = Math::Ryu::fmtpy(Math::Ryu::d2s($val)); | ||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||
| 368 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 369 | 221 | $ret = sprintf "%.17g", $val; | |||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||
| 372 | 346 | return "$ret"; | |||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | ########### >= ########## | ||||||||||||||||||||||||||||||||||||||||||
| 376 | 103 | ▶ | sub oload_gte { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
oload_gte: called CC=4 SCAR=14.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | 103 | ▶ | die "Wrong number of arguments given to oload_gte()" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | if @_ > 3; | ||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | 103 | my $cmp = oload_spaceship($_[0], $_[1], $_[2]); | |||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | 103 | ▶ | return 0 if !defined $cmp; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | 100 | ▶ | return 1 if $cmp >= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | ########### <= ########## | ||||||||||||||||||||||||||||||||||||||||||
| 388 | 103 | ▶ | sub oload_lte { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
oload_lte: called CC=4 SCAR=14.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | 103 | ▶ | die "Wrong number of arguments given to oload_lte()" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | if @_ > 3; | ||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 103 | my $cmp = oload_spaceship($_[0], $_[1], $_[2]); | |||||||||||||||||||||||||||||||||||||||||
| 393 | 103 | ▶ | return 0 if !defined $cmp; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | 100 | ▶ | return 1 if $cmp <= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | ########### == ########## | ||||||||||||||||||||||||||||||||||||||||||
| 399 | 541 | ▶ | sub oload_equiv { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
oload_equiv: called CC=4 SCAR=14.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | 541 | ▶ | die "Wrong number of arguments given to oload_equiv()" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | if @_ > 3; | ||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | 541 | my $cmp = oload_spaceship($_[0], $_[1], $_[2]); | |||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | 541 | ▶ | return 0 if !defined $cmp; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | 540 | ▶ | return 1 if $cmp == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | ########### != ########## | ||||||||||||||||||||||||||||||||||||||||||
| 411 | 3 | ▶ | sub oload_not_equiv { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
oload_not_equiv: called CC=4 SCAR=18.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 412 | 3 | ▶ | die "Wrong number of arguments given to oload_equiv()" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 413 | if @_ > 3; | ||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | 3 | my $cmp = oload_spaceship($_[0], $_[1], $_[2]); | |||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | 3 | ▶ | return 1 if !defined($cmp); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | ▶ | return 0 if $cmp == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | ########### > ########## | ||||||||||||||||||||||||||||||||||||||||||
| 423 | 3 | ▶ | sub oload_gt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
oload_gt: called CC=4 SCAR=18.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 3 | ▶ | die "Wrong number of arguments given to oload_gt()" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 425 | if @_ > 3; | ||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | 3 | my $cmp = oload_spaceship($_[0], $_[1], $_[2]); | |||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||
| 429 | 3 | ▶ | return 0 if !defined $cmp; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | ▶ | return 1 if $cmp > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | ########### < ########## | ||||||||||||||||||||||||||||||||||||||||||
| 435 | 3 | ▶ | sub oload_lt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
oload_lt: called CC=4 SCAR=18.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 436 | 3 | ▶ | die "Wrong number of arguments given to oload_lt()" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | if @_ > 3; | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | 3 | my $cmp = oload_spaceship($_[0], $_[1], $_[2]); | |||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | 3 | ▶ | return 0 if !defined $cmp; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | return 1 if $cmp < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||
| 446 | ########### <=> ########## | ||||||||||||||||||||||||||||||||||||||||||
| 447 | 756 | ▶ | sub oload_spaceship { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
oload_spaceship: called CC=6 SCAR=18.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 448 | 756 | ▶ | die "Wrong number of arguments given to oload_spaceship()" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | if @_ > 3; | ||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||
| 451 | 756 | my $ok = is_ok($_[1]); # check that 2nd arg is suitable. | |||||||||||||||||||||||||||||||||||||||||
| 452 | 756 | ▶ | die "Bad argument given to oload_spaceship" unless $ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||
| 454 | 756 | my $third_arg = $_[2]; | |||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | 756 | ▶ | if($ok == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||
| 458 | 76 | ▶ | if($third_arg) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | return ($_[1]->{val} <=> $_[0]->{val}); | |||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||
| 461 | 76 | return ($_[0]->{val} <=> $_[1]->{val}); | |||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||
| 464 | 680 | my $second = $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||
| 466 | 680 | ▶ | if($third_arg) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 467 | 6 | return ($second <=> $_[0]->{val}); | |||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||
| 469 | 674 | return ($_[0]->{val} <=> $second); | |||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | ########### << ########## | ||||||||||||||||||||||||||||||||||||||||||
| 473 | 103 | ▶ | sub oload_lshift { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
oload_lshift: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 474 | 103 | ▶ | die "Wrong number of arguments given to oload_lshift()" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | if @_ > 3; | ||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||
| 477 | 103 | my $shift = abs(int $_[1]) % 32; | |||||||||||||||||||||||||||||||||||||||||
| 478 | 103 | ▶ | $shift = 32 - $shift if ($_[1] < 0 && $shift); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$_[1] < 0 and $shift
MC/DC100%2/2
$_[1] < 0 and $shift
$_[1] < 0
$shift
Truth table100%3/3
A and B
A= $_[1] < 0B= $shift
| |||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | 103 | my $val = $_[0]->{val}; | |||||||||||||||||||||||||||||||||||||||||
| 481 | $val = reduce($val) | ||||||||||||||||||||||||||||||||||||||||||
| 482 | 103 | ▶ | if $_[0]->{type} eq 'number'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | 103 | return Math::JS->new(unpack 'l', pack 'l', (($val & 0xffffffff) << $shift) ); | |||||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||
| 487 | ########### >> ########## | ||||||||||||||||||||||||||||||||||||||||||
| 488 | 254 | ▶ | sub oload_rshift { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
oload_rshift: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||
| 490 | # From the javascript manual: | ||||||||||||||||||||||||||||||||||||||||||
| 491 | # <quote> | ||||||||||||||||||||||||||||||||||||||||||
| 492 | # Excess bits shifted off to the right are discarded, and copies of | ||||||||||||||||||||||||||||||||||||||||||
| 493 | # the leftmost bit are shifted in from the left. This operation is | ||||||||||||||||||||||||||||||||||||||||||
| 494 | # also called "sign-propagating right shift" or "arithmetic right | ||||||||||||||||||||||||||||||||||||||||||
| 495 | # shift", because the sign of the resulting number is the same as | ||||||||||||||||||||||||||||||||||||||||||
| 496 | # the sign of the first operand. | ||||||||||||||||||||||||||||||||||||||||||
| 497 | # </quote> | ||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||
| 499 | 254 | ▶ | die "Wrong number of arguments given to oload_rshift()" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 500 | if @_ > 3; | ||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||
| 502 | 254 | my $shift = abs(int $_[1]) % 32; | |||||||||||||||||||||||||||||||||||||||||
| 503 | 254 | ▶ | $shift = 32 - $shift if ($_[1] < 0 && $shift); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$_[1] < 0 and $shift
MC/DC100%2/2
$_[1] < 0 and $shift
$_[1] < 0
$shift
Truth table100%3/3
A and B
A= $_[1] < 0B= $shift
| |||||||||||||||||||||||||||||||||||||||||||
| 504 | 254 | my $type = $_[0]->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||
| 506 | 254 | my $val = $_[0]->{val}; | |||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||
| 508 | 254 | ▶ | if($type eq 'number') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 509 | 89 | $val = reduce($val); | |||||||||||||||||||||||||||||||||||||||||
| 510 | 89 | $type = $classify{is_ok($val)}; # Determine whether it reduced | |||||||||||||||||||||||||||||||||||||||||
| 511 | # to 'sint32' or 'uint32'. | ||||||||||||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||
| 514 | 254 | ▶ | if($type eq 'uint32' || ($type eq 'sint32' && $val < 0)) { # Highest order bit is set | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$type eq "uint32" or $type eq "sint32" and $val < 0
$type eq "sint32" and $val < 0
MC/DC66%2/3
$type eq "uint32" or $type eq "sint32" and $val < 0
$type eq "uint32"
$type eq "sint32"
$val < 0
Truth table75%3/4
A or B and C
A= $type eq "uint32"B= $type eq "sint32"C= $val < 0
| |||||||||||||||||||||||||||||||||||||||||||
| 515 | 143 | my $ior = 0xffffffff ^ ((1 << (32 - $shift)) - 1); | |||||||||||||||||||||||||||||||||||||||||
| 516 | 143 | my $val = unpack('l', pack 'L', $val) >> $shift; | |||||||||||||||||||||||||||||||||||||||||
| 517 | 143 | $val |= $ior; | |||||||||||||||||||||||||||||||||||||||||
| 518 | 143 | return Math::JS->new(unpack 'l', pack 'L', $val); | |||||||||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||
| 521 | # Highest order bit is unset | ||||||||||||||||||||||||||||||||||||||||||
| 522 | 111 | return Math::JS->new( ($val & 0xffffffff) >> ($_[1] % 32) ); | |||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||
| 525 | ########### >>> ########## | ||||||||||||||||||||||||||||||||||||||||||
| 526 | 115 | ▶ | sub urs { # unsigned 32-bit right shift (JavaScript's '>>>' operator). | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
urs: called CC=7 SCAR=19.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 527 | # This function is not available via overloading, and is | ||||||||||||||||||||||||||||||||||||||||||
| 528 | # exported only on request ie - use Math::JS qw(urs); | ||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||
| 530 | 115 | ▶ | die "Wrong number of arguments given to urs()" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 531 | unless @_ == 2; | ||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||
| 533 | # 1st argument must be a Math::JS object | ||||||||||||||||||||||||||||||||||||||||||
| 534 | 115 | ▶ | die "Bad first argument given to urs()" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 535 | unless ref($_[0]) eq 'Math::JS'; | ||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||
| 537 | # 2nd arg must be a perl number (IV or NV); | ||||||||||||||||||||||||||||||||||||||||||
| 538 | 115 | ▶ | die "Bad second arg given to urs()" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 539 | unless is_ok($_[1]) > 1; | ||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||
| 541 | 115 | my $shift = abs(int $_[1]) % 32; | |||||||||||||||||||||||||||||||||||||||||
| 542 | 115 | ▶ | $shift = 32 - $shift if ($_[1] < 0 && $shift); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$_[1] < 0 and $shift
MC/DC50%1/2
$_[1] < 0 and $shift
$_[1] < 0
$shift
Truth table66%2/3
A and B
A= $_[1] < 0B= $shift
| |||||||||||||||||||||||||||||||||||||||||||
| 543 | 115 | my $type = $_[0]->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||
| 545 | 115 | my $val = $_[0]->{val}; | |||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||
| 547 | 115 | ▶ | if($type eq 'number') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 548 | 113 | $val = reduce($val); | |||||||||||||||||||||||||||||||||||||||||
| 549 | # $val is either type 'uint3' or 'sint32' ... doesn't matter here. | ||||||||||||||||||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||
| 552 | 115 | $val = unpack('L', pack 'L', $val) >> $shift; | |||||||||||||||||||||||||||||||||||||||||
| 553 | 115 | return Math::JS->new($val); | |||||||||||||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||
| 556 | ########################### | ||||||||||||||||||||||||||||||||||||||||||
| 557 | ########################### | ||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||
| 559 | 316 | ▶ | sub reduce { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reduce: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 560 | # Reduce values that are greater than MAX_ULONG or | ||||||||||||||||||||||||||||||||||||||||||
| 561 | # less than MIN_SLONG to their appropriate value | ||||||||||||||||||||||||||||||||||||||||||
| 562 | # for use in bit manipulation operations, following | ||||||||||||||||||||||||||||||||||||||||||
| 563 | # the procedure used by javascipt. | ||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||
| 565 | 316 | my $mul = 1; | |||||||||||||||||||||||||||||||||||||||||
| 566 | 316 | my $big = shift; | |||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||
| 568 | 316 | ▶ | return 0 if _infnan($big); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||
| 570 | 229 | my $integer = int($big); | |||||||||||||||||||||||||||||||||||||||||
| 571 | 229 | ▶ | return $integer | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$integer <= 4294967295 and $integer >= '-2147483648'
MC/DC100%2/2
$integer <= 4294967295 and $integer >= '-2147483648'
$integer <= 4294967295
$integer >= '-2147483648'
Truth table100%3/3
A and B
A= $integer <= 4294967295B= $integer >= '-2147483648'
| |||||||||||||||||||||||||||||||||||||||||||
| 572 | if($integer <= MAX_ULONG && $integer >= MIN_SLONG); | ||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||
| 574 | 228 | ▶ | if($big < 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 575 | 108 | $mul = -1; | |||||||||||||||||||||||||||||||||||||||||
| 576 | 108 | $big = -$big; | |||||||||||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||||||||||
| 578 | 228 | my $max = shift; | |||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||
| 580 | 228 | $big -= int($big / (2 ** 32)) * (2 ** 32); | |||||||||||||||||||||||||||||||||||||||||
| 581 | 228 | my $ret = unpack 'l', pack 'l', $big; | |||||||||||||||||||||||||||||||||||||||||
| 582 | 228 | return $ret * $mul; | |||||||||||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||
| 585 | 2772 | ▶ | sub is_ok { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_ok: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 586 | 2772 | my $val = shift; | |||||||||||||||||||||||||||||||||||||||||
| 587 | 2772 | my $ret = _is_ok($val); | |||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||
| 589 | 2772 | ▶ | return $ret if $ret < 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||
| 591 | 2550 | ▶ | return 4 if $val != int($val); # Handles NaN | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 592 | 2042 | ▶ | return 4 if ($val > 4294967295 || $val < -2147483648); # Handles +Inf and -Inf | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$val > 4294967295 or $val < '-2147483648'
MC/DC100%2/2
$val > 4294967295 or $val < '-2147483648'
$val > 4294967295
$val < '-2147483648'
Truth table100%3/3
A or B
A= $val > 4294967295B= $val < '-2147483648'
| |||||||||||||||||||||||||||||||||||||||||||
| 593 | 1820 | ▶ | return 2 if $val >= 2147483648; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 594 | 1738 | return 3; # This is the only remaining possibility | |||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||
| 597 | 434 | ▶ | sub _infnan { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_infnan: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 598 | 434 | my $val = shift; | |||||||||||||||||||||||||||||||||||||||||
| 599 | 434 | my $inf = 2 ** 1500; | |||||||||||||||||||||||||||||||||||||||||
| 600 | 434 | ▶ | return 1 if ($val == $inf || $val == -$inf || $val != $val); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$val == $inf or $val == -$inf or $val != $val
$val == $inf or $val == -$inf
MC/DC100%3/3
$val == $inf or $val == -$inf or $val != $val
$val == $inf
$val == -$inf
$val != $val
Truth table100%4/4
A or B or C
A= $val == $infB= $val == -$infC= $val != $val
| |||||||||||||||||||||||||||||||||||||||||||
| 601 | 342 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 602 | } | ||||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||
| 604 | 350 | ▶ | sub _isnan { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_isnan: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 605 | 350 | my $val = shift; | |||||||||||||||||||||||||||||||||||||||||
| 606 | 350 | ▶ | return 1 if $val != $val; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 607 | 344 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 608 | } | ||||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||
| 610 | 345 | ▶ | sub _isinf { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_isinf: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 611 | 345 | my $val = shift; | |||||||||||||||||||||||||||||||||||||||||
| 612 | 345 | ▶ | return 1 if abs($val) == 2 ** 1500; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 613 | 340 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||
| 616 | 2 | ▶ | sub _get_pinf { # Return Math::JS object with a value of +Inf | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_pinf: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 617 | 2 | return 2 ** 1500; | |||||||||||||||||||||||||||||||||||||||||
| 618 | } | ||||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||
| 620 | 2 | ▶ | sub _get_ninf { # Return Math::JS object with a value of -Inf | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_ninf: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 621 | 2 | return -(2 ** 1500); | |||||||||||||||||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||
| 624 | 6 | ▶ | sub _get_nan { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_nan: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 625 | 6 | my $inf = 2 ** 1500; | |||||||||||||||||||||||||||||||||||||||||
| 626 | 6 | return ($inf / $inf); | |||||||||||||||||||||||||||||||||||||||||
| 627 | } | ||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||
| 629 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||
| 631 | __END__ | ||||||||||||||||||||||||||||||||||||||||||