File: new_in_4.1.0.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 (187 lines) | stat: -rwxr-xr-x 4,265 bytes parent folder | download | duplicates (4)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187

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

print "1..10\n";

my $have_new = 1;
my ($inex, $p, $ret, $ok);
my $rop = Math::MPFR->new();

if(!defined(MPFR_VERSION) || 262400 > MPFR_VERSION) {$have_new = 0} # mpfr version is pre 4.1.0

my @op1 = (Math::MPFR->new(200), Math::MPFR->new(-3), Math::MPFR->new(1001));
my @op2 = (Math::MPFR->new(5), Math::MPFR->new(30), Math::MPFR->new(90));


eval { $inex = Rmpfr_dot($rop, \@op1, \@op2, scalar(@op2), MPFR_RNDN) };

if($have_new) {
  if($rop == 91000) {print "ok 1\n"}
  else {
    warn "\nExpected 91000\nGot $rop\n";
    print "not ok 1\n";
  }

  if($inex == 0) {print "ok 2\n"}
  else {
    warn "\nExpected inex == 0\nGot inex == $inex\n";
    print "not ok 2\n";
  }

  push(@op1, 1);

  eval{ $inex = Rmpfr_dot($rop, \@op1, \@op2, scalar(@op2) + 1, MPFR_RNDN) };

  if($@ =~ /^2nd last arg to Rmpfr_dot is too large/) {print "ok 3\n"}
  else {
    warn "\n \$\@:\n$@\n";
    print "not ok 3\n";
  }
}
else {
  if($@ =~ /^The Rmpfr_dot function requires mpfr\-4\.1\.0/) {print "ok 1\n"}
  else {
    warn "\n\$\@:\n $@\n";
    print "not ok 1\n";
  }

  warn "\n Skipping tests 2 & 3 - we don't have mpfr-4.1.0 or later\n";
  print "ok 2\nok 3\n";
}

# Math::MPFR provides its own implementation of Rmpfr_get_str_ndigits,
# namely Rmpfr_get_str_ndigits_alt, when built against a pre-4.1.0 version
# of the MPFR library.

eval { $p = Rmpfr_get_str_ndigits(63, 100) };

if($@) {
  if($@ =~ /^1st argument given to Rmpfr_get_str_ndigits must be in the range 2\.\.62/) {
    print "ok 4\n";
  }
  else {
    warn "\n\$\@: $@\n";
    print "not ok 4\n";
  }
}

else { print "not ok 4\n" }

$ok = 1;

for my $base(2..62) {
  for my $prec(1 .. 1000) {
    $p = Rmpfr_get_str_ndigits($base, $prec);
    my $expected = Rmpfr_get_str_ndigits_alt($base, $prec);;

    if($expected != $p) {
      warn "for base $base, prec $prec bits: $expected != $p\n";
      $ok = 0;
    }
  }
}

if($ok) { print "ok 5\n" }
else    { print "not ok 5\n" }

# Math::MPFR provides its own implementation of Rmpfr_total_order_p
# when built against a pre-4.1.0 version of the MPFR library.

$ok = 1;

my $pnan = Math::MPFR->new();              # NaN
my $nnan = Math::MPFR->new();
Rmpfr_setsign($nnan, $pnan, 1, MPFR_RNDN); # -NaN
my $pinf = Math::MPFR->new(1) / 0;         # Inf
my $ninf = Math::MPFR->new();
Rmpfr_setsign($ninf, $pinf, 1, MPFR_RNDN); # -Inf
my $preal = Math::MPFR->new(2);            # 2
my $nreal = Math::MPFR->new(-2);           # -2
my $pzero = Math::MPFR->new(0);            # 0
my $nzero = Math::MPFR->new(-0.0);         # - 0

Rmpfr_clear_erangeflag();

for([$nnan, $ninf],   [$ninf, $nreal], [$nreal, $nzero], [$nzero, $pzero],
    [$pzero, $preal], [$preal, $pinf], [$pinf, $pnan],   [$nnan, $pnan]) {
  my @x = @{$_};
  if(!Rmpfr_total_order_p($x[0], $x[1])) {
    warn "$x[0] is not less than or equal to $x[1]\n";
    $ok = 0;
  }

  if(Rmpfr_total_order_p($x[1], $x[0])) {
    warn "$x[1] <= $x[0]\n";
   $ok = 0;
  }
}

for([$nnan, $nnan], [$pnan, $pnan], [$nzero, $nzero], [$pzero, $pzero]) {
  my @x = @{$_};
  if(!Rmpfr_total_order_p($x[0], $x[1])) {
    warn "$x[0] != $x[1]\n";
    $ok = 0;
  }

  if(!Rmpfr_total_order_p($x[1], $x[0])) {
    warn "$x[1] is not less than or equal to $x[0]\n";
   $ok = 0;
  }
}

  if($ok) { print "ok 6\n" }
  else    { print "not ok 6\n" }

  # Rmpfr_total_order_p() should not set erangeflag
  if(Rmpfr_erangeflag_p) {
    Rmpfr_clear_erangeflag();
    print "not ok 7\n";
  }
  else { print "ok 7\n" }

eval { $ret = Rmpfr_cmpabs_ui($nreal, 1) };

if($have_new) {

  if($ret > 0) { print "ok 8\n" }
  else {
    warn "$ret <= 0\n";
    print "not ok 8\n";
  }

  Rmpfr_clear_erangeflag();

  $ret = Rmpfr_cmpabs_ui($nnan, 1);

  if($ret == 0) { print "ok 9\n" }
  else {
    warn "$ret != 0\n";
    print "not ok 9\n";
  }

  if(Rmpfr_erangeflag_p()) {
    Rmpfr_clear_erangeflag;
    print "ok 10\n";
  }
  else {
    warn "erangeflag not set\n";
    print "not ok 10\n";
  }
}

else {

  if($@ =~ /^The Rmpfr_cmpabs_ui function requires mpfr\-4\.1\.0/) { print "ok 8\n" }
  else {
    warn "\$\@: $@\n";
    print "not ok 8\n";
  }

  warn "\n Skipping tests 9 & 10 - we don't have mpfr-4.1.0 or later\n";
  print "ok 9\n";
  print "ok 10\n";
}