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/bitwise-mbr.t			Math-BigInt
cpan/Math-BigInt/t/calling-class-methods.t		Test Math::BigInt
cpan/Math-BigInt/t/calling-constant.t			Test file related to Math::BigInt
cpan/Math-BigInt/t/calling-instance-methods.t		Test Math::BigInt
cpan/Math-BigInt/t/calling-lib1.t			Test file related to Math::BigInt
cpan/Math-BigInt/t/calling-lib2.t			Test file related to Math::BigInt
cpan/Math-BigInt/t/config.t				Test Math::BigInt->config()
cpan/Math-BigInt/t/downgrade-mbi-mbf.t			Math-BigInt
cpan/Math-BigInt/t/downgrade-mbi-mbr.t			Math-BigInt
cpan/Math-BigInt/t/hang-mbr.t				Math-BigInt
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/BareSubclass.pm	Math-BigInt
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		Module related to Math::BigInt
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/Math/BigRat/Subclass.pm		Math-BigInt
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/mbr_ali.t				Math-BigInt
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/round.t				Test rounding with non-integer A and P
cpan/Math-BigInt/t/rt-16221.t				Tests for objectify() w/foreign objs
cpan/Math-BigInt/t/rt121139.t				Math-BigInt
cpan/Math-BigInt/t/sub_ali.t				Tests for aliases in BigInt subclasses
cpan/Math-BigInt/t/sub_mbf.t				Empty subclass test of BigFloat
cpan/Math-BigInt/t/sub_mbi.t				Empty subclass test of BigInt
cpan/Math-BigInt/t/sub_mbr.t				Math-BigInt
cpan/Math-BigInt/t/sub_mif.t				Test A & P with subclasses using mbimbf.inc
cpan/Math-BigInt/t/trap.t				Test whether trap_nan and trap_inf work

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"
#            _m : absolute value of mantissa ($LIB thingy)
#           _es : sign of exponent ("+" or "-")
#            _e : absolute value of exponent ($LIB thingy)
#      accuracy : accuracy (scalar)
#     precision : precision (scalar)

use 5.006001;
use strict;
use warnings;

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

    # multiply in the zeros again
    unshift @$cx, (0) x $zero_elements;
    $cx;                        # return result
}

sub _log_int {
    # calculate integer log of $x to base $base
    # ref to array, ref to array - return ref to array
    my ($c, $x, $base) = @_;

    # X == 0 => NaN
    return if @$x == 1 && $x->[0] == 0;

    # BASE 0 or 1 => NaN
    return if @$base == 1 && $base->[0] < 2;

    # X == 1 => 0 (is exact)
    if (@$x == 1 && $x->[0] == 1) {
        @$x = 0;
        return $x, 1;
    }

    my $cmp = $c->_acmp($x, $base);

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


    return $x;
}

