1 /* Test file for mpfr_div_d
3 Copyright 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
4 Contributed by the AriC and Caramel projects, INRIA.
6 This file is part of the GNU MPFR Library.
8 The GNU MPFR Library is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
13 The GNU MPFR Library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16 License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
20 http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
21 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
27 #include "mpfr-test.h"
29 #if MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0)
40 /* nan / 1.0 is nan */
43 inexact = mpfr_div_d (y, x, 1.0, MPFR_RNDN);
44 MPFR_ASSERTN (inexact == 0);
45 MPFR_ASSERTN ((__gmpfr_flags ^ MPFR_FLAGS_NAN) == 0);
46 MPFR_ASSERTN (mpfr_nan_p (y));
48 /* +inf / 1.0 == +inf */
51 inexact = mpfr_div_d (y, x, 1.0, MPFR_RNDN);
52 MPFR_ASSERTN (inexact == 0);
53 MPFR_ASSERTN (__gmpfr_flags == 0);
54 MPFR_ASSERTN (mpfr_inf_p (y));
55 MPFR_ASSERTN (MPFR_IS_POS (y));
57 /* -inf / 1.0 == -inf */
60 inexact = mpfr_div_d (y, x, 1.0, MPFR_RNDN);
61 MPFR_ASSERTN (inexact == 0);
62 MPFR_ASSERTN (__gmpfr_flags == 0);
63 MPFR_ASSERTN (mpfr_inf_p (y));
64 MPFR_ASSERTN (MPFR_IS_NEG (y));
66 /* 0.0 / 0.0 is nan */
67 mpfr_set_ui (x, 0, MPFR_RNDN);
69 inexact = mpfr_div_d (y, x, 0.0, MPFR_RNDN);
70 MPFR_ASSERTN (inexact == 0);
71 MPFR_ASSERTN (__gmpfr_flags == MPFR_FLAGS_NAN);
72 MPFR_ASSERTN (mpfr_nan_p (y));
74 /* 1.0 / 0.0 == +inf */
75 mpfr_set_ui (x, 1, MPFR_RNDN);
77 inexact = mpfr_div_d (y, x, 0.0, MPFR_RNDN);
78 MPFR_ASSERTN (inexact == 0);
79 MPFR_ASSERTN (__gmpfr_flags == MPFR_FLAGS_DIVBY0);
80 MPFR_ASSERTN (mpfr_inf_p (y));
81 MPFR_ASSERTN (MPFR_IS_POS (y));
83 /* -1.0 / 0.0 == -inf */
84 mpfr_set_si (x, -1, MPFR_RNDN);
86 inexact = mpfr_div_d (y, x, 0.0, MPFR_RNDN);
87 MPFR_ASSERTN (inexact == 0);
88 MPFR_ASSERTN (__gmpfr_flags == MPFR_FLAGS_DIVBY0);
89 MPFR_ASSERTN (mpfr_inf_p (y));
90 MPFR_ASSERTN (MPFR_IS_NEG (y));
96 #define TEST_FUNCTION mpfr_sub_d
98 #define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1, RANDS)
110 /* check with enough precision */
111 mpfr_init2 (x, IEEE_DBL_MANT_DIG);
112 mpfr_init2 (y, IEEE_DBL_MANT_DIG);
113 mpfr_init2 (z, IEEE_DBL_MANT_DIG);
115 mpfr_set_str (y, "4096", 10, MPFR_RNDN);
118 inexact = mpfr_div_d (x, y, d, MPFR_RNDN);
121 printf ("Inexact flag error in mpfr_div_d\n");
124 mpfr_set_str (z, "32768", 10, MPFR_RNDN);
127 printf ("Error in mpfr_div_d (");
128 mpfr_out_str (stdout, 10, 0, y, MPFR_RNDN);
129 printf (" + %.20g)\nexpected ", d);
130 mpfr_out_str (stdout, 10, 0, z, MPFR_RNDN);
132 mpfr_out_str (stdout, 10, 0, x, MPFR_RNDN);
136 mpfr_clears (x, y, z, (mpfr_ptr) 0);
140 test_generic (2, 1000, 100);
151 printf ("Warning! Test disabled for this MPFR version.\n");