File Coverage

blib/lib/Float/Util.pm
Criterion Covered Total %
statement 20 20 100.0
branch 1 2 50.0
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 28 29 96.5


line stmt bran cond sub pod time code
1             package Float::Util;
2              
3             our $DATE = '2018-03-09'; # DATE
4             our $VERSION = '0.002'; # VERSION
5              
6 1     1   52807 use 5.010001;
  1         10  
7 1     1   3 use strict;
  1         9  
  1         27  
8 1     1   4 use warnings;
  1         1  
  1         19  
9 1     1   3 use Config;
  1         1  
  1         38  
10              
11 1     1   4 use Exporter qw(import);
  1         1  
  1         173  
12             our @EXPORT_OK = qw(is_exact);
13              
14             my $numsigfdigs = (
15             $Config{nvsize} == 16 ? 36 :
16             $Config{nvsize} == 8 ? 17 :
17             die "Can't handle nvsize=$Config{nvsize}")+1;
18             my $fmt = "%.${numsigfdigs}f";
19              
20             sub is_exact {
21 4     4 1 850 my $strdec = shift;
22              
23 4 50       22 $strdec =~ /\A-?[0-9]+(?:\.[0-9]+)?\z/
24             or die "Invalid input '$strdec', please supply a decimal number string";
25              
26 4         27 my $fmtnum = sprintf $fmt, $strdec;
27 4         7 for ($strdec, $fmtnum) { s/\.?0+\z// }
  8         16  
28             #say "D: strdec=<$strdec>, fmtnum=<$fmtnum>";
29 4         14 $strdec eq $fmtnum;
30             }
31              
32             1;
33             # ABSTRACT: Utilities related to floating point numbers
34              
35             __END__