blib/lib/HTML/Object/DOM/Number.pm untested

filter: Statementstmt 0.0% 0 / 62 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 5 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 19 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 103 CC 5 SCAR 17.0
CC
5
Cov
0%
BEGIN
20.0
init
6.0
EPSILON
2.0
CRAP 5.5
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/DOM/Number.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/12/13
7 ## Modified 2022/09/18
8 ## All rights reserved.
9 ##
10 ##
11 ## This program is free software; you can redistribute it and/or modify it
12 ## under the same terms as Perl itself.
13 ##----------------------------------------------------------------------------
14 package HTML::Object::DOM::Number;
15 BEGIN
16 {
17 use strict;
18 use warnings;
19 warnings::register_categories( 'HTML::Object' );
20 use parent qw( Module::Generic::Number );
21 use vars qw( $EPSILON $VERSION );
22 use Config;
23 # use Machine::Epsilon ();
24 require POSIX;
25 my( $POS_INF, $NEG_INF );
26 if( $] >= 5.022 )
27 {
28 POSIX->import( qw( isnan ) );
29 # NOTE: Inf and NaN are bare literals since 5.8.1 and do not need importing.
30 # POSIX only added them as exports in 5.22, hence the version guard.
31 $POS_INF = 9**9**9;
32 $NEG_INF = -9**9**9;
33 }
34 else
35 {
36 $POS_INF = 9**9**9;
37 $NEG_INF = -9**9**9;
38 *isnan = sub
39 {
40 return(0) if( !defined( $_[0] ) );
41 no warnings 'numeric';
42 return( $_[0] != $_[0] );
43 };
44 }
45 use constant {
46 MAX_SAFE_INTEGER => (POSIX::pow(2,53) - 1),
47 # MAX_VALUE => (1.7976931348623157 * POSIX::pow(10,308)),
48 MAX_VALUE => (POSIX::pow(2, $Config::Config{use64bitint} eq 'define' ? 64 : 32)),
49 MIN_SAFE_INTEGER => (-(POSIX::pow(2,53) - 1)),
50 MIN_VALUE => POSIX::pow(2, -1074),
51 # <https://perldoc.perl.org/perldata#Special-floating-point:-infinity-(Inf)-and-not-a-number-(NaN)>
52 # NEGATIVE_INFINITY => -9**9**9,
53 NEGATIVE_INFINITY => $NEG_INF,
54 POSITIVE_INFINITY => $POS_INF,
55 };
56 our $EPSILON;
57 our $VERSION = 'v0.2.0';
58 };
59  
60 use strict;
61 use warnings;
62  
63 sub init
64 {
65 my $self = shift( @_ );
66 $self->{_init_strict_use_sub} = 1;
67 $self->SUPER::init( @_ ) || return( $self->pass_error );
68 # $EPSILON = Machine::Epsilon::machine_epsilon() if( !defined( $EPSILON ) );
69 $EPSILON = POSIX::pow(2,-52) if( !defined( $EPSILON ) );
70 return( $self );
71 }
72  
73 # Note: property EPSILON
74 sub EPSILON : lvalue { return( shift->_lvalue({
75 get => sub
76 {
77 my $self = shift( @_ );
78 return( $EPSILON );
79 },
80 set => sub
81 {
82 my( $self, $ref ) = @_;
83 $EPSILON = shift( @$ref );
84 }
85 }, @_ ) ); }
86  
87 # Note: property MAX_SAFE_INTEGER is a constant
88  
89 # Note: property MAX_VALUE is a constant
90  
91 # Note: property MIN_SAFE_INTEGER is a constant
92  
93 # Note: property MIN_VALUE is a constant
94  
95 # Note: property NEGATIVE_INFINITY is a constant
96  
97 # Note: property POSITIVE_INFINITY is a constant
98  
99 my $POS_INF = POSITIVE_INFINITY;
100 sub isFinite { return( $_[1] != $POS_INF ); }
101  
102 sub isInteger { return( shift->_is_integer( $_[0] ) ); }
103  
104 sub isNaN { return( isnan( $_[1] ) ); }
105  
106 sub isSafeInteger { return( $_[0]->_is_integer( $_[1] ) && abs( $_[1] ) < MAX_SAFE_INTEGER ); }
107  
108 sub parseFloat { return( shift->new( shift( @_ ) ) ); }
109  
110 sub parseInt { return( shift->new( shift( @_ ) ) ); }
111  
112 1;
113 # NOTE: POD
114 __END__