line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Math::ScientificNotation::Util; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2016-06-17'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.003'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
366
|
use Exporter qw(import); |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
176
|
|
7
|
|
|
|
|
|
|
our @EXPORT_OK = qw(sci2dec); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub sci2dec { |
10
|
19
|
|
|
19
|
1
|
44
|
my $num = shift; |
11
|
19
|
50
|
|
|
|
53
|
die "Please specify a number" unless defined $num; |
12
|
|
|
|
|
|
|
|
13
|
19
|
100
|
|
|
|
133
|
if ($num =~ /\A(?:[+-]?)(?:\d+\.?|\d*\.(\d+))[eE]([+-]?\d+)\z/) { |
|
|
50
|
|
|
|
|
|
14
|
17
|
|
100
|
|
|
101
|
my $num_digs_after_dec = length($1 || "") - $2; |
15
|
17
|
100
|
|
|
|
43
|
$num_digs_after_dec = 0 if $num_digs_after_dec < 0; |
16
|
17
|
|
|
|
|
226
|
return sprintf("%.${num_digs_after_dec}f", $num); |
17
|
|
|
|
|
|
|
} elsif ($num =~ /\A[+-]?(?:\d+\.?|\d*\.\d+)\z/) { |
18
|
|
|
|
|
|
|
# already in decimal notation |
19
|
2
|
|
|
|
|
12
|
return $num; |
20
|
|
|
|
|
|
|
} else { |
21
|
0
|
|
|
|
|
|
die "Not a decimal number: $num"; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
1; |
26
|
|
|
|
|
|
|
# ABSTRACT: Utilities related to scientific notation |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
__END__ |