| 1 | package Math::SigDig; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | #Robert W. Leach | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | #Princeton University | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | #Carl Icahn Laboratory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | #Lewis Sigler Institute for Integrative Genomics | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | #Bioinformatics Group | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | #Room 133A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | #Princeton, NJ 08544 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | #rleach@genomics.princeton.edu | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | #Copyright 2014 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | #NOTICE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | #This software (Math::SigDig) and ancillary information (herein | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | #called "SOFTWARE") is free: you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | #it under the terms of the GNU General Public License as published by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | #the Free Software Foundation, either version 3 of the License, or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | #(at your option) any later version. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | #This software is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | #but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | #GNU General Public License for more details. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | #You should have received a copy of the GNU General Public License | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | #along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | #If SOFTWARE is modified to produce derivative works, such modified | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | #SOFTWARE should be clearly marked, so as not to confuse it with this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | #version. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | use 5.012003; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | use Exporter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | $VERSION = 1.00; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | @EXPORT = qw(sigdig getsigdig); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | @EXPORT_OK = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | %EXPORT_TAGS = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | sub sigdig | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 9 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sigdig: called CC=43 SCAR=49.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 9 | my $num = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 9 | ▶ | my $places = defined($_[1]) ? $_[1] : 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | #Pad with 0's by adding decimal places up to $places significant digits, or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | #if $places is 0, up to the pad value (note there can still be numbers in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | #this case with more significant digits than specified by the pad value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 9 | ▶ | my $pad = defined($_[2]) ? ($places > 0 && $_[2] ? $places : $_[2]) : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$places > 0 and $_[2]
MC/DC100%2/2
$places > 0 and $_[2]
$places > 0
$_[2]
Truth table100%3/3
A and B
A= $places > 0B= $_[2]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 9 | my $new_num = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 9 | ▶ | if(!defined($places) || $places !~ /\d/ || $places =~ /\D/ || $places < 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%3/9
not defined $places && $places =~ /\d/u or $places =~ /\D/u or $places < 0
not defined $places && $places =~ /\d/u or $places =~ /\D/u
defined $places && $places =~ /\d/u
MC/DC0%0/4
not defined $places && $places =~ /\d/u or $places =~ /\D/u or $places < 0
defined $places
$places =~ /\d/u
$places =~ /\D/u
$places < 0
Truth table20%1/5
not(A && B) or C or D
A= defined $placesB= $places =~ /\d/uC= $places =~ /\D/uD= $places < 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | print STDERR ("ERROR:sigdig(): An invalid number of significant ", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | "digits was specified."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | return($num); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | #0 means all are significant digits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | elsif($places == 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | $new_num = $num; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | my $cur_sig_dig = getsigdig($new_num); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | ▶ | if($pad > $cur_sig_dig) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | #If there's an exponent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | ▶ | if($new_num =~ /^([+\-]?[0-9\.]+)(e[+\-]?[0-9\.]+)$/i) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | my $pree = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $e = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | return(sigdig($pree,$places,$pad).$e); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | #If there's an exponent and no preceding number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | elsif($new_num =~ /^([+\-]?)e[+\-]?[0-9\.]+$/i) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my $sign = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my $e = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | return(sigdig($sign.'1',$places,$pad).$e); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | #Pad the number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | ▶ | if($new_num !~ /\./) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | {$new_num .= '.'} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | $new_num .= '0' x ($pad - $cur_sig_dig); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | return($new_num); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | return($new_num); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | #If there's an exponent with a preceding number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 7 | ▶ | if($num =~ /^([+\-]?[0-9\.]*)(e[+\-]?[0-9\.]+)$/i) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | my $pree = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | my $e = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | ▶ | $pree = $pree . '1' if($pree !~ /\d/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | return(sigdig($pree,$places,$pad).$e); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | ▶ | elsif($num =~ /[^0-9\.+\-]/ || $num =~ /\..*\./ || $num =~ /.[+\-]/) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$num =~ /[^0-9\.+\-]/u or $num =~ /\..*\./u or $num =~ /.[+\-]/u
$num =~ /[^0-9\.+\-]/u or $num =~ /\..*\./u
MC/DC0%0/3
$num =~ /[^0-9\.+\-]/u or $num =~ /\..*\./u or $num =~ /.[+\-]/u
$num =~ /[^0-9\.+\-]/u
$num =~ /\..*\./u
$num =~ /.[+\-]/u
Truth table25%1/4
A or B or C
A= $num =~ /[^0-9\.+\-]/uB= $num =~ /\..*\./uC= $num =~ /.[+\-]/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | print STDERR ("ERROR:sigdig(): Invalid number format: [$num]."); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | return($num); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | elsif($num == 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if($pad) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | $new_num = '0.'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | if($new_num !~ /\./) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | {$new_num .= '.'} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | $new_num .= '0' x $pad; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | return($new_num); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | return(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 6 | my $first_real = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 6 | my $num_added = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 6 | my $decimal_seen = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 6 | my $last_digit = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 6 | my $sign = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 6 | foreach my $digit (unpack("(A)*",$num)) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 34 | ▶ | if($digit =~ /\+|-/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | $sign = $digit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 33 | ▶ | if($digit =~ /[1-9]/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 23 | {$first_real = 1} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | elsif($digit eq '.') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 6 | $decimal_seen = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 6 | ▶ | if($new_num eq '') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | {$new_num = '0'} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 6 | ▶ | if($num_added < $places) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 5 | {$new_num .= '.'} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | elsif($num_added > $places) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | {last} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 6 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 27 | ▶ | if($first_real) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 27 | ▶ | if($num_added < $places) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 21 | $new_num .= $digit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 21 | $num_added++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | elsif($num_added == $places) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 6 | ▶ | if($digit >= 5) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | #This gets rid of the decimal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | my $tmp_num = join("",split(/\D*/,$new_num)) + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 1 | ▶ | if($new_num =~ /\.(\d*)$/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | my $len = length($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | ▶ | unless($tmp_num =~ s/(?=\d{$len}\Z)/./) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | if($new_num =~ /^(0\.0+)/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | {$tmp_num = "$1$tmp_num"} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 1 | $new_num = $tmp_num; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | #If we haven't gotten to the end of the whole number yet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 6 | ▶ | if(!$decimal_seen) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | $new_num .= '0'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | $num_added++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 6 | {last} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | elsif(!$decimal_seen) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | $new_num .= '0'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | $num_added++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | {last} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 21 | $last_digit = $digit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | elsif($decimal_seen) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | {$new_num .= '0'} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 6 | ▶ | if($pad) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 1 | my $cur_sig_dig = getsigdig($new_num); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | ▶ | if($pad > $cur_sig_dig && $new_num !~ /\./) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$pad > $cur_sig_dig and not $new_num =~ /\./u
MC/DC0%0/2
$pad > $cur_sig_dig and not $new_num =~ /\./u
$pad > $cur_sig_dig
not $new_num =~ /\./u
Truth table33%1/3
A and not(B)
A= $pad > $cur_sig_digB= not $new_num =~ /\./u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | {$new_num .= '.'} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 1 | $new_num .= '0' x ($pad - $cur_sig_dig); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | #Trim the trailing zeros | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | elsif($new_num =~ /\./i) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 4 | $new_num =~ s/0+$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 4 | $new_num =~ s/\.$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 6 | return("$sign$new_num"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | sub getsigdig | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 11 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getsigdig: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 11 | my $num = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 11 | ▶ | my $nowholetail = defined($_[1]) ? $_[1] : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 11 | ▶ | my $nodecimaltail = defined($_[2]) ? $_[2] : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | #Remove sign | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 11 | $num =~ s/[+\-]+//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | #Repair exponents with assumed 1s | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 11 | ▶ | if($num =~ /^e/i) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | {$num = "1$num"} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | #Remove exponent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 11 | $num =~ s/e.*//i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | #Remove leading zeros | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 11 | $num =~ s/^0+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | #If $nowholetail is true and there's no decimal point, remove trailing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | #whole-number zeros | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 11 | ▶ | $num =~ s/0+$// if($nowholetail && $num !~ /\./); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$nowholetail and not $num =~ /\./u
MC/DC100%2/2
$nowholetail and not $num =~ /\./u
$nowholetail
not $num =~ /\./u
Truth table100%3/3
A and not(B)
A= $nowholetailB= not $num =~ /\./u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | #Remove decimal point | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 11 | $num =~ s/\.//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | #If $nodecimaltail is true, remove all trailing zeros | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 11 | ▶ | $num =~ s/0+$// if($nodecimaltail); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 11 | return(length($num)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||