NAME
HTML::Object::DOM::Number - HTML Object DOM Number
SYNOPSIS
use HTML::Object::DOM::Number;
my $this = HTML::Object::DOM::Number->new ||
die( HTML::Object::DOM::Number->error, "\n" );
VERSION
v0.2.0
DESCRIPTION
This interface represents and manipulates numbers like 37 or -9.25.
It inherits from Module::Generic::Number
PROPERTIES
EPSILON
The smallest interval between two representable numbers.
The EPSILON property has a value of approximately 2.22044604925031e-16, or 2^-52
You do not have to create a HTML::Object::DOM::Number object to access this static property (use HTML::Object::DOM::Number->EPSILON).
Example:
my $result = abs(0.2 - 0.3 + 0.1);
say $result;
# expected output: 2.77555756156289e-17
say $result < HTML::Object::DOM::Number->EPSILON;
# expected output: 1 (i.e. true)
if( !defined( HTML::Object::DOM::Number->EPSILON ) )
{
HTML::Object::DOM::Number->EPSILON = POSIX::pow(2, -52);
}
See also Mozilla documentation
MAX_SAFE_INTEGER
This represents the maximum safe integer in JavaScript i.e. (2^53 - 1).
However, under perl, it does not work the same way.
Example:
Under JavaScript
const x = Number.MAX_SAFE_INTEGER + 1;
const y = Number.MAX_SAFE_INTEGER + 2;
console.log(Number.MAX_SAFE_INTEGER);
// expected output: 9007199254740991
console.log(x);
// expected output: 9007199254740992
console.log(x === y);
// expected output: true
However, under perl, $x == $y
would be false of course.
See also Mozilla documentation
MAX_VALUE
This represents the maximum numeric value representable in JavaScript.
The MAX_VALUE
property has a value of approximately 1.79E+308, or 2^64. Values larger than MAX_VALUE are represented as Infinity.
Because MAX_VALUE is a static property of HTML::Object::DOM::Number, you always use it as HTML::Object::DOM::Number-
MAX_VALUE>, rather than as a property of a HTML::Object::DOM::Number
object you created.
Example:
if( $num1 * $num2 <= HTML::Object::DOM::Number->MAX_VALUE )
{
func1();
}
else
{
func2();
}
See also Mozilla documentation
MIN_SAFE_INTEGER
This represents the minimum safe integer in JavaScript (-(2^53 - 1)).
Because MIN_SAFE_INTEGER
is a static property of HTML::Object::DOM::Number, you can use it as HTML::Object::DOM::Number-
MIN_SAFE_INTEGER>, rather than as a property of a HTML::Object::DOM::Number
object you created.
Example:
HTML::Object::DOM::Number->MIN_SAFE_INTEGER # -9007199254740991
-(POSIX::pow(2, 53) - 1) # -9007199254740991
See also Mozilla documentation
MIN_VALUE
The smallest positive representable number—that is, the positive number closest to zero (without actually being zero).
Example:
if( $num1 / $num2 >= HTML::Object::DOM::Number->MIN_VALUE )
{
func1();
}
else
{
func2();
}
See also Mozilla documentation
NEGATIVE_INFINITY
Special value representing negative infinity. Returned on overflow.
Example:
my $smallNumber = (-HTML::Object::DOM::Number->MAX_VALUE) * 2;
if( $smallNumber == HTML::Object::DOM::Number->NEGATIVE_INFINITY )
{
$smallNumber = returnFinite();
}
See also Mozilla documentation
NaN
Special "Not a Number" value.
This is actually a value exported by POSIX
Example:
sub sanitise
{
my $x = shift( @_ );
if( isNaN($x) )
{
return( HTML::Object::DOM::Number->NaN );
}
return($x);
}
See also Mozilla documentation
POSITIVE_INFINITY
Special value representing infinity. Returned on overflow.
Example:
my $bigNumber = HTML::Object::DOM::Number->MAX_VALUE * 2;
if( $bigNumber == HTML::Object::DOM::Number->POSITIVE_INFINITY )
{
$bigNumber = returnFinite();
}
See also Mozilla documentation
METHODS
Inherits methods from its parent Module::Generic::Number
isFinite
Determine whether the passed value is a finite number.
Example:
HTML::Object::DOM::Number->isFinite($value)
HTML::Object::DOM::Number->isFinite(Infinity); # false
HTML::Object::DOM::Number->isFinite(NaN); # false
HTML::Object::DOM::Number->isFinite(-Infinity); # false
HTML::Object::DOM::Number->isFinite(0); # true
HTML::Object::DOM::Number->isFinite(2e64); # true
HTML::Object::DOM::Number->isFinite('0'); # false, would've been true with
# global isFinite('0')
HTML::Object::DOM::Number->isFinite(undef); # false, would've been true with
# global isFinite(undef)
See also Mozilla documentation
isInteger
Determine whether the passed value is an integer.
Example:
HTML::Object::DOM::Number->isInteger(value)
HTML::Object::DOM::Number->isInteger(0); # true
HTML::Object::DOM::Number->isInteger(1); # true
HTML::Object::DOM::Number->isInteger(-100000); # true
HTML::Object::DOM::Number->isInteger(99999999999999999999999); # true
HTML::Object::DOM::Number->isInteger(0.1); # false
HTML::Object::DOM::Number->isInteger(Math->PI); # false
HTML::Object::DOM::Number->isInteger(NaN); # false
HTML::Object::DOM::Number->isInteger(Infinity); # false
HTML::Object::DOM::Number->isInteger(-Infinity); # false
HTML::Object::DOM::Number->isInteger('10'); # false
HTML::Object::DOM::Number->isInteger(true); # false
HTML::Object::DOM::Number->isInteger(false); # false
HTML::Object::DOM::Number->isInteger([1]); # false
HTML::Object::DOM::Number->isInteger(5.0); # true
HTML::Object::DOM::Number->isInteger(5.000000000000001); # false
HTML::Object::DOM::Number->isInteger(5.0000000000000001); # true
See also Mozilla documentation
isNaN
Determine whether the passed value is NaN
.
Example:
HTML::Object::DOM::Number->isNaN(value)
HTML::Object::DOM::Number->isNaN(NaN); # true
HTML::Object::DOM::Number->isNaN(HTML::Object::DOM::Number->NaN); # true
HTML::Object::DOM::Number->isNaN(0 / 0); # true
# e->g. these would have been true with global isNaN()
HTML::Object::DOM::Number->isNaN('NaN'); # false
HTML::Object::DOM::Number->isNaN(undefined); # false
HTML::Object::DOM::Number->isNaN({}); # false
HTML::Object::DOM::Number->isNaN('blabla'); # false
# These all return false
HTML::Object::DOM::Number->isNaN(true);
HTML::Object::DOM::Number->isNaN(undef);
HTML::Object::DOM::Number->isNaN(37);
HTML::Object::DOM::Number->isNaN('37');
HTML::Object::DOM::Number->isNaN('37.37');
HTML::Object::DOM::Number->isNaN('');
HTML::Object::DOM::Number->isNaN(' ');
See also Mozilla documentation
isSafeInteger
Determine whether the passed value is a safe integer (number between -(2^53 - 1) and 2^53 - 1).
Example:
HTML::Object::DOM::Number->isSafeInteger(3); # true
HTML::Object::DOM::Number->isSafeInteger(POSIX::pow(2, 53)); # false
HTML::Object::DOM::Number->isSafeInteger(POSIX::pow(2, 53) - 1); # true
HTML::Object::DOM::Number->isSafeInteger(NaN); # false
HTML::Object::DOM::Number->isSafeInteger(Infinity); # false
HTML::Object::DOM::Number->isSafeInteger('3'); # false
HTML::Object::DOM::Number->isSafeInteger(3.1); # false
HTML::Object::DOM::Number->isSafeInteger(3.0); # true
See also Mozilla documentation
parseFloat
Provided with a value and this will return a new HTML::Object::DOM::Number object.
See also Mozilla documentation
parseInt
Provided with a value and this will return a new HTML::Object::DOM::Number object.
See also Mozilla documentation
AUTHOR
Jacques Deguest <jack@deguest.jp>
SEE ALSO
Mozilla documentation, Machine::Epsilon
COPYRIGHT & LICENSE
Copyright(c) 2021 DEGUEST Pte. Ltd.
All rights reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.