view release on metacpan or search on metacpan
lib/Data/Dmp/Prune.pm view on Meta::CPAN
} elsif (looks_like_number($val) && !$OPT_STRINGIFY_NUMBERS &&
# perl does several normalizations to number literal, e.g.
# "+1" becomes 1, 0123 is octal literal, etc. make sure we
# only leave out quote when the number is not normalized
$val eq $val+0 &&
# perl also doesn't recognize Inf and NaN as numeric
# literals (ref: perldata) so these unquoted literals will
# choke under 'use strict "subs"
$val !~ /\A-?(?:inf(?:inity)?|nan)\z/i
) {
return $val;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/Dump/HTML/Collapsible.pm view on Meta::CPAN
} elsif (looks_like_number($val) && !$OPT_STRINGIFY_NUMBERS &&
# perl does several normalizations to number literal, e.g.
# "+1" becomes 1, 0123 is octal literal, etc. make sure we
# only leave out quote when the number is not normalized
$val eq $val+0 &&
# perl also doesn't recognize Inf and NaN as numeric
# literals (ref: perldata) so these unquoted literals will
# choke under 'use strict "subs"
$val !~ /\A-?(?:inf(?:inity)?|nan)\z/i
) {
return $val;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/Dump/HTML/PopUp.pm view on Meta::CPAN
} elsif (looks_like_number($val) && !$OPT_STRINGIFY_NUMBERS &&
# perl does several normalizations to number literal, e.g.
# "+1" becomes 1, 0123 is octal literal, etc. make sure we
# only leave out quote when the number is not normalized
$val eq $val+0 &&
# perl also doesn't recognize Inf and NaN as numeric
# literals (ref: perldata) so these unquoted literals will
# choke under 'use strict "subs"
$val !~ /\A-?(?:inf(?:inity)?|nan)\z/i
) {
return $val;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/Dump/SExpression.pm view on Meta::CPAN
if ($val == "Inf") {
return "1.0e+INF";
} elsif ($val == "-Inf") {
return "-1.0e+INF";
} elsif ($val =~ /nan/i) {
return "1.0e+NaN";
} else {
return $val;
}
} else {
return _double_quote($val);
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/Dump/ppport.h view on Meta::CPAN
s++; if (s == send || (*s != 'Y' && *s != 'y')) return 0;
s++;
}
sawinf = 1;
} else if (*s == 'N' || *s == 'n') {
/* XXX TODO: There are signaling NaNs and quiet NaNs. */
s++; if (s == send || (*s != 'A' && *s != 'a')) return 0;
s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
s++;
sawnan = 1;
} else
view all matches for this distribution
view release on metacpan or search on metacpan
2021-06-25 Breno G. de Oliveira <garu@cpan.org>
Release 1.24
Strings like "NaN" are still strings
Update maintainer and repository information
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/Dumper/Interp.pm view on Meta::CPAN
"\n Unhandled warn/exception from unary & :$@\n"
if $Debug;
# Unknown problem, treat as a string
return 0;
}
elsif (ref($uand_str_result) ne "" && $uand_str_result =~ /NaN|Inf/) {
# unary & returned an object representing Nan or Inf
# (e.g. Math::BigFloat) so $value must be numberish.
return 1;
}
warn "# ".__PACKAGE__." : (value & \"...\") succeeded\n",
view all matches for this distribution
view release on metacpan or search on metacpan
s++; if (s == send || (*s != 'Y' && *s != 'y')) return 0;
s++;
}
sawinf = 1;
} else if (*s == 'N' || *s == 'n') {
/* XXX TODO: There are signaling NaNs and quiet NaNs. */
s++; if (s == send || (*s != 'A' && *s != 'a')) return 0;
s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
s++;
sawnan = 1;
} else
view all matches for this distribution
view release on metacpan or search on metacpan
s++; if (s == send || (*s != 'Y' && *s != 'y')) return 0;
s++;
}
sawinf = 1;
} else if (*s == 'N' || *s == 'n') {
/* XXX TODO: There are signaling NaNs and quiet NaNs. */
s++; if (s == send || (*s != 'A' && *s != 'a')) return 0;
s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
s++;
sawnan = 1;
} else
view all matches for this distribution
view release on metacpan or search on metacpan
t/lib/Averager.pm view on Meta::CPAN
},
);
sub value {
my $self = shift;
return $self->_count ? sprintf( "%.6g", $self->_sum / $self->_count ) : 'NaN';
}
sub enter {
my ( $self, $event ) = @_;
my $val = $self->value_sub->($event);
view all matches for this distribution
view release on metacpan or search on metacpan
DoubleDouble.pm view on Meta::CPAN
my $hex = NV2H($_[0]);
my $raw = @_ == 2 && $_[1] eq 'raw' ? 1 : 0;
# If the 2nd arg is 'raw' we do the calculations for the arg
# even if it is an Inf/NaN.
unless($raw) {
if($hex eq '7ff00000000000000000000000000000') { # +inf
return ('+', 'inf', 1024);
}
if($hex eq 'fff00000000000000000000000000000') { # -inf
DoubleDouble.pm view on Meta::CPAN
}
##############################
##############################
# Return a hex string representation as per perl Data::Float
# For NaN and Inf returns 'nan' or 'inf' (prefixed with either
# '+' or '-' as appropriate) unless an additional arg of 'raw'
# has been provided - in which case it does the calculations
# and returns the hex string it has calculated.
# This function returns a hex representation of the *actual*
# value - even if that value requires more than 106 bits.
DoubleDouble.pm view on Meta::CPAN
}
##############################
##############################
# Return true iff at least one argument is a NaN.
sub are_nan {
for(@_) {
return 0 if $_ == $_;
DoubleDouble.pm view on Meta::CPAN
@bin = NV2binary($nv);
Another way of arriving at (almost) the same binary representation
of the NV -ie as an array consisting of (sign, mantissa, exponent).
The mantissa if Infs and NaNs will be returned as 'inf' or 'nan'
respectively and the sign associated with the nan will always
be '+'.
With this function, trailing zeroes are stripped from the mantissa
and exponents for 0, inf and nan might not match the other binary
representations.
DoubleDouble.pm view on Meta::CPAN
#############################################
$bool = are_nan(@nv); # Aliased to float_is_nan.
Returns true if and only if all of the (NV) arguments are
NaNs. Else returns false.
#############################################
$hex = dd_bytes($nv);
DoubleDouble.pm view on Meta::CPAN
#############################################
$bool = float_is_nan($nv); # Alias for are_nan()
Returns true if $nv is a NaN.
Else returns false.
#############################################
$bool = float_is_infinite($nv); # Alias for are_inf()
DoubleDouble.pm view on Meta::CPAN
#############################################
$bool = float_is_finite($nv);
Returns true if NV is neither infinite nor a NaN.
Else returns false.
#############################################
$bool = float_is_nzfinite($nv);
Returns true if NV is neither infinite, nor a NaN, nor zero.
Else returns false.
#############################################
$bool = float_is_zero($nv);
DoubleDouble.pm view on Meta::CPAN
equal to $nv1. Infinite values are regarded as being adjacent to
the largest representable finite values. Zero counts as one value,
even if it is signed, and it is adjacent to the positive and
negative smallest representable finite values. If a zero is returned
then it has the same sign as $nv1. Returns
NaN if either argument is a NaN.
#############################################
$nv = nextup($nv1);
DoubleDouble.pm view on Meta::CPAN
the largest representable finite values. Zero counts as one value,
even if it is signed, and it is adjacent to the smallest
representable positive and negative finite values. If a zero is
returned, because $nv1 is the smallest representable negative
value, and zeroes are signed, it is a negative zero that is
returned. Returns NaN if $nv1 is a NaN.
#############################################
$nv = nextdown($nv1);
DoubleDouble.pm view on Meta::CPAN
no such value. Infinite values are regarded as being adjacent to the
largest representable finite values. Zero counts as one value, even
if it is signed, and it is adjacent to the smallest representable
positive and negative finite values. If a zero is returned, because
$nv is the smallest representable positive value, and zeroes are
signed, it is a positive zero that is returned. Returns NaN if VALUE
is a NaN.
#############################################
#############################################
=head1 TODO
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/Float.pm view on Meta::CPAN
Perl does not always generate infinite values when normal floating point
behaviour calls for it. For example, the division C<1.0/0.0> causes an
exception rather than returning an infinity.
=item not-a-number (NaN)
This type of value exists in some floating point formats to indicate
error conditions. Mathematically undefined operations may generate NaNs,
and NaNs propagate through all arithmetic operations. A NaN has the
distinctive property of comparing numerically unequal to all floating
point values, including itself.
Perl does not always generate NaNs when normal floating point behaviour
calls for it. For example, the division C<0.0/0.0> causes an exception
rather than returning a NaN.
Perl has only (at most) one NaN value, even if the underlying system
supports different NaNs. (IEEE 754 arithmetic has NaNs which carry a
quiet/signal bit, a sign bit (yes, a sign on a not-number), and many
bits of implementation-defined data.)
=back
lib/Data/Float.pm view on Meta::CPAN
Truth value indicating whether there are infinite floating point values.
=item have_nan
Truth value indicating whether there are NaN floating point values.
It is difficult to reliably generate a NaN in Perl, so in some unlikely
circumstances it is possible that there might be NaNs that this module
failed to detect. In that case this constant would be false but a NaN
might still turn up somewhere. What this constant reliably indicates
is the availability of the C<nan> constant below.
=back
lib/Data/Float.pm view on Meta::CPAN
The negative infinite value. (Exists only if there are infinite values,
as indicated by the C<have_infinite> constant.)
=item nan
Not-a-number. (Exists only if NaN values were detected, as indicated
by the C<have_nan> constant.)
=back
=cut
lib/Data/Float.pm view on Meta::CPAN
sub float_is_subnormal($) { float_class($_[0]) eq "SUBNORMAL" }
=item float_is_nzfinite(VALUE)
Returns true iff VALUE is a non-zero finite value (either normal or
subnormal; not zero, infinite, or NaN).
=cut
sub float_is_infinite($);
lib/Data/Float.pm view on Meta::CPAN
}
=item float_is_finite(VALUE)
Returns true iff VALUE is a finite value (either normal, subnormal,
or zero; not infinite or NaN).
=cut
sub float_is_finite($) {
my($val) = @_;
lib/Data/Float.pm view on Meta::CPAN
return $val == $pos_infinity || $val == $neg_infinity;
}
=item float_is_nan(VALUE)
Returns true iff VALUE is a NaN.
=cut
sub float_is_nan($) {
my($val) = @_;
lib/Data/Float.pm view on Meta::CPAN
=over
=item float_sign(VALUE)
Returns "B<+>" or "B<->" to indicate the sign of VALUE. An unsigned
zero returns the sign "B<+>". C<die>s if VALUE is a NaN.
=cut
sub signbit($);
sub float_sign($) {
my($val) = @_;
croak "can't get sign of a NaN" if $val != $val;
return signbit($val) ? "-" : "+";
}
=item signbit(VALUE)
VALUE must be a floating point value. Returns the sign bit of VALUE:
0 if VALUE is positive or a positive or unsigned zero, or 1 if VALUE is
negative or a negative zero. Returns an unpredictable value if VALUE
is a NaN.
This is an IEEE 754 standard function. According to the standard NaNs
have a well-behaved sign bit, but Perl can't see that bit.
=cut
sub signbit($) {
lib/Data/Float.pm view on Meta::CPAN
The string that is returned for an infinite magnitude. Default "B<inf>".
=item B<nan_string>
The string that is returned for a NaN value. Default "B<nan>".
=item B<neg_sign>
The string that is prepended to a negative value (including negative
zero). Default "B<->".
lib/Data/Float.pm view on Meta::CPAN
represent then an infinity is returned, or the largest finite value if
there are no infinities.
Additional input formats are accepted for special values.
"[I<s>]B<inf>[B<inity>]" returns an infinity, or C<die>s if there are
no infinities. "[I<s>][B<s>]B<nan>" returns a NaN, or C<die>s if there
are no NaNs available.
All input formats are understood case insensitively. The function
correctly interprets all possible outputs from C<float_hex> with default
settings.
lib/Data/Float.pm view on Meta::CPAN
0, or +1, indicating whether A is to be sorted before, the same as,
or after B.
The ordering is of the identities of floating point values, not their
numerical values. If zeroes are signed, then the two types are considered
to be distinct. NaNs compare equal to each other, but different from
all numeric values. The exact ordering provided is mostly numerical
order: NaNs come first, followed by negative infinity, then negative
finite values, then negative zero, then positive (or unsigned) zero,
then positive finite values, then positive infinity.
In addition to sorting, this function can be useful to check for a zero
of a particular sign.
lib/Data/Float.pm view on Meta::CPAN
This is a comparison function supplying a total ordering of floating point
values. A and B must both be floating point values. Returns a truth value
indicating whether A is to be sorted before-or-the-same-as B. That is,
it is a <= predicate on the total ordering. The ordering is the same as
that provided by C<float_id_cmp>: NaNs come first, followed by negative
infinity, then negative finite values, then negative zero, then positive
(or unsigned) zero, then positive finite values, then positive infinity.
This is an IEEE 754r standard function. According to the standard it
is meant to distinguish different kinds of NaNs, based on their sign
bit, quietness, and payload, but this function (like the rest of Perl)
perceives only one NaN.
=cut
sub totalorder($$) { float_id_cmp($_[0], $_[1]) <= 0 }
lib/Data/Float.pm view on Meta::CPAN
VALUE and SIGN_FROM must both be floating point values. Returns a
floating point value with the magnitude of VALUE and the sign of
SIGN_FROM. If SIGN_FROM is an unsigned zero then it is treated as
positive. If VALUE is an unsigned zero then it is returned unchanged.
If VALUE is a NaN then it is returned unchanged. If SIGN_FROM is a NaN
then the sign copied to VALUE is unpredictable.
This is an IEEE 754 standard function. According to the standard NaNs
have a well-behaved sign bit, which can be read and modified by this
function, but Perl only perceives one NaN and can't see its sign bit,
so behaviour on NaNs is not standard-conforming.
=cut
sub copysign($$) {
my($val, $signfrom) = @_;
lib/Data/Float.pm view on Meta::CPAN
no such value. Infinite values are regarded as being adjacent to the
largest representable finite values. Zero counts as one value, even if
it is signed, and it is adjacent to the smallest representable positive
and negative finite values. If a zero is returned, because VALUE is
the smallest representable negative value, and zeroes are signed, it is
a negative zero that is returned. Returns NaN if VALUE is a NaN.
This is an IEEE 754r standard function.
=cut
lib/Data/Float.pm view on Meta::CPAN
no such value. Infinite values are regarded as being adjacent to the
largest representable finite values. Zero counts as one value, even if
it is signed, and it is adjacent to the smallest representable positive
and negative finite values. If a zero is returned, because VALUE is
the smallest representable positive value, and zeroes are signed, it is
a positive zero that is returned. Returns NaN if VALUE is a NaN.
This is an IEEE 754r standard function.
=cut
lib/Data/Float.pm view on Meta::CPAN
direction of DIRECTION, or returns DIRECTION if it is numerically
equal to VALUE. Infinite values are regarded as being adjacent to
the largest representable finite values. Zero counts as one value,
even if it is signed, and it is adjacent to the positive and negative
smallest representable finite values. If a zero is returned and zeroes
are signed then it has the same sign as VALUE. Returns NaN if either
argument is a NaN.
This is an IEEE 754 standard function.
=cut
lib/Data/Float.pm view on Meta::CPAN
maintains negative and integer zeroes. If a negative zero gets partially
transformed into an integer zero, as described above, the stringification
that it gets is based on its state at the first occasion on which the
scalar was stringified.
NaN handling is generally not well defined in Perl. Arithmetic with
a mathematically undefined result may either C<die> or generate a NaN.
Avoid relying on any particular behaviour for such operations, even if
your hardware's behaviour is known.
As of Perl 5.8.7 the B<%> operator truncates its arguments to integers, if
the divisor is within the range of the native integer type. It therefore
view all matches for this distribution
view release on metacpan or search on metacpan
NEG_INF
NEG_SNAN_FIRST NEG_SNAN_LAST
NEG_IND NEG_QNAN_FIRST NEG_QNAN_LAST
);
my @EXPORT_INFO = qw(isSignMinus isNormal isFinite isZero isSubnormal
isInfinite isNaN isSignaling isSignalingConvertedToQuiet isCanonical
class radix totalOrder totalOrderMag compareFloatingValue compareFloatingMag);
my @EXPORT_SIGNBIT = qw(copy negate abs copySign isSignMinus);
our @EXPORT_OK = (@EXPORT_FLOATING, @EXPORT_RAW754, @EXPORT_ULP, @EXPORT_CONST, @EXPORT_INFO, @EXPORT_SIGNBIT);
our %EXPORT_TAGS = (
The first three nibbles (hexadecimal digits) encode the sign and the exponent. The sign is
the most significant bit of the three nibbles (so AND the first nibble with 8; if it's true,
the number is negative, else it's positive). The remaining 11 bits of the nibbles encode the
exponent: convert the 11bits to decimal, then subtract 1023. If the resulting exponent is -1023,
it indicates a zero or denormal value; if the exponent is +1024, it indicates an infinite (Inf) or
not-a-number (NaN) value, which are generally used to indicate the calculation has grown to large
to fit in an IEEE754 double (Inf) or has tried an performed some other undefined operation (divide
by zero or the logarithm of a zero or negative value) (NaN).
The final thirteen nibbles are the encoding of the fractional value (usually C<1 + thirteennibbles /
16**13>, unless it's zero, denormal, infinite, or not a number).
Of course, this is easier to decode using the L</to_dec_floatingpoint()> function, which interprets
NEG_SNAN_LAST # -0x1.#SNAN00000000p+0000 # negative signaling NAN with "0x7FFFFFFFFFFFF" as the system-dependent information [*]
NEG_IND # -0x1.#IND000000000p+0000 # negative quiet NAN with "0x8000000000000" as the system-dependent information [%]
NEG_QNAN_FIRST # -0x1.#QNAN00000000p+0000 # negative quiet NAN with "0x8000000000001" as the system-dependent information
NEG_QNAN_LAST # -0x1.#QNAN00000000p+0000 # negative quiet NAN with "0xFFFFFFFFFFFFF" as the system-dependent information
[*] note that many perl interpreters will internally convert Signalling NaN (SNAN) to Quiet NaN (QNAN)
[%] some perl interpreters define the zeroeth negative Quiet NaN, NEG_IND, as an "indeterminate" value (IND);
in a symmetrical world, they would also define the zeroeth positive Quiet NaN, POS_IND, as an "indeterminate" value (IND)
=cut
{ my $local; sub POS_ZERO () { $local = hexstr754_to_double('000'.'0000000000000') unless defined $local; return $local; } }
{ my $local; sub POS_DENORM_SMALLEST() { $local = hexstr754_to_double('000'.'0000000000001') unless defined $local; return $local; } }
C<nextUp(I<value>)>; if I<direction> is numerically below I<float>, return C<nextDown(I<value>)>.
=cut
sub nextAfter {
return $_[0] if $_[0] != $_[0]; # return value when value is NaN
return $_[1] if $_[1] != $_[1]; # return direction when direction is NaN
return $_[1] if $_[1] == $_[0]; # return direction when the two are equal
return nextUp($_[0]) if $_[1] > $_[0]; # return nextUp if direction > value
return nextDown($_[0]); # otherwise, return nextDown()
}
information about the floating-point value: most define whether a value is a special condition of
floating-point or not (such as normal, finite, zero, ...).
=head3 isSignMinus( I<value> )
Returns 1 if I<value> has negative sign (even applies to zeroes and NaNs); otherwise, returns 0.
=cut
sub isSignMinus {
# look at leftmost nibble, and determine whether it has the 8-bit or not (which is the sign bit)
return (hex(substr(hexstr754_from_double(shift),0,1)) & 8) >> 3;
}
=head3 isNormal( I<value> )
Returns 1 if I<value> is a normal number (not zero, subnormal, infinite, or NaN); otherwise, returns 0.
=cut
sub isNormal {
# it's normal if the leftmost three nibbles (excluding sign bit) are not 000 or 7FF
return (0 < $exp) && ($exp < 0x7FF) || 0;
}
=head3 isFinite( I<value> )
Returns 1 if I<value> is a finite number (zero, subnormal, or normal; not infinite or NaN); otherwise, returns 0.
=cut
sub isFinite {
# it's finite if the leftmost three nibbles (excluding sign bit) are not 7FF
return ($str eq '0'x15) || 0;
}
=head3 isSubnormal( I<value> )
Returns 1 if I<value> is subnormal (not zero, normal, infinite, nor NaN); otherwise, returns 0.
=cut
sub isSubnormal {
# it's subnormal if it's 0x[80]00___ and the last 13 digits are not all zero
return ($exp eq '000' || $exp eq '800') && ($frc ne '0'x13) || 0;
}
=head3 isInfinite( I<value> )
Returns 1 if I<value> is positive or negative infinity (not zero, subnormal, normal, nor NaN); otherwise, returns 0.
=cut
sub isInfinite {
# it's infinite if it's 0x[F7]FF_0000000000000
my $exp = substr($h,0,3);
my $frc = substr($h,3,13);
return ($exp eq '7FF' || $exp eq 'FFF') && ($frc eq '0'x13) || 0;
}
=head3 isNaN( I<value> )
Returns 1 if I<value> is NaN (not zero, subnormal, normal, nor infinite); otherwise, returns 0.
=cut
sub isNaN {
# it's infinite if it's 0x[F7]FF_0000000000000
my $h = hexstr754_from_double(shift);
my $exp = substr($h,0,3);
my $frc = substr($h,3,13);
return ($exp eq '7FF' || $exp eq 'FFF') && ($frc ne '0'x13) || 0;
}
=head3 isSignaling( I<value> )
Returns 1 if I<value> is a signaling NaN (not zero, subnormal, normal, nor infinite), otherwise, returns 0.
Note that some perl implementations convert some or all signaling NaNs to quiet NaNs, in which case,
C<isSignaling> might return only 0.
=cut
sub isSignaling {
# it's signaling if isNaN and MSB of fractional portion is 1
my $h = hexstr754_from_double(shift);
my $exp = substr($h,0,3);
my $frc = substr($h,3,13);
my $qbit = (0x8 && hex(substr($h,3,1))) >> 3; # 1: quiet, 0: signaling
return ($exp eq '7FF' || $exp eq 'FFF') && ($frc ne '0'x13) && (!$qbit) || 0; # v0.013_007 = possible coverage bug: don't know whether it's the paren or non-paren, but the "LEFT=TRUE" condition of "OR 2 CONDITIONS" is never covered
}
=head4 isSignalingConvertedToQuiet()
Returns 1 if your implementation of perl converts a SignalingNaN to a QuietNaN, otherwise returns 0.
This is I<not> a standard IEEE 754 function; but this is used to determine if the C<isSignaling()>
function is meaningful in your implementation of perl.
=cut
=head3 class( I<value> )
Returns the "class" of the I<value>:
signalingNaN
quietNaN
negativeInfinity
negativeNormal
negativeSubnormal
negativeZero
positiveZero
positiveInfinity
=cut
sub class {
return 'signalingNaN' if isSignaling($_[0]); # v0.013 coverage note: ignore Devel::Cover failures on this line (won't return on systems that quiet SNaNs
return 'quietNaN' if isNaN($_[0]);
return 'negativeInfinity' if isInfinite($_[0]) && isSignMinus($_[0]);
return 'negativeNormal' if isNormal($_[0]) && isSignMinus($_[0]);
return 'negativeSubnormal' if isSubnormal($_[0]) && isSignMinus($_[0]);
return 'negativeZero' if isZero($_[0]) && isSignMinus($_[0]);
return 'positiveZero' if isZero($_[0]) && !isSignMinus($_[0]); # v0.013 coverage note: ignore Devel::Cover->CONDITION failure; alternate condition already returned above
Returns TRUE if I<x> E<le> I<y>, FALSE if I<x> E<gt> I<y>.
Special cases are ordered as below:
-quietNaN < -signalingNaN < -infinity < ...
... < -normal < -subnormal < -zero < ...
... < +zero < +subnormal < +normal < ...
... < +infinity < +signalingNaN < +quietNaN
=cut
sub totalOrder {
my ($x, $y) = @_[0,1];
my ($bx,$by) = map { binstr754_from_double($_) } $x, $y; # convert to binary strings
my @xsegs = ($bx =~ /(.)(.{11})(.{20})(.{32})/); # split into sign, exponent, MSB, LSB
my @ysegs = ($by =~ /(.)(.{11})(.{20})(.{32})/); # split into sign, exponent, MSB, LSB
my ($xin, $yin) = map { isNaN($_) } $x, $y; # determine if NaN: used twice each, so save the values rather than running twice each during if-switch
if( $xin && $yin ) { # BOTH NaN
# use a trick: the rules for both-NaN treat it as if it's just another floating point,
# so lie about the exponent and do a normal comparison
($bx, $by) = map { $_->[1] = '1' . '0'x10; join '', @$_ } \@xsegs, \@ysegs;
($x, $y) = map { binstr754_to_double($_) } $bx, $by;
return (($x <= $y) || 0);
} elsif ( $xin ) { # just x NaN: TRUE if x is NEG
return ( ($xsegs[0]) || 0 );
} elsif ( $yin ) { # just y NaN: TRUE if y is not NEG
return ( (!$ysegs[0]) || 0 );
} elsif ( isZero($x) && isZero($y) ) { # both zero: TRUE if x NEG, or if x==y
# trick = -signbit(x) <= -signbit(y), since signbit is 1 for negative, -signbit = -1 for negative
return ( (-$xsegs[0] <= -$ysegs[0]) || 0 );
} else { # numeric comparison (works for inf, normal, subnormal, or only one +/-zero)
totalOrder( abs(x), abs(y) )
Special cases are ordered as below:
zero < subnormal < normal < infinity < signalingNaN < quietNaN
=cut
sub totalOrderMag {
my ($x, $y) = @_[0,1];
These are similar to C<totalOrder()> and C<totalOrderMag()>, except they return
-1 for C<x E<lt> y>, 0 for C<x == y>, and +1 for C<x E<gt> y>.
These are not in IEEE 754-2008, but are included as functions to replace the perl spaceship
(C<E<lt>=E<gt>>) when comparing floating-point values that might be NaN.
=cut
sub compareFloatingValue {
my ($x, $y) = @_[0,1];
my ($bx,$by) = map { binstr754_from_double($_) } $x, $y; # convert to binary strings
my @xsegs = ($bx =~ /(.)(.{11})(.{20})(.{32})/); # split into sign, exponent, MSB, LSB
my @ysegs = ($by =~ /(.)(.{11})(.{20})(.{32})/); # split into sign, exponent, MSB, LSB
my ($xin, $yin) = map { isNaN($_) } $x, $y; # determine if NaN: used twice each, so save the values rather than running twice each during if-switch
if( $xin && $yin ) { # BOTH NaN
# use a trick: the rules for both-NaN treat it as if it's just another floating point,
# so lie about the exponent and do a normal comparison
($bx, $by) = map { $_->[1] = '1' . '0'x10; join '', @$_ } \@xsegs, \@ysegs;
($x, $y) = map { binstr754_to_double($_) } $bx, $by;
return ($x <=> $y);
} elsif ( $xin ) { # just x NaN: if isNaN(x) && isNegative(x) THEN -1 (x<y) ELSE (x>y)
return ( ($xsegs[0])*-1 || +1 );
} elsif ( $yin ) { # just y NaN: if isNaN(y) && !isNegative(y) THEN -1 (x<y) ELSE (x>y)
return ( (!$ysegs[0])*-1 || +1 );
} elsif ( isZero($x) && isZero($y) ) { # both zero: TRUE if x NEG, or if x==y
# trick = -signbit(x) <=> -signbit(y), since signbit is 1 for negative, -signbit = -1 for negative
return (-$xsegs[0] <=> -$ysegs[0]);
} else { # numeric comparison (works for inf, normal, subnormal, or only one +/-zero)
These functions, from IEEE Std 754-2008, manipulate the sign bits
of the argument(s)set P.
See IEEE Std 754-2008 #5.5.1 "Sign bit operations": This section asserts
that the sign bit operations (including C<negate>, C<abs>, and C<copySign>)
should only affect the sign bit, and should treat numbers and NaNs alike.
=head3 copy( I<value> )
Copies the I<value> to the output, leaving the sign bit unchanged, for all
numbers and NaNs.
=cut
sub copy {
return shift;
=head3 negate( I<value> )
Reverses the sign bit of I<value>. (If the sign bit is set on I<value>,
it will not be set on the output, and vice versa; this will work on
signed zeroes, on infinities, and on NaNs.)
=cut
sub negate {
my $b = binstr754_from_double(shift); # convert to binary string
module-based function to get the absolute value (magnitude) of a 64bit
floating-point number.
The C<CORE::abs()> function behaves properly (per the IEEE 754 description)
for all classes of I<value>, except that many implementations do not correctly
handle -NaN properly, outputting -NaN, which is in violation of the standard.
The C<Data::IEEE754::Tools::abs()> function correctly treats NaNs in the same
way it treats numerical values, and clears the sign bit on the output.
Please note that exporting C<abs()> or C<:signbit> from this module will
"hide" the builtin C<abs()> function. If you really need to use the builtin
version (for example, you care more about execution speed than its ability to find
the absolute value of a signed NaN), then you may call it as C<CORE::abs>.
=cut
sub abs {
my $b = binstr754_from_double(shift); # convert to binary string
=item * L<Perlmonks: Integers sometimes turn into Reals after substraction|http://perlmonks.org/?node_id=1163025> for
inspiring me to go down the IEEE754-expansion trail in perl.
=item * L<Perlmonks: Exploring IEEE754 floating point bit patterns|http://perlmonks.org/?node_id=984141> as a resource
for how perl interacts with the various "edge cases" (+/-infinity, L<denormalized numbers|https://en.wikipedia.org/wiki/Denormal_number>,
signaling and quiet L<NaNs (Not-A-Number)|https://en.wikipedia.org/wiki/NaN>.
=item * L<Data::IEEE754>: I really wanted to use this module, but it didn't get me very far down the "Tools" track,
and included a lot of overhead modules for its install/test that I didn't want to require for B<Data::IEEE754::Tools>.
However, I was inspired by his byteorder-dependent anonymous subs (which were in turn derived from L<Data::MessagePack::PP>);
they were more efficient, on a per-call-to-subroutine basis, than my original inclusion of the if(byteorder) in every call to
view all matches for this distribution
view release on metacpan or search on metacpan
share/js/00-sprintf.min.js view on Meta::CPAN
/*! sprintf-js v1.1.2 | Copyright (c) 2007-present, Alexandru MÄrÄÈteanu <hello@alexei.ro> | BSD-3-Clause */
!function(){"use strict";var g={not_string:/[^s]/,not_bool:/[^t]/,not_type:/[^T]/,not_primitive:/[^v]/,number:/[diefg]/,numeric_arg:/[bcdiefguxX]/,json:/[j]/,not_json:/[^j]/,text:/^[^\x25]+/,modulo:/^\x25{2}/,placeholder:/^\x25(?:([1-9]\d*)\$|\(([^)]...
//# sourceMappingURL=sprintf.min.js.map
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/JSONSchema/Ajv/src.pm view on Meta::CPAN
=cut
__DATA__
/* ajv 6.8.1: Another JSON Schema Validator */
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self...
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/JavaScript/Anon.pm view on Meta::CPAN
@ISA = 'Class::Default';
$errstr = '';
# Attempt to define a single, all encompasing,
# regex for detecting a legal JavaScript number.
# We do not support the exotic values, such as Infinite and NaN.
my $_sci = qr/[eE](?:\+|\-)?\d+/; # The scientific notation exponent ( e.g. 'e+12' )
my $_dec = qr/\.\d+/; # The decimal section ( e.g. '.0212' )
my $_int = qr/(?:[1-9]\d*|0)/; # The integers section ( e.g. '2312' )
my $real = qr/(?:$_int(?:$_dec)?|$_dec)(?:$_sci)?/; # Merge the integer, decimal and scientific parts
my $_hex = qr/0[xX][0-9a-fA-F]+/; # Hexidecimal notation
lib/Data/JavaScript/Anon.pm view on Meta::CPAN
When generating the javascript, numbers will be printed directly and not
quoted. The C<is_a_number> method provides convenient access to the test
that is used to see if something is a number. The test handles just about
everything legal in JavaScript, with the one exception of the exotics, such
as Infinite, -Infinit and NaN.
Returns true is a scalar is numeric, or false otherwise.
You may also access method in using an instantiated object.
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/JavaScript.pm view on Meta::CPAN
for undefined values. You may define your own default--for either version--at
compile time by supplying the default value on the C<use> line:
use Data::JavaScript {JS=>1.1, UNDEF=>'null'};
Other useful values might be C<0>, C<null>, or C<NaN>.
=head1 EXPORT
In addition, althought the module no longer uses Exporter, it heeds its
import conventions; C<qw(:all>), C<()>, etc.
view all matches for this distribution
view release on metacpan or search on metacpan
s++; if (s == send || (*s != 'Y' && *s != 'y')) return 0;
s++;
}
sawinf = 1;
} else if (*s == 'N' || *s == 'n') {
/* XXX TODO: There are signaling NaNs and quiet NaNs. */
s++; if (s == send || (*s != 'A' && *s != 'a')) return 0;
s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
s++;
sawnan = 1;
} else
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/MATFile.pm view on Meta::CPAN
sub double_from_hex { unpack 'd', scalar reverse pack 'H*', $_[0] }
use constant POS_INF => double_from_hex '7FF0000000000000';
use constant NEG_INF => double_from_hex 'FFF0000000000000';
use constant NaN => double_from_hex '7FF8000000000000';
sub parse_double
{
my ($bytes) = @_;
my ($bottom, $top) = unpack ("LL", $bytes);
lib/Data/MATFile.pm view on Meta::CPAN
elsif ($top == 0xfff00000) {
return NEG_INF;
}
}
elsif ($top == 0x7ff00000) {
return NaN;
}
my $sign = $top >> 31;
# print "$sign\n";
my $exponent = (($top >> 20) & 0x7FF) - 1023;
# print "$exponent\n";
view all matches for this distribution
view release on metacpan or search on metacpan
t/test-mails/josey-fold view on Meta::CPAN
On Nov 13, 9:56am in "Re: Defect in XBD lr", Joanna Farley wrote:
> Sun's expert in this area after some discussions with a colleague
> outside of Sun concluded that for lround, to align with both C99 and SUS
> changes of the following form were necessary:
>
> + If x is +/-Inf/NaN, a domain error occurs, and
> + errno is set to EDOM in MATH_ERRNO mode;
> + the invalid exception is raised in MATH_ERREXCEPT mode.
> [to align with C99 Annex F.4]
>
> + If x is too large to be represented as a long, a *range* error
t/test-mails/josey-fold view on Meta::CPAN
>
> Andrew Josey wrote:
> >
> > The text referred to is MX shaded and part of the ISO 60559 floating
> > point option. I do not think changing the Domain Error to a Range Error
> > is the fix or at least not the fix for the NaN and +-Inf cases. ISO C
> > 99 describes the range error case if the magnitude of x is too large as a
> > may fail. I'll ask Fred T for his thoughts on this one...
> > regards
> > Andrew
> >
view all matches for this distribution
view release on metacpan or search on metacpan
msgpack-3.3.0/test/msgpack_basic.cpp view on Meta::CPAN
v.push_back(nanf("tag"));
if (numeric_limits<float>::has_infinity) {
v.push_back(numeric_limits<float>::infinity());
v.push_back(-numeric_limits<float>::infinity());
}
if (numeric_limits<float>::has_quiet_NaN) {
v.push_back(numeric_limits<float>::quiet_NaN());
}
if (numeric_limits<float>::has_signaling_NaN) {
v.push_back(numeric_limits<float>::signaling_NaN());
}
for (unsigned int i = 0; i < kLoop; i++) {
v.push_back(static_cast<float>(msgpack_rand()));
v.push_back(static_cast<float>(-msgpack_rand()));
msgpack-3.3.0/test/msgpack_basic.cpp view on Meta::CPAN
v.push_back(nanf("tag"));
if (numeric_limits<double>::has_infinity) {
v.push_back(numeric_limits<double>::infinity());
v.push_back(-numeric_limits<double>::infinity());
}
if (numeric_limits<double>::has_quiet_NaN) {
v.push_back(numeric_limits<double>::quiet_NaN());
}
if (numeric_limits<double>::has_signaling_NaN) {
v.push_back(numeric_limits<double>::signaling_NaN());
}
for (unsigned int i = 0; i < kLoop; i++) {
v.push_back(msgpack_rand());
v.push_back(-msgpack_rand());
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/Mining/Apriori.pm view on Meta::CPAN
next if(defined $self->{metrics}{minConfidence} && $confidence < $self->{metrics}{minConfidence});
my $lift = ($support/($supportAntecedent*$supportConsequent));
next if(defined $self->{metrics}{minLift} && $lift < $self->{metrics}{minLift});
my $leverage = ($support-($supportAntecedent*$supportConsequent));
next if(defined $self->{metrics}{minLeverage} && $leverage < $self->{metrics}{minLeverage});
my $conviction = ((1-$supportConsequent)==0)?"NaN":((1-$confidence)==0)?"NaN":((1-$supportConsequent)/(1-$confidence));
next if(defined $self->{metrics}{minConviction} && $conviction < $self->{metrics}{minConviction});
my $coverage = $supportAntecedent;
next if(defined $self->{metrics}{minCoverage} && $coverage < $self->{metrics}{minCoverage});
my $correlation = (($support-($supportAntecedent*$supportConsequent))/sqrt($supportAntecedent*(1-$supportAntecedent)*$supportConsequent*(1-$supportConsequent)));
next if(defined $self->{metrics}{minCorrelation} && $correlation < $self->{metrics}{minCorrelation});
lib/Data/Mining/Apriori.pm view on Meta::CPAN
$self->{rule}++;
$support = sprintf("%.$self->{precision}f", $support);
$confidence = sprintf("%.$self->{precision}f", $confidence);
$lift = sprintf("%.$self->{precision}f", $lift);
$leverage = sprintf("%.$self->{precision}f", $leverage);
$conviction = sprintf("%.$self->{precision}f", $conviction)if($conviction ne "NaN");
$coverage = sprintf("%.$self->{precision}f", $coverage);
$correlation = sprintf("%.$self->{precision}f", $correlation);
$cosine = sprintf("%.$self->{precision}f", $cosine);
$laplace = sprintf("%.$self->{precision}f", $laplace);
$jaccard = sprintf("%.$self->{precision}f", $jaccard);
view all matches for this distribution
view release on metacpan or search on metacpan
s++; if (s == send || (*s != 'Y' && *s != 'y')) return 0;
s++;
}
sawinf = 1;
} else if (*s == 'N' || *s == 'n') {
/* XXX TODO: There are signaling NaNs and quiet NaNs. */
s++; if (s == send || (*s != 'A' && *s != 'a')) return 0;
s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
s++;
sawnan = 1;
} else
view all matches for this distribution
view release on metacpan or search on metacpan
s++; if (s == send || (*s != 'Y' && *s != 'y')) return 0;
s++;
}
sawinf = 1;
} else if (*s == 'N' || *s == 'n') {
/* XXX TODO: There are signaling NaNs and quiet NaNs. */
s++; if (s == send || (*s != 'A' && *s != 'a')) return 0;
s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
s++;
sawnan = 1;
} else
view all matches for this distribution
view release on metacpan or search on metacpan
t/004_dump.t view on Meta::CPAN
is(dump(-33), "-33", "-33");
is(dump(-1.5), "-1.5", "-1.5");
is(dump("Inf"), qq("Inf"), qq("Inf"));
is(dump("-Inf"), qq("-Inf"), qq("-Inf"));
is(dump("nan"), qq("nan"), qq("nan"));
is(dump("NaN"), qq("NaN"), qq("NaN"));
is(dump("0123"), qq("0123"), qq("0123"));
is(dump(1..2), "(1, 2)", "(1, 2)");
is(dump(1..3), "(1, 2, 3)", "(1, 2, 3)");
is(dump(1..4), "(1 .. 4)", "(1 .. 4)");
is(dump(1..5,6,8,9), "(1 .. 6, 8, 9)", "(1 .. 6, 8, 9)");
view all matches for this distribution
view release on metacpan or search on metacpan
s++; if (s == send || (*s != 'Y' && *s != 'y')) return 0;
s++;
}
sawinf = 1;
} else if (*s == 'N' || *s == 'n') {
/* XXX TODO: There are signaling NaNs and quiet NaNs. */
s++; if (s == send || (*s != 'A' && *s != 'a')) return 0;
s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
s++;
sawnan = 1;
} else
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/Rlist.pm view on Meta::CPAN
- lexical conventions such as the C<"0b"> (binary), C<"0"> (octal), C<"0x"> (hex) prefix to denote
a number-base other than decimal, and
- Perls' legible numbers, e.g. F<3.14_15_92>,
- the IEEE 754 notations of Infinite and NaN.
See also
$ perldoc -q "whether a scalar is a number"
lib/Data/Rlist.pm view on Meta::CPAN
The C<"threads"> L<compile option|/Compile Options> has not yet been implemented.
=item *
IEEE 754 notations of Infinite and NaN not yet implemented.
=item *
F<L</compile_Perl>> is experimental.
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/Sah/Coerce/js/To_date/From_obj/date.pm view on Meta::CPAN
$res->{expr_match} = join(
" && ",
"($dt instanceof Date)",
);
$res->{expr_coerce} = "isNaN($dt) ? ['Invalid date', $dt] : [null, $dt]";
$res;
}
1;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/Sah/Compiler/human/TH/float.pm view on Meta::CPAN
if ($cd->{cl_is_expr}) {
$c->add_ccl($cd, {});
} else {
$c->add_ccl($cd, {
fmt => $cv ?
q[%(modal_verb)s be a NaN] :
q[%(modal_verb_neg)s be a NaN],
});
}
}
sub clause_is_inf {
view all matches for this distribution