sub _log_int {
    # calculate integer log of $x to base $base
    # calculate integer log of $x to base $base
    # ref to array, ref to array - return ref to array
    my ($class, $x, $base) = @_;

    # X == 0 => NaN
    return if $class -> _is_zero($x);

    $base = $class -> _new(2)     unless defined($base);
    $base = $class -> _new($base) unless ref($base);

    # BASE 0 or 1 => NaN
    return if $class -> _is_zero($base) || $class -> _is_one($base);

    # X == 1 => 0 (is exact)
    if ($class -> _is_one($x)) {
        return $class -> _zero(), 1 if wantarray;
        return $class -> _zero();
    }

    my $cmp = $class -> _acmp($x, $base);

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

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

# The following hash values are used:

#          sign : "+", "-", "+inf", "-inf", or "NaN"
#            _d : denominator
#            _n : numerator (value = _n/_d)
#      accuracy : accuracy
#     precision : precision

# You should not look at the innards of a BigRat - use the methods for this.

package Math::BigRat;

use 5.006;

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

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

###############################################################################
# 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/bigrat.t  view on Meta::CPAN


    $x = $mbr->$method("1e2/1e1");
    is($x, 10, qq|\$x = $mbr->$method("1e2/1e1")|);

    $x = $mbr->$method("1 / 3");
    is($x, "1/3", qq|\$x = $mbr->$method("1 / 3")|);

    $x = $mbr->$method("-1 / 3");
    is($x, "-1/3", qq|\$x = $mbr->$method("-1 / 3")|);

    $x = $mbr->$method("NaN");
    is($x, "NaN", qq|\$x = $mbr->$method("NaN")|);

    $x = $mbr->$method("inf");
    is($x, "inf", qq|\$x = $mbr->$method("inf")|);

    $x = $mbr->$method("-inf");
    is($x, "-inf", qq|\$x = $mbr->$method("-inf")|);

    $x = $mbr->$method("1/");
    is($x, "NaN", qq|\$x = $mbr->$method("1/")|);

    $x = $mbr->$method("0x7e");
    is($x, 126, qq|\$x = $mbr->$method("0x7e")|);

    # input ala "1+1/3" isn"t parsed ok yet
    $x = $mbr->$method("1+1/3");
    is($x, "NaN", qq|\$x = $mbr->$method("1+1/3")|);

    $x = $mbr->$method("1/1.2");
    is($x, "5/6", qq|\$x = $mbr->$method("1/1.2")|);

    $x = $mbr->$method("1.3/1.2");
    is($x, "13/12", qq|\$x = $mbr->$method("1.3/1.2")|);

    $x = $mbr->$method("1.2/1");
    is($x, "6/5", qq|\$x = $mbr->$method("1.2/1")|);

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

1234:-1:1
1234:-2:2
1234:-3:3
1234:-4:4
0:0:0
0:1:0

&bmodinv
# format: number:modulus:result
# bmodinv Data errors
abc:abc:NaN
abc:5:NaN
5:abc:NaN
# bmodinv Expected Results from normal use
1:5:1
3:5:2
3:-5:-3
-2:5:2
8:5033:4404
1234567891:13:6
-1234567891:13:7
324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902
## bmodinv Error cases / useless use of function
inf:5:NaN
5:inf:NaN
-inf:5:NaN
5:-inf:NaN

&as_number
144/7:20
12/1:12
-12/1:-12
-12/3:-4
NaN:NaN
+inf:inf
-inf:-inf

&as_int
144/7:20
12/1:12
-12/1:-12
-12/3:-4
NaN:NaN
+inf:inf
-inf:-inf

&bmodpow
# format: number:exponent:modulus:result
# bmodpow Data errors
abc:abc:abc:NaN
5:abc:abc:NaN
abc:5:abc:NaN
abc:abc:5:NaN
5:5:abc:NaN
5:abc:5:NaN
abc:5:5:NaN
# bmodpow Expected results
0:0:2:1
1:0:2:1
0:0:1:0
8:7:5032:3840
8:-1:5033:4404
8:8:-5:-4
98436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518
# bmodpow Error cases
8:-1:16:NaN
inf:5:13:NaN
5:inf:13:NaN

&bmod
NaN:1:NaN
1:NaN:NaN
1:1:0
2:2:0
12:6:0
7/4:4/14:1/28
7/4:4/16:0
-7/4:4/16:0
-7/4:-4/16:0
7/4:-4/16:0
7/4:4/32:0
-7/4:4/32:0
-7/4:-4/32:0
7/4:-4/32:0
7/4:4/28:1/28
-7/4:4/28:3/28
7/4:-4/28:-3/28
-7/4:-4/28:-1/28

&fsqrt
1:1
0:0
NaN:NaN
+inf:inf
-inf:NaN
144:12
# sqrt(144) / sqrt(4) = 12/2 = 6/1
144/4:6
25/16:5/4
-3:NaN
4/9:2/3
36/49:6/7
49/121:7/11
999966000289/99999820000081:999983/9999991

&flog
NaN:NaN
0:-inf
-2:NaN

&blog
NaN:NaN:NaN
0:NaN:NaN
NaN:0:NaN
NaN:1:NaN
1:NaN:NaN
0:2:-inf
0:-2:NaN
3:-2:NaN

&finf
1:+:inf
2:-:-inf
3:abc:inf

&numify
0:0
+1:1
1234:1234
3/4:0.75
5/2:2.5
3/2:1.5
5/4:1.25

&fnan
abc:NaN
2:NaN
-2:NaN
0:NaN

&fone
2:+:1
-2:-:-1
-2:+:1
2:-:-1
0::1
-2::1
abc::1
2:abc:1

&fsstr
+inf:inf
-inf:-inf
abcfsstr:NaN
1:1
3/1:3
0.1:1/10

&bnorm
1:1
-0:0
bnormNaN:NaN
+inf:inf
-inf:-inf
inf/inf:NaN
5/inf:0
5/-inf:0
inf/5:inf
-inf/5:-inf
inf/-5:-inf
-inf/-5:inf
123:123
-123.4567:-1234567/10000
#1.E3:NaN
.2E-3.:NaN
#1e3e4:NaN
.2E2:20
inf:inf
+inf:inf
-inf:-inf
+InFiNiTy:inf
+-inf:NaN
abc:NaN
   1 a:NaN
1bcd2:NaN
11111b:NaN
+1z:NaN
-1z:NaN
0:0
+0:0
+00:0
+0_0_0:0
000000_0000000_00000:0
-0:0
-0000:0
+1:1
+01:1
+001:1

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-mbi-mbf.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/inf_nan.t  view on Meta::CPAN

# -*- mode: perl; -*-

# test inf/NaN handling all in one place

use strict;
use warnings;
use lib 't';

use Test::More tests => 1044;

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

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/trap.t  view on Meta::CPAN


    ###########################################################################
    # Default values.
    ###########################################################################

    # defaults are okay?
    is($class->config("trap_nan"), 0, 'trap_nan defaults to 0');
    is($class->config("trap_inf"), 0, 'trap_inf defaults to 0');

    ###########################################################################
    # Trap NaN.
    ###########################################################################

    # can set?
    $class->config( trap_nan => 1 );
    is($class->config("trap_nan"), 1, qq|$class->config( trap_nan => 1 );|);

    # can reset?
    $class->config( trap_nan => 0 );
    is($class->config("trap_nan"), 0, qq|$class->config( trap_nan => 0 );|);

    # can set via hash ref?
    $class->config( { trap_nan => 1 } );
    is($class->config("trap_nan"), 1, qq|$class->config( { trap_nan => 1 } );|);

    # 0/0 => NaN
    $x = $class->new("0");
    eval { $x->bdiv(0); };
    like($@, qr/^Tried to /, qq|\$x = $class->new("0"); \$x->bdiv(0);|);

    # new() didn't modify $x
    is($x, 0, qq|\$x = $class->new("0"); \$x->bdiv(0);|);

    # also test that new() still works normally
    eval { $x = $class->new('42'); $x->bnan(); };
    like($@, qr/^Tried to /, 'died');

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

( run in 1.017 second using v1.00-cache-2.02-grep-82fe00e-cpan-20ab987cc5d )