perl

 view release on metacpan or  search on metacpan

Configure  view on Meta::CPAN

#define DOUBLESIZE $doublesize
#$d_longdbl HAS_LONG_DOUBLE
#ifdef HAS_LONG_DOUBLE
#define LONG_DOUBLESIZE $longdblsize
#define LONG_DOUBLEKIND $longdblkind
#endif
#include <math.h>
#include <string.h>
#include <stdio.h>
/* Note that whether the sign bit is on or off
 * for NaN depends on the CPU/FPU, and possibly
 * can be affected by the build toolchain.
 *
 * For example for older MIPS and HP-PA 2.0 the quiet NaN is:
 * 0x7f, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
 * 0x7f, 0xf4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
 * (respectively) as opposed to the more usual
 * 0x7f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
 *
 * Pre-IEEE-754 floating point format do not even have inf/nan support
 * at all.  They might have a "max" value (DBL_MAX), which may be deadly
 * to even mention, causing immediate SIGFPE or equivalent: this is
 * the case with VAX floating point, for example.
 */

MANIFEST  view on Meta::CPAN

cpan/Math-BigInt/t/bigints.t			See if BigInt.pm works
cpan/Math-BigInt/t/biglog.t			Test the log function
cpan/Math-BigInt/t/bigroot.t			Test the broot function
cpan/Math-BigInt/t/calling-class-methods.t	Test Math::BigInt
cpan/Math-BigInt/t/calling-constant.t
cpan/Math-BigInt/t/calling-instance-methods.t	Test Math::BigInt
cpan/Math-BigInt/t/calling-lib1.t
cpan/Math-BigInt/t/calling-lib2.t
cpan/Math-BigInt/t/config.t			Test Math::BigInt->config()
cpan/Math-BigInt/t/downgrade.t			Test if use Math::BigInt(); under downgrade works
cpan/Math-BigInt/t/inf_nan.t			Special tests for inf and *NaN* handling
cpan/Math-BigInt/t/isa.t			Test for Math::BigInt inheritance
cpan/Math-BigInt/t/Math/BigFloat/Subclass.pm	Empty subclass of BigFloat for test
cpan/Math-BigInt/t/Math/BigInt/BareCalc.pm	Bigint's simulation of Calc
cpan/Math-BigInt/t/Math/BigInt/Lib/Minimal.pm
cpan/Math-BigInt/t/Math/BigInt/Lib/TestUtil.pm	Test Math::BigInt
cpan/Math-BigInt/t/Math/BigInt/Scalar.pm	Pure Perl module to support Math::BigInt
cpan/Math-BigInt/t/Math/BigInt/Subclass.pm	Empty subclass of BigInt for test
cpan/Math-BigInt/t/mbf_ali.t			Tests for BigFloat
cpan/Math-BigInt/t/mbi_ali.t			Tests for BigInt
cpan/Math-BigInt/t/mbi_rand.t			Test Math::BigInt randomly
cpan/Math-BigInt/t/mbimbf.inc			Actual BigInt/BigFloat accuracy, precision and fallback, round_mode tests
cpan/Math-BigInt/t/mbimbf.t			BigInt/BigFloat accuracy, precision and fallback, round_mode
cpan/Math-BigInt/t/nan_cmp.t			overloaded comparison involving *NaN*
cpan/Math-BigInt/t/new_overloaded.t		test overloaded numbers in BigFloat's new()
cpan/Math-BigInt/t/req_mbf0.t			test: require Math::BigFloat; ->bzero();
cpan/Math-BigInt/t/req_mbf1.t			test: require Math::BigFloat; ->bone();
cpan/Math-BigInt/t/req_mbfa.t			test: require Math::BigFloat; ->bnan();
cpan/Math-BigInt/t/req_mbfi.t			test: require Math::BigFloat; ->binf();
cpan/Math-BigInt/t/req_mbfn.t			test: require Math::BigFloat; ->new();
cpan/Math-BigInt/t/req_mbfw.t			require Math::BigFloat; import ( with => );
cpan/Math-BigInt/t/require.t			Test if require Math::BigInt works
cpan/Math-BigInt/t/round.t			Test rounding with non-integer A and P
cpan/Math-BigInt/t/rt-16221.t			Tests for objectify() w/foreign objs

