File: compound.t

package info (click to toggle)
libmath-mpfr-perl 4.45-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,716 kB
  • sloc: perl: 1,508; ansic: 517; makefile: 9
file content (60 lines) | stat: -rwxr-xr-x 2,365 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

# Test script for:
# mpfr_compound_si - new in 4.2.0
# mpfr_compound - new in 4.3.0

use strict;
use warnings;
use Math::MPFR qw(:mpfr);

use Test::More;

my $rop = Math::MPFR->new();

warn "MPFR_VERSION: ", MPFR_VERSION, "\n";
warn "MPFR_VERSION_STRING: ", MPFR_VERSION_STRING, "\n";

if(MPFR_VERSION >= 262656) {
  my $inex = Rmpfr_compound_si($rop, Math::MPFR->new(5), 3, MPFR_RNDN);
  cmp_ok($rop, '==', 216, "Rmpfr_compound_si: 6 ** 3 == 216");

  $inex = Rmpfr_compound_si($rop, Math::MPFR->new(-1.001), 3, MPFR_RNDN);
  cmp_ok(Rmpfr_nan_p($rop), '!=', 0, "Rmpfr_compound_si: -1.001 ** 3 is NaN");

  $inex = Rmpfr_compound_si($rop, Math::MPFR->new(), 0, MPFR_RNDN);
  cmp_ok($rop, '==', 1, "Rmpfr_compound_si: NaN ** 0 is 1");

  $inex = Rmpfr_compound_si($rop, Math::MPFR->new(-1), -1, MPFR_RNDN);
  cmp_ok((Rmpfr_inf_p($rop) && ($rop > 0)), '!=', 0, "Rmpfr_compound_si: -1 ** a negative power is +Inf");

  $inex = Rmpfr_compound_si($rop, Math::MPFR->new(-1), 1, MPFR_RNDN);
  cmp_ok((Rmpfr_zero_p($rop) && !Rmpfr_signbit($rop)), '!=', 0, "Rmpfr_compound_si: -1 ** a positive power is +0");
}
else {
  eval {Rmpfr_compound_si($rop, Math::MPFR->new(5), 0, MPFR_RNDN);};
  like($@, qr/^Rmpfr_compound_si function not implemented/, "Rmpfr_compound_si requires mpfr-4.2.0");
}

if(MPFR_VERSION >= 262912) {

  my $inex = Rmpfr_compound($rop, Math::MPFR->new(5), Math::MPFR->new(3), MPFR_RNDN);
  cmp_ok($rop, '==', 216, "Rmpfr_compound: 6 ** 3 == 216");

  $inex = Rmpfr_compound($rop, Math::MPFR->new(-1.001), Math::MPFR->new(3), MPFR_RNDN);
  cmp_ok(Rmpfr_nan_p($rop), '!=', 0, "Rmpfr_compound: -1.001 ** 3 is NaN");

  $inex = Rmpfr_compound($rop, Math::MPFR->new(), Math::MPFR->new(0), MPFR_RNDN);
  cmp_ok($rop, '==', 1, "Rmpfr_compound: NaN ** 0 is 1");

  $inex = Rmpfr_compound($rop, Math::MPFR->new(-1), Math::MPFR->new(-2.5), MPFR_RNDN);
  cmp_ok((Rmpfr_inf_p($rop) && ($rop > 0)), '!=', 0, "Rmpfr_compound: -1 ** a negative power is +Inf");

  $inex = Rmpfr_compound($rop, Math::MPFR->new(-1), Math::MPFR->new(2.5), MPFR_RNDN);
  cmp_ok((Rmpfr_zero_p($rop) && !Rmpfr_signbit($rop)), '!=', 0, "Rmpfr_compound: -1 ** a positive power is +0");
}
else {
  eval {Rmpfr_compound($rop, Math::MPFR->new(5), Math::MPFR->new(0), MPFR_RNDN);};
  like($@, qr/^Rmpfr_compound function not implemented/, "Rmpfr_compound requires mpfr-4.3.0");
}

done_testing();