diff options
author | pelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4> | 2003-12-09 13:52:50 +0000 |
---|---|---|
committer | pelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4> | 2003-12-09 13:52:50 +0000 |
commit | e97bb114dc859b50ac84a62ee8747f6cde0a98c4 (patch) | |
tree | 56e9936e70bf10ad3d73380c9d839947106bb4ff /tests | |
parent | b0a8072e3f96fb138f35b466d50bcbe2336bbec6 (diff) | |
download | mpfr-e97bb114dc859b50ac84a62ee8747f6cde0a98c4.tar.gz |
+ Add function mpfr_print_mantissa_binary, for debugging reason.
+ Rename MPFR_ALLOC_SIZE in MPFR_MALLOC_SIZE.
+ Add conditionnal -DSMALL directive in mpfr-impl.h.
+ Add new function: sub1sp.
Substraction in case of all the ops have the same prec.
+ Add its test (tsub1sp).
+ Modify a few the tests to avoid comparing mpfr results with double, for portability reason.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2569 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/tabs.c | 4 | ||||
-rw-r--r-- | tests/tadd.c | 4 | ||||
-rw-r--r-- | tests/tconst_log2.c | 2 | ||||
-rw-r--r-- | tests/tdiv_ui.c | 2 | ||||
-rw-r--r-- | tests/tmul.c | 2 | ||||
-rw-r--r-- | tests/tmul_ui.c | 4 | ||||
-rw-r--r-- | tests/tpow.c | 6 | ||||
-rw-r--r-- | tests/tset_d.c | 8 | ||||
-rw-r--r-- | tests/tset_str.c | 4 | ||||
-rw-r--r-- | tests/tsin.c | 2 | ||||
-rw-r--r-- | tests/tsqrt.c | 2 | ||||
-rw-r--r-- | tests/tsub.c | 4 | ||||
-rw-r--r-- | tests/tsub1sp.c | 365 | ||||
-rw-r--r-- | tests/ttan.c | 2 | ||||
-rw-r--r-- | tests/ttrunc.c | 6 | ||||
-rw-r--r-- | tests/tui_pow.c | 6 |
17 files changed, 394 insertions, 31 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index a67f8afd3..03a4800f1 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,6 +1,6 @@ AUTOMAKE_OPTIONS = gnu -check_PROGRAMS = tinits tsgn tcheck tisnan texceptions tset tabs tset_d tset_f tset_q tset_si tset_str tset_z tset_ld tadd tsub tmul tdiv tcmp tcmp2 tcan_round tround_prec tswap reuse tsqrt tnext tcomparisons teq tadd_ui tsub_ui tcmp_ui tdiv_ui tmul_ui tsqrt_ui tui_div tui_sub tcmp_d tmul_2exp tfma tfrac tget_str tout_str tget_d tget_d_2exp tconst_log2 tconst_pi tconst_euler trandom ttrunc trint texp texp2 texpm1 tlog tlog2 tlog10 tlog1p tpow tui_pow tpow3 tcosh tsinh ttanh tacosh tasinh tatanh thyperbolic tasin tacos tcos tatan tsin ttan tsin_cos tagm thypot tfactorial tgamma terf tcbrt mpf_compat mpfr_compat tzeta +check_PROGRAMS = tinits tsgn tcheck tisnan texceptions tset tabs tset_d tset_f tset_q tset_si tset_str tset_z tset_ld tadd tsub tmul tdiv tcmp tcmp2 tcan_round tround_prec tswap reuse tsqrt tnext tcomparisons teq tadd_ui tsub_ui tcmp_ui tdiv_ui tmul_ui tsqrt_ui tui_div tui_sub tcmp_d tmul_2exp tfma tfrac tget_str tout_str tget_d tget_d_2exp tconst_log2 tconst_pi tconst_euler trandom ttrunc trint texp texp2 texpm1 tlog tlog2 tlog10 tlog1p tpow tui_pow tpow3 tcosh tsinh ttanh tacosh tasinh tatanh thyperbolic tasin tacos tcos tatan tsin ttan tsin_cos tagm thypot tfactorial tgamma terf tcbrt mpf_compat mpfr_compat tzeta tsub1sp EXTRA_DIST = tgeneric.c mpf_compat.h diff --git a/tests/tabs.c b/tests/tabs.c index 46d4fcdb4..d26891bd8 100644 --- a/tests/tabs.c +++ b/tests/tabs.c @@ -96,7 +96,7 @@ main (int argc, char *argv[]) mpfr_set_ui(x, 1, GMP_RNDN); mpfr_abs(x, x, GMP_RNDN); - if (mpfr_get_d1 (x) != 1.0) + if (mpfr_cmp_ui (x, 1)) { printf ("Error in mpfr_abs(1.0)\n"); exit (1); @@ -104,7 +104,7 @@ main (int argc, char *argv[]) mpfr_set_si(x, -1, GMP_RNDN); mpfr_abs(x, x, GMP_RNDN); - if (mpfr_get_d1 (x) != 1.0) + if (mpfr_cmp_ui (x, 1)) { printf ("Error in mpfr_abs(-1.0)\n"); exit (1); diff --git a/tests/tadd.c b/tests/tadd.c index 8faf2f62d..c910cc264 100644 --- a/tests/tadd.c +++ b/tests/tadd.c @@ -237,7 +237,7 @@ check64 (void) mpfr_set_str_binary(x, "0.10011010101000110101010000000011001001001110001011101011111011101E623"); mpfr_set_str_binary(t, "0.10011010101000110101010000000011001001001110001011101011111011100E623"); mpfr_sub(u, x, t, GMP_RNDU); - if (mpfr_get_d1 (u) != 9.4349060620538533806e167) + if (mpfr_cmp_ui_2exp(u, 1, 558)) { /* 2^558 */ printf ("Error (1) in mpfr_sub\n"); exit (1); @@ -427,7 +427,7 @@ check_same (void) mpfr_init(x); mpfr_set_ui(x, 1, GMP_RNDZ); mpfr_add(x, x, x, GMP_RNDZ); - if (mpfr_get_d1 (x) != 2.0) + if (mpfr_cmp_ui (x, 2)) { printf ("Error when all 3 operands are equal\n"); exit (1); diff --git a/tests/tconst_log2.c b/tests/tconst_log2.c index 450db9f80..71695d52d 100644 --- a/tests/tconst_log2.c +++ b/tests/tconst_log2.c @@ -88,7 +88,7 @@ main (int argc, char *argv[]) /* check precision of 2 bits */ mpfr_set_prec (x, 2); mpfr_const_log2 (x, GMP_RNDN); - if (mpfr_get_d1 (x) != 0.75) + if (mpfr_cmp_ui_2exp(x, 3, -2)) /* 3*2^-2 */ { printf ("mpfr_const_log2 failed for prec=2, rnd=GMP_RNDN\n" "expected 0.75, got %f\n", mpfr_get_d1 (x)); diff --git a/tests/tdiv_ui.c b/tests/tdiv_ui.c index 8e468bdfa..7796fb388 100644 --- a/tests/tdiv_ui.c +++ b/tests/tdiv_ui.c @@ -103,7 +103,7 @@ special (void) { mpfr_set_prec (y, yprec); mpfr_div_ui (y, x, 1, GMP_RNDN); - if (mpfr_get_d1 (x) != mpfr_get_d1 (y)) + if (mpfr_cmp(x,y)) { printf ("division by 1.0 fails for xprec=%u, yprec=%u\n", xprec, yprec); printf ("expected "); mpfr_print_binary (x); puts (""); diff --git a/tests/tmul.c b/tests/tmul.c index dc6d05392..328326312 100644 --- a/tests/tmul.c +++ b/tests/tmul.c @@ -170,7 +170,7 @@ check_sign (void) mpfr_set_si (a, -1, GMP_RNDN); mpfr_set_ui (b, 2, GMP_RNDN); mpfr_mul(a, b, b, GMP_RNDN); - if (mpfr_get_d1 (a) != 4.0) + if (mpfr_cmp_ui (a, 4) ) { printf ("2.0*2.0 gives %1.20e\n", mpfr_get_d1 (a)); exit (1); diff --git a/tests/tmul_ui.c b/tests/tmul_ui.c index ad54b9af5..f8defca92 100644 --- a/tests/tmul_ui.c +++ b/tests/tmul_ui.c @@ -136,7 +136,7 @@ main (int argc, char *argv[]) mpfr_set_str (x, /*1.0/3.0*/ "0.333333333333333333333333333333333", 10, GMP_RNDZ); mpfr_mul_ui (x, x, 3, GMP_RNDU); - if (mpfr_get_d1 (x) != 1.0) + if (mpfr_cmp_ui (x, 1)) { printf ("Error in mpfr_mul_ui: U(Z(1/3)*3) does not give 1\n"); exit (1); @@ -217,7 +217,7 @@ main (int argc, char *argv[]) { mpfr_set_prec (y, yprec); mpfr_mul_ui (y, x, 1, GMP_RNDN); - if (mpfr_get_d1 (x) != mpfr_get_d1 (y)) + if (mpfr_cmp(x,y)) { printf ("multiplication by 1.0 fails for xprec=%u, yprec=%u\n", xprec, yprec); diff --git a/tests/tpow.c b/tests/tpow.c index 0adb8a4b2..beea9be20 100644 --- a/tests/tpow.c +++ b/tests/tpow.c @@ -165,7 +165,7 @@ special () mpfr_set_str_binary (x, "0.111011000111100000111010000101010100110011010000011"); mpfr_set_str_binary (y, "0.111110010100110000011101100011010111000010000100101"); mpfr_set_str_binary (t, "0.1110110011110110001000110100100001001111010011111000010000011001"); - ; + mpfr_pow (z, x, y, GMP_RNDN); if (mpfr_cmp (z, t)) { @@ -179,7 +179,7 @@ special () mpfr_set_str (x, "5.68824667828621954868e-01", 10, GMP_RNDN); mpfr_set_str (y, "9.03327850535952658895e-01", 10, GMP_RNDN); mpfr_pow (z, x, y, GMP_RNDZ); - if (mpfr_get_d1 (z) != 0.60071044650456473235) + if (mpfr_cmp_d(z, 0.60071044650456473235)) { printf ("Error in mpfr_pow for prec=53, rnd=GMP_RNDZ\n"); exit (1); @@ -365,7 +365,7 @@ main (void) for (p=2; p<100; p++) check_inexact (p); - /* underflows (); */ + /*underflows ();*/ overflows (); diff --git a/tests/tset_d.c b/tests/tset_d.c index 6d90326db..af44a8a6b 100644 --- a/tests/tset_d.c +++ b/tests/tset_d.c @@ -62,20 +62,20 @@ main (int argc, char *argv[]) /* checks that rounds to nearest sets the last bit to zero in case of equal distance */ mpfr_set_d (x, 5.0, GMP_RNDN); - if (mpfr_get_d1 (x) != 4.0) + if (mpfr_cmp_ui (x, 4)) { printf ("Error in tset_d: got %g instead of 4.0\n", mpfr_get_d1 (x)); exit (1); } mpfr_set_d (x, -5.0, GMP_RNDN); - if (mpfr_get_d1 (x) != -4.0) + if (mpfr_cmp_si (x, -4)) { printf ("Error in tset_d: got %g instead of -4.0\n", mpfr_get_d1 (x)); exit (1); } mpfr_set_d (x, 9.84891017624509146344e-01, GMP_RNDU); - if (mpfr_get_d1 (x) != 1.0) + if (mpfr_cmp_ui (x, 1)) { printf ("Error in tset_d: got %g instead of 1.0\n", mpfr_get_d1 (x)); exit (1); @@ -83,7 +83,7 @@ main (int argc, char *argv[]) mpfr_init2(z, 32); mpfr_set_d(z, 1.0, 0); - if (mpfr_get_d1 (z) != 1.0) + if (mpfr_cmp_ui (z, 1)) { mpfr_print_binary (z); puts (""); printf ("Error: 1.0 != 1.0\n"); diff --git a/tests/tset_str.c b/tests/tset_str.c index b9aa25b2b..13f9cfeb7 100644 --- a/tests/tset_str.c +++ b/tests/tset_str.c @@ -120,7 +120,7 @@ main (int argc, char *argv[]) mpfr_set_str_binary (x, "+110101100.01010000101101000000100111001000101011101110E00"); mpfr_set_str_binary (x, "1.0"); - if (mpfr_get_d1 (x) != 1.0) + if (mpfr_cmp_ui (x, 1)) { printf ("Error in mpfr_set_str_binary for s=1.0\n"); mpfr_clear(x); @@ -131,7 +131,7 @@ main (int argc, char *argv[]) mpfr_set_str_binary (x, "+0000"); mpfr_set_str_binary (x, "+0000E0"); mpfr_set_str_binary (x, "0000E0"); - if (mpfr_get_d1 (x) != 0.0) + if (mpfr_cmp_ui (x, 0)) { printf ("Error in mpfr_set_str_binary for s=0.0\n"); mpfr_clear (x); diff --git a/tests/tsin.c b/tests/tsin.c index ba5bc0409..33cd4d938 100644 --- a/tests/tsin.c +++ b/tests/tsin.c @@ -152,7 +152,7 @@ main (int argc, char *argv[]) mpfr_set_str (x, "0.5", 10, GMP_RNDN); mpfr_sin (x, x, GMP_RNDD); - if (mpfr_get_d1 (x) != 0.375) + if (mpfr_cmp_ui_2exp (x, 3, -3)) /* x != 0.375 = 3/8 */ { printf ("mpfr_sin(0.5, GMP_RNDD) failed with precision=2\n"); exit (1); diff --git a/tests/tsqrt.c b/tests/tsqrt.c index 6d319ee2e..c100a37b4 100644 --- a/tests/tsqrt.c +++ b/tests/tsqrt.c @@ -172,7 +172,7 @@ special (void) mpfr_set_ui (z, 1, GMP_RNDN); mpfr_add_one_ulp (z, GMP_RNDN); mpfr_sqrt (x, z, GMP_RNDU); - if (mpfr_get_d1 (x) != 1.5) + if (mpfr_cmp_ui_2exp(x, 3, -1)) { printf ("Error: sqrt(1+ulp(1), up) should give 1.5 (prec=%u)\n", (unsigned int) p); diff --git a/tests/tsub.c b/tests/tsub.c index 1d54f1c23..2126d6cb2 100644 --- a/tests/tsub.c +++ b/tests/tsub.c @@ -161,9 +161,9 @@ check_diverse (void) /* check in-place operations */ mpfr_set_ui (x, 1, GMP_RNDN); mpfr_sub (x, x, x, GMP_RNDN); - if (mpfr_get_d1 (x) != 0.0) + if (mpfr_cmp_ui(x, 0)) { - printf ("Error for mpfr_add (x, x, x, GMP_RNDN) with x=1.0\n"); + printf ("Error for mpfr_sub (x, x, x, GMP_RNDN) with x=1.0\n"); exit (1); } diff --git a/tests/tsub1sp.c b/tests/tsub1sp.c new file mode 100644 index 000000000..66ee6af64 --- /dev/null +++ b/tests/tsub1sp.c @@ -0,0 +1,365 @@ +/* Test file for mpfr_sub1sp. + +Copyright 2003 Free Software Foundation. + +This file is part of the MPFR Library. + +The MPFR Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your +option) any later version. + +The MPFR Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the MPFR Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, +MA 02111-1307, USA. */ + +#include <stdio.h> +#include <stdlib.h> +#include "mpfr-impl.h" +#include "mpfr-test.h" + +void check_special(void); +void check_random(mpfr_prec_t p); + +int main(void) +{ + mpfr_prec_t p; + + tests_start_mpfr (); + + check_special (); + for(p = 2 ; p < 200 ; p++) + check_random (p); + + tests_end_mpfr (); + return 0; +} + +#define STD_ERROR \ + {\ + printf("ERROR: for %s and p=%lu and i=%d:\nY=",\ + mpfr_print_rnd_mode(r), p, i);\ + mpfr_print_binary(y);\ + printf("\nZ="); mpfr_print_binary(z);\ + printf("\nReal: "); mpfr_print_binary(x2);\ + printf("\nGot : "); mpfr_print_binary(x);\ + putchar('\n');\ + abort();\ + } + +#define STD_ERROR2 \ + {\ + printf("ERROR: for %s and p=%lu and i=%d:\nY=",\ + mpfr_print_rnd_mode(r), p, i);\ + mpfr_print_binary(y);\ + printf("\nZ="); mpfr_print_binary(z);\ + printf("\nR="); mpfr_print_binary(x);\ + printf("\nWrong inexact flag. Real: %d. Got: %d", \ + inexact1, inexact2); \ + abort();\ + } + +void check_random(mpfr_prec_t p) +{ + mpfr_t x,y,z,x2; + mp_rnd_t r; + int i, inexact1, inexact2; + gmp_randstate_t state; + + mpfr_inits2(p, x,y,z,x2,NULL); + gmp_randinit_lc_2exp_size (state, 128); + gmp_randseed_ui (state, 17422471); + + for(i = 0 ; i < 1000 ; i++) + { + mpfr_urandomb(y, state); + mpfr_urandomb(z, state); + if (MPFR_IS_PURE_FP(y) && MPFR_IS_PURE_FP(z)) + for(r = 0 ; r < 4 ; r++) + { + inexact1 = mpfr_sub1(x2, y, z, r); + inexact2 = mpfr_sub1sp(x, y, z, r); + if (mpfr_cmp(x, x2)) + STD_ERROR; + if (inexact1 != inexact2) + STD_ERROR2; + } + } + + mpfr_clears(x,y,z,x2,NULL); + gmp_randclear(state); +} + +void check_special(void) +{ + mpfr_t x,y,z,x2; + mp_rnd_t r; + mpfr_prec_t p; + int i = -1, inexact1, inexact2; + + mpfr_inits(x,y,z,x2,NULL); + + for(r = 0 ; r < 4 ; r++) + { + p = 53; + mpfr_set_prec(x, 53); + mpfr_set_prec(x2, 53); + mpfr_set_prec(y, 53); + mpfr_set_prec(z, 53); + + mpfr_set_str_binary (y, + "0.10110111101101110010010010011011000001101101011011001E31"); + + mpfr_sub1sp(x, y, y, r); + if (mpfr_cmp_ui(x, 0)) + { + printf("Error for x-x with p=%lu. Expected 0. Got:", p); + mpfr_print_binary(x); + abort(); + } + + mpfr_set(z, y, r); + mpfr_sub1sp(x, y, z, r); + if (mpfr_cmp_ui(x, 0)) + { + printf("Error for x-y with y=x and p=%lu. Expected 0. Got:", p); + mpfr_print_binary(x); + abort(); + } + /* diff = 0 */ + mpfr_set_str_binary (y, + "0.10110111101101110010010010011011001001101101011011001E31"); + inexact1 = mpfr_sub1(x2, y, z, r); + inexact2 = mpfr_sub1sp(x, y, z, r); + if (mpfr_cmp(x, x2)) + STD_ERROR; + if (inexact1 != inexact2) + STD_ERROR2; + + /* Diff = 1 */ + mpfr_set_str_binary (y, + "0.10110111101101110010010010011011000001101101011011001E30"); + inexact1 = mpfr_sub1(x2, y, z, r); + inexact2 = mpfr_sub1sp(x, y, z, r); + if (mpfr_cmp(x, x2)) + STD_ERROR; + if (inexact1 != inexact2) + STD_ERROR2; + + /* Diff = 2 */ + mpfr_set_str_binary (y, + "0.10110111101101110010010010011011000101101101011011001E32"); + inexact1 = mpfr_sub1(x2, y, z, r); + inexact2 = mpfr_sub1sp(x, y, z, r); + if (mpfr_cmp(x, x2)) + STD_ERROR; + if (inexact1 != inexact2) + STD_ERROR2; + + /* Diff = 32 */ + mpfr_set_str_binary (y, + "0.10110111101101110010010010011011000001101101011011001E63"); + inexact1 = mpfr_sub1(x2, y, z, r); + inexact2 = mpfr_sub1sp(x, y, z, r); + if (mpfr_cmp(x, x2)) + STD_ERROR; + if (inexact1 != inexact2) + STD_ERROR2; + + /* Diff = 52 */ + mpfr_set_str_binary (y, + "0.10110111101101110010010010011011010001101101011011001E83"); + inexact1 = mpfr_sub1(x2, y, z, r); + inexact2 = mpfr_sub1sp(x, y, z, r); + if (mpfr_cmp(x, x2)) + STD_ERROR; + if (inexact1 != inexact2) + STD_ERROR2; + + /* Diff = 53 */ + mpfr_set_str_binary (y, + "0.10110111101101110010010010011111000001101101011011001E31"); + inexact1 = mpfr_sub1(x2, y, z, r); + inexact2 = mpfr_sub1sp(x, y, z, r); + if (mpfr_cmp(x, x2)) + STD_ERROR; + if (inexact1 != inexact2) + STD_ERROR2; + + /* Diff > 200 */ + mpfr_set_str_binary (y, + "0.10110111101101110010010010011011000001101101011011001E331"); + inexact1 = mpfr_sub1(x2, y, z, r); + inexact2 = mpfr_sub1sp(x, y, z, r); + if (mpfr_cmp(x, x2)) + STD_ERROR; + if (inexact1 != inexact2) + STD_ERROR2; + + mpfr_set_str_binary (y, + "0.10000000000000000000000000000000000000000000000000000E31"); + mpfr_set_str_binary (z, + "0.11111111111111111111111111111111111111111111111111111E30"); + inexact1 = mpfr_sub1(x2, y, z, r); + inexact2 = mpfr_sub1sp(x, y, z, r); + if (mpfr_cmp(x, x2)) + STD_ERROR; + if (inexact1 != inexact2) + STD_ERROR2; + + mpfr_set_str_binary (y, + "0.10000000000000000000000000000000000000000000000000000E31"); + mpfr_set_str_binary (z, + "0.11111111111111111111111111111111111111111111111111111E29"); + inexact1 = mpfr_sub1(x2, y, z, r); + inexact2 = mpfr_sub1sp(x, y, z, r); + if (mpfr_cmp(x, x2)) + STD_ERROR; + if (inexact1 != inexact2) + STD_ERROR2; + + mpfr_set_str_binary (y, + "0.10000000000000000000000000000000000000000000000000000E52"); + mpfr_set_str_binary (z, + "0.10000000000010000000000000000000000000000000000000000E00"); + inexact1 = mpfr_sub1(x2, y, z, r); + inexact2 = mpfr_sub1sp(x, y, z, r); + if (mpfr_cmp(x, x2)) + STD_ERROR; + if (inexact1 != inexact2) + STD_ERROR2; + + mpfr_set_str_binary (y, + "0.11100000000000000000000000000000000000000000000000000E53"); + mpfr_set_str_binary (z, + "0.10000000000000000000000000000000000000000000000000000E00"); + inexact1 = mpfr_sub1(x2, y, z, r); + inexact2 = mpfr_sub1sp(z, y, z, r); + mpfr_set(x, z, r); + if (mpfr_cmp(x, x2)) + STD_ERROR; + if (inexact1 != inexact2) + STD_ERROR2; + + mpfr_set_str_binary (y, + "0.10000000000000000000000000000000000000000000000000000E53"); + mpfr_set_str_binary (z, + "0.10100000000000000000000000000000000000000000000000000E00"); + inexact1 = mpfr_sub1(x2, y, z, r); + inexact2 = mpfr_sub1sp(x, y, z, r); + if (mpfr_cmp(x, x2)) + STD_ERROR; + if (inexact1 != inexact2) + STD_ERROR2; + + mpfr_set_str_binary (y, + "0.10000000000000000000000000000000000000000000000000000E54"); + mpfr_set_str_binary (z, + "0.10100000000000000000000000000000000000000000000000000E00"); + inexact1 = mpfr_sub1(x2, y, z, r); + inexact2 = mpfr_sub1sp(x, y, z, r); + if (mpfr_cmp(x, x2)) + STD_ERROR; + if (inexact1 != inexact2) + STD_ERROR2; + + p = 63; + mpfr_set_prec(x, p); + mpfr_set_prec(x2, p); + mpfr_set_prec(y, p); + mpfr_set_prec(z, p); + mpfr_set_str_binary (y, + "0.100000000000000000000000000000000000000000000000000000000000000E62"); + mpfr_set_str_binary (z, + "0.110000000000000000000000000000000000000000000000000000000000000E00"); + inexact1 = mpfr_sub1(x2, y, z, r); + inexact2 = mpfr_sub1sp(x, y, z, r); + if (mpfr_cmp(x, x2)) + STD_ERROR; + if (inexact1 != inexact2) + STD_ERROR2; + + p = 64; + mpfr_set_prec(x, 64); + mpfr_set_prec(x2, 64); + mpfr_set_prec(y, 64); + mpfr_set_prec(z, 64); + + mpfr_set_str_binary (y, + "0.1100000000000000000000000000000000000000000000000000000000000000E31"); + mpfr_set_str_binary (z, + "0.1111111111111111111111111110000000000000000000000000011111111111E29"); + inexact1 = mpfr_sub1(x2, y, z, r); + inexact2 = mpfr_sub1sp(x, y, z, r); + if (mpfr_cmp(x, x2)) + STD_ERROR; + if (inexact1 != inexact2) + STD_ERROR2; + + mpfr_set_str_binary (y, + "0.1000000000000000000000000000000000000000000000000000000000000000E63"); + mpfr_set_str_binary (z, + "0.1011000000000000000000000000000000000000000000000000000000000000E00"); + inexact1 = mpfr_sub1(x2, y, z, r); + inexact2 = mpfr_sub1sp(x, y, z, r); + if (mpfr_cmp(x, x2)) + STD_ERROR; + if (inexact1 != inexact2) + STD_ERROR2; + + mpfr_set_str_binary (y, + "0.1000000000000000000000000000000000000000000000000000000000000000E63"); + mpfr_set_str_binary (z, + "0.1110000000000000000000000000000000000000000000000000000000000000E00"); + inexact1 = mpfr_sub1(x2, y, z, r); + inexact2 = mpfr_sub1sp(x, y, z, r); + if (mpfr_cmp(x, x2)) + STD_ERROR; + if (inexact1 != inexact2) + STD_ERROR2; + + mpfr_set_str_binary (y, + "0.10000000000000000000000000000000000000000000000000000000000000E63"); + mpfr_set_str_binary (z, + "0.10000000000000000000000000000000000000000000000000000000000000E00"); + inexact1 = mpfr_sub1(x2, y, z, r); + inexact2 = mpfr_sub1sp(x, y, z, r); + if (mpfr_cmp(x, x2)) + STD_ERROR; + if (inexact1 != inexact2) + STD_ERROR2; + + mpfr_set_str_binary (y, + "0.1000000000000000000000000000000000000000000000000000000000000000E64"); + mpfr_set_str_binary (z, + "0.1010000000000000000000000000000000000000000000000000000000000000E00"); + inexact1 = mpfr_sub1(x2, y, z, r); + inexact2 = mpfr_sub1sp(x, y, z, r); + if (mpfr_cmp(x, x2)) + STD_ERROR; + if (inexact1 != inexact2) + STD_ERROR2; + + mpfr_set_str_binary (y, + "0.1000000000000000000000000000000000000000000000000000000000000000" + "E-1073741823"); + mpfr_set_str_binary (z, + "0.1010000000000000000000000000000000000000000000000000000000000000" + "E-1073741823"); + inexact1 = mpfr_sub1(x2, y, z, r); + inexact2 = mpfr_sub1sp(x, y, z, r); + if (mpfr_cmp(x, x2)) + STD_ERROR; + if (inexact1 != inexact2) + STD_ERROR2; + + } + + mpfr_clears(x,y,z,x2,NULL); +} diff --git a/tests/ttan.c b/tests/ttan.c index 9b15ea9f6..8f435037a 100644 --- a/tests/ttan.c +++ b/tests/ttan.c @@ -82,7 +82,7 @@ main(int argc, char *argv[]) mpfr_set_prec (x, 2); mpfr_set_str (x, "0.5", 10, GMP_RNDN); mpfr_tan (x, x, GMP_RNDD); - if (mpfr_get_d1 (x) != 0.5) + if (mpfr_cmp_ui_2exp(x, 1, -1)) { printf ("mpfr_tan(0.5, GMP_RNDD) failed\n" "expected 0.5, got %f\n", mpfr_get_d1 (x)); diff --git a/tests/ttrunc.c b/tests/ttrunc.c index 7d5010adc..347f4000c 100644 --- a/tests/ttrunc.c +++ b/tests/ttrunc.c @@ -45,7 +45,7 @@ main (void) mpfr_set_str (x, "0.5", 10, GMP_RNDN); mpfr_ceil(y, x); - if (mpfr_get_d1 (y) != 1.0) + if (mpfr_cmp_ui (y, 1)) { printf ("Error in mpfr_ceil for x=0.5: expected 1.0, got %f\n", mpfr_get_d1 (y)); @@ -54,7 +54,7 @@ main (void) mpfr_set_ui (x, 0, GMP_RNDN); mpfr_ceil(y, x); - if (mpfr_get_d1 (y) != 0.0) + if (mpfr_cmp_ui(y,0)) { printf ("Error in mpfr_ceil for x=0.0: expected 0.0, got %f\n", mpfr_get_d1 (y)); @@ -63,7 +63,7 @@ main (void) mpfr_set_ui (x, 1, GMP_RNDN); mpfr_ceil(y, x); - if (mpfr_get_d1 (y) != 1.0) + if (mpfr_cmp_ui(y,1)) { printf ("Error in mpfr_ceil for x=1.0: expected 1.0, got %f\n", mpfr_get_d1 (y)); diff --git a/tests/tui_pow.c b/tests/tui_pow.c index cc9af8fef..d072c2810 100644 --- a/tests/tui_pow.c +++ b/tests/tui_pow.c @@ -182,7 +182,7 @@ main (int argc, char *argv[]) mpfr_set_prec (y, 2); mpfr_set_str (x, "-0.5", 10, GMP_RNDZ); mpfr_ui_pow (y, 4, x, GMP_RNDD); - if (mpfr_get_d1 (y) != 0.5) + if (mpfr_cmp_ui_2exp(y, 1, -1)) { fprintf (stderr, "Error for 4^(-0.5), prec=2, GMP_RNDD\n"); fprintf (stderr, "expected 0.5, got "); @@ -197,7 +197,7 @@ main (int argc, char *argv[]) mpfr_set_prec (y, 2); mpfr_set_str (x, "0.5", 10, GMP_RNDN); mpfr_ui_pow (y, 398441521, x, GMP_RNDN); - if (mpfr_get_d1 (y) != 16384.0) + if (mpfr_cmp_ui_2exp(y, 1, 14)) { fprintf (stderr, "Error for 398441521^(0.5), prec=2, GMP_RNDN\n"); fprintf (stderr, "expected 1.0e14, got "); @@ -211,8 +211,6 @@ main (int argc, char *argv[]) mpfr_set_prec (x, 2); mpfr_set_str (x, "0.5", 10, GMP_RNDN); - /* mpfr_set_ui (x, 1, GMP_RNDN); - mpfr_div_2exp (x, x, 1, GMP_RNDN); /* x = 1/2 */ check1 (x, 2, 398441521, GMP_RNDN); /* 398441521 = 19961^2 */ /* generic test */ |