Porting/Glossary  view on Meta::CPAN

	This variable conditionally defines HAS_MUNMAP if munmap() is
	available to unmap a region mapped by mmap().

d_mymalloc (mallocsrc.U):
	This variable conditionally defines MYMALLOC in case other parts
	of the source want to take special action if MYMALLOC is used.
	This may include different sorts of profiling or error detection.

d_nan (d_nan.U):
	This variable conditionally defines HAS_NAN if nan() is
	available to generate NaN.

d_nanosleep (d_nanosleep.U):
	This variable conditionally defines HAS_NANOSLEEP
	if nanosleep() is available to sleep with 1E-9 sec accuracy.

d_ndbm (i_ndbm.U):
	This variable conditionally defines the HAS_NDBM symbol, which
	indicates that both the ndbm.h include file and an appropriate ndbm
	library exist.  Consult the different i_*ndbm variables
	to find out the actual include location.  Sometimes, a system has the

Porting/config_H  view on Meta::CPAN

 *	The returned values are defined in <float.h> and are:
 *
 *	FP_PLUS_NORM	Positive normalized, nonzero
 *	FP_MINUS_NORM	Negative normalized, nonzero
 *	FP_PLUS_DENORM	Positive denormalized, nonzero
 *	FP_MINUS_DENORM	Negative denormalized, nonzero
 *	FP_PLUS_ZERO	+0.0
 *	FP_MINUS_ZERO	-0.0
 *	FP_PLUS_INF	+INF
 *	FP_MINUS_INF	-INF
 *	FP_NANS		Signaling Not a Number (NaNS)
 *	FP_NANQ		Quiet Not a Number (NaNQ)
 */
/*#define HAS_CLASS		/ **/

/* HAS_CLEARENV:
 *	This symbol, if defined, indicates that the clearenv () routine is
 *	available for use.
 */
#define HAS_CLEARENV		/**/

/* HAS_STRUCT_CMSGHDR:

README.vms  view on Meta::CPAN


Prior to 5.8.0, Perl simply accepted the default floating point options of the
C compiler, namely representing doubles with G_FLOAT on Alpha.  Single
precision floating point values are represented in F_FLOAT format when either
D_FLOAT or G_FLOAT is in use for doubles.  Beginning with 5.8.0, Alpha builds
now use IEEE floating point formats by default, which in VMS parlance are S_FLOAT
for singles and T_FLOAT for doubles.  Itanium builds have always used IEEE by
default. The  available non-default options are D_FLOAT or G_FLOAT on Alpha
or Itanium.

The use of IEEE introduces NaN, infinity, and denormalization capabilities not
available with D_FLOAT and G_FLOAT.  When using one of those non-IEEE formats,
silent underflow and overflow are emulated in the conversion of strings to
numbers, but it is preferable to get the real thing by using IEEE where possible.
You are likely to see quite a few test failures when not using IEEE floating point.

Regardless of what floating point format you consider preferable, be aware
that the choice may have an impact on compatibility with external libraries,
such as database interfaces, and with existing data, such as data created with
the C<pack> function and written to disk, or data stored via the Storable
extension.  For example, a C<pack("d", $foo)")> will create a D_FLOAT,

charclass_invlists.h  view on Meta::CPAN

	"600000",
	"700000",
	"800000",
	"900000",
	"1000000",
	"10000000",
	"20000000",
	"100000000",
	"10000000000",
	"1000000000000",
	"NaN",
	"nan",
	NULL
};

static const char * const UNI_sb_values[] = {
	"AT",
	"at",
	"ATerm",
	"aterm",
	"CL",

config_h.SH  view on Meta::CPAN

 *	The returned values are defined in <float.h> and are:
 *
 *	FP_PLUS_NORM	Positive normalized, nonzero
 *	FP_MINUS_NORM	Negative normalized, nonzero
 *	FP_PLUS_DENORM	Positive denormalized, nonzero
 *	FP_MINUS_DENORM	Negative denormalized, nonzero
 *	FP_PLUS_ZERO	+0.0
 *	FP_MINUS_ZERO	-0.0
 *	FP_PLUS_INF	+INF
 *	FP_MINUS_INF	-INF
 *	FP_NANS		Signaling Not a Number (NaNS)
 *	FP_NANQ		Quiet Not a Number (NaNQ)
 */
