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
|
use warnings;
use strict;
use Math::MPFR qw(:mpfr);
print "1..3\n";
print "# Using Math::MPFR version ", $Math::MPFR::VERSION, "\n";
print "# Using mpfr library version ", MPFR_VERSION_STRING, "\n";
print "# Using gmp library version ", Math::MPFR::gmp_v(), "\n";
my $ok;
my($have_mpz, $have_mpq, $have_gmp) = (0, 0, 0);
eval{require Math::GMPz;};
unless($@) {$have_mpz = 1}
eval{require Math::GMPq;};
unless($@) {$have_mpq = 1}
eval{require Math::GMP;};
unless($@) {$have_gmp = 1}
my($q_zero, $z_zero);
# Rmpfr_div
# Rmpfr_div_d Rmpfr_div_q Rmpfr_div_si Rmpfr_div_ui Rmpfr_div_z
# Rmpfr_si_div Rmpfr_ui_div Rmpfr_d_div
my $unity = Math::MPFR->new(1);
my $rop = Math::MPFR->new();
my $fr_zero = Math::MPFR->new(0);
if($have_gmp) {$z_zero = Math::GMP->new(0)}
if($have_mpz && !$have_gmp) {$z_zero = Math::GMPz->new(0)}
if($have_mpq) {$q_zero = Math::GMPq->new(0)}
if((MPFR_VERSION_MAJOR == 3 && MPFR_VERSION_MINOR >= 1) || MPFR_VERSION_MAJOR > 3) {
unless(Rmpfr_divby0_p()) {$ok .= 'a'}
Rmpfr_set_divby0();
if(Rmpfr_divby0_p()) {$ok .= 'b'}
Rmpfr_clear_divby0();
unless(Rmpfr_divby0_p()) {$ok .= 'c'}
Rmpfr_set_divby0();
if(Rmpfr_divby0_p()) {$ok .= 'd'}
Rmpfr_clear_flags();
unless(Rmpfr_divby0_p()) {$ok .= 'e'}
if($ok eq 'abcde') {print "ok 1\n"}
else {
warn "1: \$ok: $ok\n";
print "not ok 1\n";
}
$ok = '';
Rmpfr_div($rop, $unity, $fr_zero, GMP_RNDN);
if(Rmpfr_divby0_p()) {$ok .= 'a'}
Rmpfr_clear_divby0();
unless(Rmpfr_divby0_p()) {$ok .= 'b'}
if($have_gmp || $have_mpz) {
Rmpfr_div_z($rop, $unity, $z_zero, GMP_RNDN);
if(Rmpfr_divby0_p()) {$ok .= 'c'}
Rmpfr_clear_divby0();
unless(Rmpfr_divby0_p()) {$ok .= 'd'}
}
else {
warn "Skipping tests 2c and 2d - no Math::GMP or Math::GMPz\n";
$ok .= 'cd';
}
if($have_mpq) {
Rmpfr_div_q($rop, $unity, $q_zero, GMP_RNDN);
if(Rmpfr_divby0_p()) {$ok .= 'e'}
Rmpfr_clear_divby0();
unless(Rmpfr_divby0_p()) {$ok .= 'f'}
}
else {
warn "Skipping tests 2e and 2f - no Math::GMPq\n";
$ok .= 'ef';
}
Rmpfr_div_ui($rop, $unity, 0, GMP_RNDN);
if(Rmpfr_divby0_p()) {$ok .= 'g'}
Rmpfr_clear_divby0();
unless(Rmpfr_divby0_p()) {$ok .= 'h'}
Rmpfr_div_si($rop, $unity, 0, GMP_RNDN);
if(Rmpfr_divby0_p()) {$ok .= 'i'}
Rmpfr_clear_divby0();
unless(Rmpfr_divby0_p()) {$ok .= 'j'}
Rmpfr_div_d($rop, $unity, 0.0, GMP_RNDN);
if(Rmpfr_divby0_p()) {$ok .= 'k'}
Rmpfr_clear_divby0();
unless(Rmpfr_divby0_p()) {$ok .= 'l'}
Rmpfr_ui_div($rop, 15, $fr_zero, GMP_RNDN);
if(Rmpfr_divby0_p()) {$ok .= 'm'}
Rmpfr_clear_divby0();
unless(Rmpfr_divby0_p()) {$ok .= 'n'}
Rmpfr_si_div($rop, -23, $fr_zero, GMP_RNDN);
if(Rmpfr_divby0_p()) {$ok .= 'o'}
Rmpfr_clear_divby0();
unless(Rmpfr_divby0_p()) {$ok .= 'p'}
Rmpfr_d_div($rop, 12.34, $fr_zero, GMP_RNDN);
if(Rmpfr_divby0_p()) {$ok .= 'q'}
Rmpfr_clear_divby0();
unless(Rmpfr_divby0_p()) {$ok .= 'r'}
if($ok eq 'abcdefghijklmnopqr') {print "ok 2\n"}
else {
warn "2: \$ok: $ok\n";
print "not ok 2\n";
}
$ok = '';
$rop = $unity / $fr_zero;
if(Rmpfr_divby0_p()) {$ok .= 'a'}
Rmpfr_clear_divby0();
unless(Rmpfr_divby0_p()) {$ok .= 'b'}
$rop = $unity / 0;
if(Rmpfr_divby0_p()) {$ok .= 'c'}
Rmpfr_clear_divby0();
unless(Rmpfr_divby0_p()) {$ok .= 'd'}
$rop = $unity / 0.0;
if(Rmpfr_divby0_p()) {$ok .= 'e'}
Rmpfr_clear_divby0();
unless(Rmpfr_divby0_p()) {$ok .= 'f'}
$rop = $unity / '0.0';
if(Rmpfr_divby0_p()) {$ok .= 'g'}
Rmpfr_clear_divby0();
unless(Rmpfr_divby0_p()) {$ok .= 'h'}
$rop = 1 / $fr_zero;
if(Rmpfr_divby0_p()) {$ok .= 'i'}
Rmpfr_clear_divby0();
unless(Rmpfr_divby0_p()) {$ok .= 'j'}
$rop = -1 / $fr_zero;
if(Rmpfr_divby0_p()) {$ok .= 'k'}
Rmpfr_clear_divby0();
unless(Rmpfr_divby0_p()) {$ok .= 'l'}
$rop = 12.34 / $fr_zero;
if(Rmpfr_divby0_p()) {$ok .= 'm'}
Rmpfr_clear_divby0();
unless(Rmpfr_divby0_p()) {$ok .= 'n'}
$rop = '12.34' / $fr_zero;
if(Rmpfr_divby0_p()) {$ok .= 'o'}
Rmpfr_clear_divby0();
unless(Rmpfr_divby0_p()) {$ok .= 'p'}
if($ok eq 'abcdefghijklmnop') {print "ok 3\n"}
else {
warn "3: \$ok: $ok\n";
print "not ok 3\n";
}
}
else {
eval{Rmpfr_set_divby0();};
if($@ =~ /Rmpfr_set_divby0 not implemented/) {print "ok 1\n"}
else {print "not ok 1\n"}
eval{Rmpfr_clear_divby0();};
if($@ =~ /Rmpfr_clear_divby0 not implemented/) {print "ok 2\n"}
else {print "not ok 2\n"}
eval{Rmpfr_divby0_p();};
if($@ =~ /Rmpfr_divby0_p not implemented/) {print "ok 3\n"}
else {print "not ok 3\n"}
}
|