| 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 | 8 | ▶ | { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
| |||||||||||||||||||||
| 17 | 8 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | 8 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 8 | warnings::register_categories( 'HTML::Object' ); | |||||||||||||||||||
| 20 | 8 | ▶ | use parent qw( Module::Generic::Number ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | 8 | ▶ | use vars qw( $EPSILON $VERSION ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | 8 | ▶ | use Config; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 23 | # use Machine::Epsilon (); | ||||||||||||||||||||
| 24 | 8 | require POSIX; | |||||||||||||||||||
| 25 | 8 | my( $POS_INF, $NEG_INF ); | |||||||||||||||||||
| 26 | 8 | ▶ | if( $] >= 5.022 ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 27 | { | ||||||||||||||||||||
| 28 | 8 | 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 | 8 | $POS_INF = 9**9**9; | |||||||||||||||||||
| 32 | 8 | $NEG_INF = -9**9**9; | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | else | ||||||||||||||||||||
| 35 | { | ||||||||||||||||||||
| 36 | 0 | $POS_INF = 9**9**9; | |||||||||||||||||||
| 37 | 0 | $NEG_INF = -9**9**9; | |||||||||||||||||||
| 38 | *isnan = sub | ||||||||||||||||||||
| 39 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=10.1
| |||||||||||||||||||||
| 40 | 0 | ▶ | return(0) if( !defined( $_[0] ) ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | 8 | ▶ | no warnings 'numeric'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 42 | 0 | return( $_[0] != $_[0] ); | |||||||||||||||||||
| 43 | 0 | }; | |||||||||||||||||||
| 44 | } | ||||||||||||||||||||
| 45 | 8 | ▶ | use constant { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
| |||||||||||||||||||||
| 46 | MAX_SAFE_INTEGER => (POSIX::pow(2,53) - 1), | ||||||||||||||||||||
| 47 | # MAX_VALUE => (1.7976931348623157 * POSIX::pow(10,308)), | ||||||||||||||||||||
| 48 | 8 | ▶ | MAX_VALUE => (POSIX::pow(2, $Config::Config{use64bitint} eq 'define' ? 64 : 32)), | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 | 8 | }; | |||||||||||||||||||
| 56 | 8 | our $EPSILON; | |||||||||||||||||||
| 57 | 8 | our $VERSION = 'v0.2.0'; | |||||||||||||||||||
| 58 | }; | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 8 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 61 | 8 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | sub init | ||||||||||||||||||||
| 64 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
init: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 65 | 0 | my $self = shift( @_ ); | |||||||||||||||||||
| 66 | 0 | $self->{_init_strict_use_sub} = 1; | |||||||||||||||||||
| 67 | 0 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | # $EPSILON = Machine::Epsilon::machine_epsilon() if( !defined( $EPSILON ) ); | ||||||||||||||||||||
| 69 | 0 | ▶ | $EPSILON = POSIX::pow(2,-52) if( !defined( $EPSILON ) ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 70 | 0 | return( $self ); | |||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | # Note: property EPSILON | ||||||||||||||||||||
| 74 | 0 | ▶ | sub EPSILON : lvalue { return( shift->_lvalue({ | ||||||||||||||||||
|
Subroutine
EPSILON: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 75 | get => sub | ||||||||||||||||||||
| 76 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 77 | 0 | my $self = shift( @_ ); | |||||||||||||||||||
| 78 | 0 | return( $EPSILON ); | |||||||||||||||||||
| 79 | }, | ||||||||||||||||||||
| 80 | set => sub | ||||||||||||||||||||
| 81 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 82 | 0 | my( $self, $ref ) = @_; | |||||||||||||||||||
| 83 | 0 | $EPSILON = shift( @$ref ); | |||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | 0 | }, @_ ) ); } | |||||||||||||||||||
| 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 | 8 | my $POS_INF = POSITIVE_INFINITY; | |||||||||||||||||||
| 100 | 0 | ▶ | sub isFinite { return( $_[1] != $POS_INF ); } | ||||||||||||||||||
|
Subroutine
isFinite: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | 0 | ▶ | sub isInteger { return( shift->_is_integer( $_[0] ) ); } | ||||||||||||||||||
|
Subroutine
isInteger: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | 0 | ▶ | sub isNaN { return( isnan( $_[1] ) ); } | ||||||||||||||||||
|
Subroutine
isNaN: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 0 | ▶ | sub isSafeInteger { return( $_[0]->_is_integer( $_[1] ) && abs( $_[1] ) < MAX_SAFE_INTEGER ); } | ||||||||||||||||||
|
Subroutine
isSafeInteger: not called CC=2 SCAR=17.9
Pod
documented
Condition0%0/3
$_[0]->_is_integer($_[1]) && abs $_[1] < 9007199254740991.0
MC/DC0%0/2
$_[0]->_is_integer($_[1]) && abs $_[1] < 9007199254740991.0
$_[0]->_is_integer($_[1])
abs $_[1] < 9007199254740991.0
Truth table0%0/3
A && B
A= $_[0]->_is_integer($_[1])B= abs $_[1] < 9007199254740991.0
| |||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | 0 | ▶ | sub parseFloat { return( shift->new( shift( @_ ) ) ); } | ||||||||||||||||||
|
Subroutine
parseFloat: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 0 | ▶ | sub parseInt { return( shift->new( shift( @_ ) ) ); } | ||||||||||||||||||
|
Subroutine
parseInt: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | 8 | 1; | |||||||||||||||||||
| 113 | # NOTE: POD | ||||||||||||||||||||
| 114 | __END__ | ||||||||||||||||||||