#$d_class HAS_CLASS		/**/

/* HAS_CLEARENV:
 *	This symbol, if defined, indicates that the clearenv () routine is
 *	available for use.
 */
#$d_clearenv HAS_CLEARENV		/**/

/* HAS_STRUCT_CMSGHDR:

cpan/JSON-PP/lib/JSON/PP.pm  view on Meta::CPAN

results in a different JSON text from the one JSON::XS encodes (and
thus may break tests that compare entire JSON texts). If you do
need the previous behavior for compatibility or for finer control,
set PERL_JSON_PP_USE_B environmental variable to true before you
C<use> JSON::PP (or JSON.pm).

Note that numerical precision has the same meaning as under Perl (so
binary to decimal conversion follows the same rules as in Perl, which
can differ to other languages). Also, your perl interpreter might expose
extensions to the floating point numbers of your platform, such as
infinities or NaN's - these cannot be represented in JSON, and it is an
error to pass those in.

JSON::PP (and JSON::XS) trusts what you pass to C<encode> method
(or C<encode_json> function) is a clean, validated data structure with
values that can be represented as valid JSON values only, because it's
not from an external data source (as opposed to JSON texts you pass to
C<decode> or C<decode_json>, which JSON::PP considers tainted and
doesn't trust). As JSON::PP doesn't know exactly what you and consumers
of your JSON texts want the unexpected values to be (you may want to
convert them into null, or to stringify them with or without
normalisation (string representation of infinities/NaN may vary
depending on platforms), or to croak without conversion), you're advised
to do what you and your consumers need before you encode, and also not
to numify values that may start with values that look like a number
(including infinities/NaN), without validating.

=back

=head2 OBJECT SERIALISATION

As JSON cannot directly represent Perl objects, you have to choose between
a pure JSON representation (without the ability to deserialise the object
automatically again), and a nonstandard extension to the JSON syntax,
tagged values.

cpan/Math-BigInt-FastCalc/t/biglog.t  view on Meta::CPAN


is($class->new(21)->blog(undef, 71),
   '3.0445224377234229965005979803657054342845752874046106401940844835750742',
   "$class->new(21)->blog(undef, 71)");

###############################################################################

# These tests are now really fast, since they collapse to blog(10), basically
# Don't attempt to run them with older versions. You are warned.

# $x < 0 => NaN
is($class->new(-2)->blog(),    'NaN', "$class->new(-2)->blog()");
is($class->new(-1)->blog(),    'NaN', "$class->new(-1)->blog()");
is($class->new(-10)->blog(),   'NaN', "$class->new(-10)->blog()");
is($class->new(-2, 2)->blog(), 'NaN', "$class->new(-2, 2)->blog()");

my $ten = $class->new(10)->blog();

# 10 is cached (up to 75 digits)
is($class->new(10)->blog(),
   '2.302585092994045684017991454684364207601',
   qq|$class->new(10)->blog()|);

# 0.1 is using the cached value for log(10), too

cpan/Math-BigInt/lib/Math/BigFloat.pm  view on Meta::CPAN

package Math::BigFloat;

#
# Mike grinned. 'Two down, infinity to go' - Mike Nostrus in 'Before and After'
#

# The following hash values are used internally:
# sign  : "+", "-", "+inf", "-inf", or "NaN" if not a number
#   _m  : mantissa ($LIB thingy)
#   _es : sign of _e
#   _e  : exponent ($LIB thingy)
#   _a  : accuracy
#   _p  : precision

use 5.006001;
use strict;
use warnings;

cpan/Math-BigInt/t/Math/BigInt/Scalar.pm  view on Meta::CPAN

require Exporter;

our @ISA = qw(Exporter);

our $VERSION = '0.13';

##############################################################################
# global constants, flags and accessory

# constants for easier life
my $nan = 'NaN';

##############################################################################
# create objects from various representations

sub _new {
    # create scalar ref from string
    my $d = $_[1];
    my $x = $d;                 # make copy
    \$x;
}

cpan/Math-BigInt/t/bigfltpm.inc  view on Meta::CPAN

is($x->{_a}, undef, qq|\$x = $CLASS->new(2); \$x->bnan(); \$x->{_a}|);
is($x->{_p}, undef, qq|\$x = $CLASS->new(2); \$x->bnan(); \$x->{_p}|);

###############################################################################
# bone/binf etc as plain calls (Lite failed them)

is($CLASS->bzero(),      0,      qq|$CLASS->bzero()|);
is($CLASS->bone(),       1,      qq|$CLASS->bone()|);
is($CLASS->bone("+"),    1,      qq|$CLASS->bone("+")|);
is($CLASS->bone("-"),    -1,     qq|$CLASS->bone("-")|);
is($CLASS->bnan(),       "NaN",  qq|$CLASS->bnan()|);
is($CLASS->binf(),       "inf",  qq|$CLASS->binf()|);
is($CLASS->binf("+"),    "inf",  qq|$CLASS->binf("+")|);
is($CLASS->binf("-"),    "-inf", qq|$CLASS->binf("-")|);
is($CLASS->binf("-inf"), "-inf", qq|$CLASS->binf("-inf")|);

$CLASS->accuracy(undef);        # reset
$CLASS->precision(undef);       # reset

###############################################################################
# bsqrt() with set global A/P or A/P enabled on $x, also a test whether bsqrt()

cpan/Math-BigInt/t/bigintpm.inc  view on Meta::CPAN

    } elsif ($f =~ /^(numify|length|stringify)$/) {
        $try .= " \$x->$f();";
    } elsif ($f =~ /^(to|as)_(hex|oct|bin)$/) {
        $try .= " \$x->$f();";
    # overloaded functions
    } elsif ($f =~ /^(log|exp|sin|cos|atan2|int|neg|abs|sqrt)$/) {
        $try .= " \$x = $f(\$x);";
    } elsif ($f eq "parts") {
        $try .= ' ($m, $e) = $x->parts();';
        # ->bstr() to see if an object is returned
        $try .= ' $m = $m->bstr(); $m = "NaN" if !defined $m;';
        $try .= ' $e = $e->bstr(); $e = "NaN" if !defined $e;';
        $try .= ' "$m,$e";';
    } elsif ($f eq "exponent") {
        # ->bstr() to see if an object is returned
        $try .= ' $x = $x->exponent()->bstr();';
    } elsif ($f eq "mantissa") {
        # ->bstr() to see if an object is returned
        $try .= ' $x = $x->mantissa()->bstr();';
    } elsif ($f eq "bpi") {
        $try .= " $CLASS\->bpi(\$x);";
    } else {

cpan/Math-BigInt/t/biglog.t  view on Meta::CPAN


is($class->new(21)->blog(undef, 71),
   '3.0445224377234229965005979803657054342845752874046106401940844835750742',
   "$class->new(21)->blog(undef, 71)");

###############################################################################

# These tests are now really fast, since they collapse to blog(10), basically
# Don't attempt to run them with older versions. You are warned.

# $x < 0 => NaN
is($class->new(-2)->blog(),    'NaN', "$class->new(-2)->blog()");
is($class->new(-1)->blog(),    'NaN', "$class->new(-1)->blog()");
is($class->new(-10)->blog(),   'NaN', "$class->new(-10)->blog()");
is($class->new(-2, 2)->blog(), 'NaN', "$class->new(-2, 2)->blog()");

my $ten = $class->new(10)->blog();

# 10 is cached (up to 75 digits)
is($class->new(10)->blog(),
   '2.302585092994045684017991454684364207601',
   qq|$class->new(10)->blog()|);

# 0.1 is using the cached value for log(10), too

cpan/Math-BigInt/t/calling-class-methods.t  view on Meta::CPAN

&is_nan
abc:1
1:0
&is_inf
inf:1
0:0
&bstr
5:5
10:10
-10:-10
abc:NaN
"+inf":inf
"-inf":-inf
&bsstr
1:1e+0
0:0e+0
2:2e+0
200:2e+2
-5:-5e+0
-100:-1e+2
abc:NaN
"+inf":inf
&babs
-1:1
1:1
#&bnot
#-2:1
#1:-2
&bzero
:0
&bnan
:NaN
abc:NaN
&bone
:1
"+":1
"-":-1
&binf
:inf
"+":inf
"-":-inf

cpan/Math-BigInt/t/calling-instance-methods.t  view on Meta::CPAN

&is_nan
abc:1
1:0
&is_inf
inf:1
0:0
&bstr
5:5
10:10
-10:-10
abc:NaN
"+inf":inf
"-inf":-inf
&bsstr
1:1e+0
0:0e+0
2:2e+0
200:2e+2
-5:-5e+0
-100:-1e+2
abc:NaN
"+inf":inf
&babs
-1:1
1:1
&bnot
-2:1
1:-2
&bzero
:0
&bnan
:NaN
abc:NaN
&bone
:1
#"+":1
#"-":-1
&binf
:inf
#"+":inf
#"-":-inf

cpan/Math-BigInt/t/downgrade.t  view on Meta::CPAN

    is(ref $x, "Math::BigInt", "downgrades to Math::BigInt");
};

$x = Math::BigFloat -> new("Inf");
subtest '$x = Math::BigFloat -> new("inf")' => sub {
    plan tests => 2;
    cmp_ok($x, "==", "Inf", 'value of $x');
    is(ref $x, "Math::BigInt", "downgrades to Math::BigInt");
};

$x = Math::BigFloat -> new("NaN");
subtest '$x = Math::BigFloat -> new("NaN")' => sub {
    plan tests => 2;
    is($x, "NaN", );
    is(ref $x, "Math::BigInt", "downgrades to Math::BigInt");
};

note("testing bzero()");

$x = Math::BigFloat -> bzero();
subtest '$x = Math::BigFloat -> bzero()' => sub {
    plan tests => 2;
    cmp_ok($x, '==', 0, 'value of $x');
    is(ref $x, 'Math::BigInt', 'downgrades to Math::BigInt');

cpan/Math-BigInt/t/mbimbf.inc  view on Meta::CPAN

is($x, 123500, qq|\$x = $mbi->new(123456); \$x->precision(2)|);

###############################################################################
# test actual rounding via round()

$x = $mbf->new("123.456");
is($x->copy()->round(5), "123.46",
   qq|\$x = $mbf->new("123.456"); \$x->copy()->round(5)|);
is($x->copy()->round(4), "123.5",
   qq|\$x = $mbf->new("123.456"); \$x->copy()->round(4)|);
is($x->copy()->round(5, 2), "NaN",
   qq|\$x = $mbf->new("123.456"); \$x->copy()->round(5, 2)|);
is($x->copy()->round(undef, -2), "123.46",
   qq|\$x = $mbf->new("123.456"); \$x->copy()->round(undef, -2)|);
is($x->copy()->round(undef, 2), 120,
   qq|\$x = $mbf->new("123.456"); \$x->copy()->round(undef, 2)|);

$x = $mbi->new("123");
is($x->round(5, 2), "NaN",
   qq|\$x = $mbi->new("123"); \$x->round(5, 2)|);

$x = $mbf->new("123.45000");
is($x->copy()->round(undef, -1, "odd"), "123.5",
   qq|\$x = $mbf->new("123.45000"); \$x->copy()->round(undef, -1, "odd")|);

# see if rounding is 'sticky'
$x = $mbf->new("123.4567");
$y = $x->copy()->bround();              # no-op since nowhere A or P defined

cpan/Math-BigInt/t/nan_cmp.t  view on Meta::CPAN

# -*- mode: perl; -*-

# test that overloaded compare works when NaN are involved

use strict;
use warnings;

use Test::More tests => 26;

use Math::BigInt;
use Math::BigFloat;

compare('Math::BigInt');

cpan/Math-BigInt/t/req_mbfa.t  view on Meta::CPAN

# check that simple requiring Math::BigFloat and then bnan() works

use strict;
use warnings;

use Test::More tests => 1;

require Math::BigFloat;

my $x = Math::BigFloat->bnan(1);
is($x, 'NaN', '$x is NaN');

# all tests done

cpan/Math-BigInt/t/trap.t  view on Meta::CPAN

    eval ("\$x = \$class->new('4711'); \$x->bdiv(0);");
    like($@, qr/^Tried to create/, 'died');
    is($x, 4711, '$x after new() never modified');

    # -$x/0 => -inf
    eval ("\$x = \$class->new('-0815'); \$x->bdiv(0);");
    like($@, qr/^Tried to create/, 'died');
    is($x, '-815', '$x after new not modified');

    $cfg = $class->config( trap_nan => 1 );
    # 0/0 => NaN
    eval ("\$x = \$class->new('0'); \$x->bdiv(0);");
    like($@, qr/^Tried to create/, 'died');
    is($x, '0', '$x after new not modified');
}

##############################################################################
# Math::BigInt

$x = Math::BigInt->new(2);
eval ("\$x = \$mbi->new('0.1');");

cpan/Math-BigInt/t/upgrade.inc  view on Meta::CPAN

        $try .= ' $x->length();';
    } elsif ($f eq "exponent") {
        # ->bstr() to see if an object is returned
        $try .= ' $x = $x->exponent()->bstr();';
    } elsif ($f eq "mantissa") {
        # ->bstr() to see if an object is returned
        $try .= ' $x = $x->mantissa()->bstr();';
    } elsif ($f eq "parts") {
        $try .= ' ($m, $e) = $x->parts();';
        # ->bstr() to see if an object is returned
        $try .= ' $m = $m->bstr(); $m = "NaN" if !defined $m;';
        $try .= ' $e = $e->bstr(); $e = "NaN" if !defined $e;';
        $try .= ' "$m,$e";';
    } else {
        if ($args[1] !~ /\./) {
            $try .= qq| \$y = $CLASS->new("$args[1]");|;
        } else {
            $try .= qq| \$y = $EXPECTED_CLASS->new("$args[1]");|;
        }
        if ($f eq "bcmp") {
            $try .= ' $x->bcmp($y);';
        } elsif ($f eq "bacmp") {

cpan/Math-BigRat/lib/Math/BigRat.pm  view on Meta::CPAN

#
# "Tax the rat farms." - Lord Vetinari
#

# The following hash values are used:
#   sign : +,-,NaN,+inf,-inf
#   _d   : denominator
#   _n   : numerator (value = _n/_d)
#   _a   : accuracy
#   _p   : precision
# You should not look at the innards of a BigRat - use the methods for this.

package Math::BigRat;

use 5.006;
use strict;

cpan/Math-BigRat/t/Math/BigRat/Test.pm  view on Meta::CPAN

    my $y = Math::BigFloat->new($x->bsstr(), undef, undef);
    $class->new($y->ffround($p));
}

sub bstr {
    # calculate a BigFloat compatible string output
    my ($x) = @_;

    $x = $class->new($x) unless ref $x;

    if ($x->{sign} !~ /^[+-]$/) { # inf, NaN etc
        my $s = $x->{sign};
        $s =~ s/^\+//;          # +inf => inf
        return $s;
    }

    my $s = '';
    $s = $x->{sign} if $x->{sign} ne '+'; # +3 vs 3

    #  print " bstr \$x ", $accuracy || $x->{_a} || 'notset', " ", $precision || $x->{_p} || 'notset', "\n";
    return $s.$x->{_n} if $x->{_d}->is_one();

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.871 second using v1.00-cache-2.02-grep-82fe00e-cpan-503542c4f10 )