File: author-numify-mbf.t

package info (click to toggle)
libmath-bigint-perl 1.999818-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 9,628 kB
  • sloc: perl: 47,633; pascal: 5,299; makefile: 2
file content (61 lines) | stat: -rwxr-xr-x 1,869 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!perl

BEGIN {
    unless ($ENV{AUTHOR_TESTING}) {
        print "1..0 # SKIP these tests are for testing by the author";
        exit;
    }
}

use strict;
use warnings;

use Test::More tests => 9;

use Math::BigFloat;

use Math::Complex;

my $inf = Math::Complex::Inf();
my $nan = $inf - $inf;

###############################################################################
# Check numify() on finite values.

{
    my $x = Math::BigFloat -> new("0.008");
    my $y = Math::BigFloat -> new(2);
    $x -> bdiv(3, $y);
    cmp_ok($x, "==", "0.0027",
           qq|\$x = Math::BigFloat -> new("0.008");|
         . qq| \$y = Math::BigFloat -> new(2); \$x -> bdiv(3, \$y);|);

    cmp_ok(Math::BigFloat -> new("12345e67") -> numify(), "==", 1.2345e71,
           qq|Math::BigFloat -> new("12345e67") -> numify()|);
}

###############################################################################
# Verify that numify() underflows and overflows when given "extreme" values.

# positive overflow
cmp_ok(Math::BigFloat -> new("1e9999") -> numify(), "==", $inf,
   qq|Math::BigFloat -> new("1e9999") -> numify()|);

# negative overflow
cmp_ok(Math::BigFloat -> new("-1e9999") -> numify(), "==", -$inf,
   qq|Math::BigFloat -> new("-1e9999") -> numify()|);

# positive underflow
cmp_ok(Math::BigFloat -> new("1e-9999") -> numify(), "==", 0,
       qq|Math::BigFloat -> new("1e-9999") -> numify()|);

# negative underflow
cmp_ok(Math::BigFloat -> new("-1e-9999") -> numify(), "==", 0,
       qq|Math::BigFloat -> new("-1e-9999") -> numify()|);

###############################################################################
# Check numify on non-finite objects.

is(Math::BigFloat -> binf("+") -> numify(),  $inf, "numify of +Inf");
is(Math::BigFloat -> binf("-") -> numify(), -$inf, "numify of -Inf");
is(Math::BigFloat -> bnan()    -> numify(),  $nan, "numify of NaN");