1 /* Test file for mpfr_add_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)
38 /* (1) check with enough precision */
39 mpfr_init2 (x, IEEE_DBL_MANT_DIG);
40 mpfr_init2 (y, IEEE_DBL_MANT_DIG);
41 mpfr_init2 (z, IEEE_DBL_MANT_DIG);
43 mpfr_set_str (y, "4096", 10, MPFR_RNDN);
46 inexact = mpfr_add_d (x, y, d, MPFR_RNDN);
49 printf ("Inexact flag error in mpfr_add_d (1)\n");
52 mpfr_set_str (z, "4096.125", 10, MPFR_RNDN);
55 printf ("Error in mpfr_add_d (");
56 mpfr_out_str (stdout, 10, 7, y, MPFR_RNDN);
57 printf (" + %.20g)\nexpected ", d);
58 mpfr_out_str (stdout, 10, 0, z, MPFR_RNDN);
60 mpfr_out_str (stdout, 10, 0, x, MPFR_RNDN);
65 /* (2) check inexact flag */
70 inexact = mpfr_add_d (x, y, d, MPFR_RNDN);
73 printf ("Inexact flag error in mpfr_add_d (2)\n");
76 mpfr_set_str (z, "4096.125", 10, MPFR_RNDN);
79 printf ("Error in mpfr_add_d (");
80 mpfr_out_str (stdout, 10, 0, y, MPFR_RNDN);
81 printf (" + %.20g)\nexpected ", d);
82 mpfr_out_str (stdout, 10, 0, z, MPFR_RNDN);
84 mpfr_out_str (stdout, 10, 0, x, MPFR_RNDN);
89 mpfr_clears (x, y, z, (mpfr_ptr) 0);
95 #if !defined(MPFR_ERRDIVZERO)
102 /* nan + 1.0 is nan */
105 inexact = mpfr_add_d (y, x, 1.0, MPFR_RNDN);
106 MPFR_ASSERTN (inexact == 0);
107 MPFR_ASSERTN ((__gmpfr_flags ^ MPFR_FLAGS_NAN) == 0);
108 MPFR_ASSERTN (mpfr_nan_p (y));
110 /* +inf + 1.0 == +inf */
113 inexact = mpfr_add_d (y, x, 1.0, MPFR_RNDN);
114 MPFR_ASSERTN (inexact == 0);
115 MPFR_ASSERTN (__gmpfr_flags == 0);
116 MPFR_ASSERTN (mpfr_inf_p (y));
117 MPFR_ASSERTN (MPFR_IS_POS (y));
119 /* -inf + 1.0 == -inf */
120 mpfr_set_inf (x, -1);
122 inexact = mpfr_add_d (y, x, 1.0, MPFR_RNDN);
123 MPFR_ASSERTN (inexact == 0);
124 MPFR_ASSERTN (__gmpfr_flags == 0);
125 MPFR_ASSERTN (mpfr_inf_p (y));
126 MPFR_ASSERTN (MPFR_IS_NEG (y));
133 #define TEST_FUNCTION mpfr_add_d
135 #define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1, RANDS)
136 #include "tgeneric.c"
146 test_generic (2, 1000, 100);
157 printf ("Warning! Test disabled for this MPFR version.\n");