| 1 | package Math::NumOnly; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | use overload | ||||||||||||||||||||||||||||
| 6 | 1 | ▶ | '+' => \&oload_add, | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | '-' => \&oload_sub, | ||||||||||||||||||||||||||||
| 8 | '*' => \&oload_mul, | ||||||||||||||||||||||||||||
| 9 | '/' => \&oload_div, | ||||||||||||||||||||||||||||
| 10 | '**' => \&oload_pow, | ||||||||||||||||||||||||||||
| 11 | '++' => \&oload_inc, | ||||||||||||||||||||||||||||
| 12 | '--' => \&oload_dec, | ||||||||||||||||||||||||||||
| 13 | '>=' => \&oload_gte, | ||||||||||||||||||||||||||||
| 14 | '<=' => \&oload_lte, | ||||||||||||||||||||||||||||
| 15 | '==' => \&oload_equiv, | ||||||||||||||||||||||||||||
| 16 | '>' => \&oload_gt, | ||||||||||||||||||||||||||||
| 17 | '<' => \&oload_lt, | ||||||||||||||||||||||||||||
| 18 | '<=>' => \&oload_spaceship, | ||||||||||||||||||||||||||||
| 19 | '""' => \&oload_stringify, | ||||||||||||||||||||||||||||
| 20 | 1 | ; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | require DynaLoader; | |||||||||||||||||||||||||||
| 25 | 1 | Math::NumOnly->DynaLoader::bootstrap($VERSION); | |||||||||||||||||||||||||||
| 26 | 1 | ▶ | sub dl_load_flags {0} | ||||||||||||||||||||||||||
|
Subroutine
dl_load_flags: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 36 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 29 | 36 | ▶ | shift if(!ref($_[0]) && $_[0] eq "Math::NumOnly"); # 'new' has been called as a method | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not ref $_[0] and $_[0] eq "Math::NumOnly"
MC/DC0%0/2
not ref $_[0] and $_[0] eq "Math::NumOnly"
not ref $_[0]
$_[0] eq "Math::NumOnly"
Truth table33%1/3
not(A) and B
A= not ref $_[0]B= $_[0] eq "Math::NumOnly"
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 36 | my $ok = is_ok($_[0]); | |||||||||||||||||||||||||||
| 32 | 36 | ▶ | die "Bad argument (or no argument) given to new" unless $ok; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 33 | ▶ | if($ok == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | # return a copy of the given Math::NumOnly object | ||||||||||||||||||||||||||||
| 36 | 0 | my $ret = shift; | |||||||||||||||||||||||||||
| 37 | 0 | return $ret; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # given arg must be a valid IV or NV | ||||||||||||||||||||||||||||
| 41 | 33 | my %h = ('val' => shift); | |||||||||||||||||||||||||||
| 42 | 33 | return bless(\%h, 'Math::NumOnly'); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 10 | ▶ | sub oload_add { | ||||||||||||||||||||||||||
|
Subroutine
oload_add: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 46 | 10 | ▶ | die "Wrong number of arguments given to oload_add()" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | if @_ > 3; | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 10 | my $ok = is_ok($_[1]); # check that 2nd arg is suitable. | |||||||||||||||||||||||||||
| 50 | 10 | ▶ | die "Bad argument given to oload_add" unless $ok; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 7 | ▶ | if($ok == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 2 | return Math::NumOnly->new($_[0]->{val} + $_[1]->{val}); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 5 | return Math::NumOnly->new($_[0]->{val} + $_[1]); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 5 | ▶ | sub oload_mul { | ||||||||||||||||||||||||||
|
Subroutine
oload_mul: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 60 | 5 | ▶ | die "Wrong number of arguments given to oload_mul()" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | if @_ > 3; | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 5 | my $ok = is_ok($_[1]); # check that 2nd arg is suitable. | |||||||||||||||||||||||||||
| 64 | 5 | ▶ | die "Bad argument given to oload_mul" unless $ok; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 4 | ▶ | if($ok == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 1 | return Math::NumOnly->new($_[0]->{val} * $_[1]->{val}); | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 3 | return Math::NumOnly->new($_[0]->{val} * $_[1]); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 6 | ▶ | sub oload_sub { | ||||||||||||||||||||||||||
|
Subroutine
oload_sub: called CC=6 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 74 | 6 | ▶ | die "Wrong number of arguments given to oload_sub()" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | if @_ > 3; | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 6 | my $ok = is_ok($_[1]); # check that 2nd arg is suitable. | |||||||||||||||||||||||||||
| 78 | 6 | ▶ | die "Bad argument given to oload_sub" unless $ok; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 4 | my $third_arg = $_[2]; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 4 | ▶ | if($ok == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 1 | ▶ | if($third_arg) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | return Math::NumOnly->new($_[1]->{val} - $_[0]->{val}); | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 1 | return Math::NumOnly->new($_[0]->{val} - $_[1]->{val}); | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 3 | ▶ | if($third_arg) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 1 | return Math::NumOnly->new($_[1] - $_[0]->{val}); | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | 2 | return Math::NumOnly->new($_[0]->{val} - $_[1]); | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 5 | ▶ | sub oload_div { | ||||||||||||||||||||||||||
|
Subroutine
oload_div: called CC=6 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 96 | 5 | ▶ | die "Wrong number of arguments given to oload_div()" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | if @_ > 3; | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 5 | my $ok = is_ok($_[1]); # check that 2nd arg is suitable. | |||||||||||||||||||||||||||
| 100 | 5 | ▶ | die "Bad argument given to oload_div" unless $ok; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 4 | my $third_arg = $_[2]; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 4 | ▶ | if($ok == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 1 | ▶ | if($third_arg) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 0 | return Math::NumOnly->new($_[1]->{val} / $_[0]->{val}); | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | 1 | return Math::NumOnly->new($_[0]->{val} / $_[1]->{val}); | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 3 | ▶ | if($third_arg) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 1 | return Math::NumOnly->new($_[1] / $_[0]->{val}); | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | 2 | return Math::NumOnly->new($_[0]->{val} / $_[1]); | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 5 | ▶ | sub oload_pow { | ||||||||||||||||||||||||||
|
Subroutine
oload_pow: called CC=6 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 118 | 5 | ▶ | die "Wrong number of arguments given to oload_pow()" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | if @_ > 3; | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 5 | my $ok = is_ok($_[1]); # check that 2nd arg is suitable. | |||||||||||||||||||||||||||
| 122 | 5 | ▶ | die "Bad argument given to oload_div" unless $ok; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 4 | my $third_arg = $_[2]; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 4 | ▶ | if($ok == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 1 | ▶ | if($third_arg) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 0 | return Math::NumOnly->new($_[1]->{val} ** $_[0]->{val}); | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | 1 | return Math::NumOnly->new($_[0]->{val} ** $_[1]->{val}); | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 3 | ▶ | if($third_arg) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 1 | return Math::NumOnly->new($_[1] ** $_[0]->{val}); | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | 2 | return Math::NumOnly->new($_[0]->{val} ** $_[1]); | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 1 | ▶ | sub oload_inc { | ||||||||||||||||||||||||||
|
Subroutine
oload_inc: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 140 | 1 | ($_[0]->{val}) += 1;; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 1 | ▶ | sub oload_dec { | ||||||||||||||||||||||||||
|
Subroutine
oload_dec: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 144 | 1 | ($_[0]->{val}) -= 1; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | ▶ | sub oload_stringify { | ||||||||||||||||||||||||||
|
Subroutine
oload_stringify: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 148 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 149 | 0 | return $self->{val}; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 4 | ▶ | sub oload_gte { | ||||||||||||||||||||||||||
|
Subroutine
oload_gte: called CC=3 SCAR=12.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 153 | 4 | ▶ | die "Wrong number of arguments given to oload_gte()" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | if @_ > 3; | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 4 | my $cmp = oload_spaceship($_[0], $_[1], $_[2]); | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 4 | ▶ | return 1 if $cmp >= 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 0 | return 0; | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 4 | ▶ | sub oload_lte { | ||||||||||||||||||||||||||
|
Subroutine
oload_lte: called CC=3 SCAR=12.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 163 | 4 | ▶ | die "Wrong number of arguments given to oload_lte()" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | if @_ > 3; | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 4 | my $cmp = oload_spaceship($_[0], $_[1], $_[2]); | |||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | #if($_[2]) { | ||||||||||||||||||||||||||||
| 169 | # return 1 if $cmp >= 0; | ||||||||||||||||||||||||||||
| 170 | # return 0; | ||||||||||||||||||||||||||||
| 171 | #} | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 4 | ▶ | return 1 if $cmp <= 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | 0 | return 0; | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 28 | ▶ | sub oload_equiv { | ||||||||||||||||||||||||||
|
Subroutine
oload_equiv: called CC=3 SCAR=13.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 178 | 28 | ▶ | die "Wrong number of arguments given to oload_equiv()" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | if @_ > 3; | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 28 | ▶ | return 1 if(oload_spaceship($_[0], $_[1], $_[2]) == 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | 0 | return 0; | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 2 | ▶ | sub oload_gt { | ||||||||||||||||||||||||||
|
Subroutine
oload_gt: called CC=3 SCAR=12.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 186 | 2 | ▶ | die "Wrong number of arguments given to oload_gt()" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | if @_ > 3; | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 2 | my $cmp = oload_spaceship($_[0], $_[1], $_[2]); | |||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 2 | ▶ | return 1 if $cmp > 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 192 | 0 | return 0; | |||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 2 | ▶ | sub oload_lt { | ||||||||||||||||||||||||||
|
Subroutine
oload_lt: called CC=3 SCAR=12.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 196 | 2 | ▶ | die "Wrong number of arguments given to oload_lt()" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | if @_ > 3; | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 2 | my $cmp = oload_spaceship($_[0], $_[1], $_[2]); | |||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 2 | ▶ | return 1 if $cmp < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | 0 | return 0; | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 46 | ▶ | sub oload_spaceship { | ||||||||||||||||||||||||||
|
Subroutine
oload_spaceship: called CC=6 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 206 | 46 | ▶ | die "Wrong number of arguments given to oload_spaceship()" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | if @_ > 3; | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 46 | my $ok = is_ok($_[1]); # check that 2nd arg is suitable. | |||||||||||||||||||||||||||
| 210 | 46 | ▶ | die "Bad argument given to oload_spaceship" unless $ok; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 46 | my $third_arg = $_[2]; | |||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 46 | ▶ | if($ok == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 215 | 0 | ▶ | if($third_arg) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | 0 | return ($_[1]->{val} <=> $_[0]->{val}); | |||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | 0 | return ($_[0]->{val} <=> $_[1]->{val}); | |||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | 46 | ▶ | if($third_arg) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | 10 | return ($_[1] <=> $_[0]->{val}); | |||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | 36 | return ($_[0]->{val} <=> $_[1]); | |||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 1 | 1; | |||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | __END__ | ||||||||||||||||||||||||||||