1 /* Test file for mpfr_expm1.
3 Copyright 2001, 2002, 2003, 2004, 2005, 2006, 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. */
26 #include "mpfr-test.h"
30 test_expm1 (mpfr_ptr a, mpfr_srcptr b, mpfr_rnd_t rnd_mode)
33 int ok = rnd_mode == MPFR_RNDN && mpfr_number_p (b) && mpfr_get_prec (a)>=53;
38 res = mpfr_expm1 (a, b, rnd_mode);
48 #define test_expm1 mpfr_expm1
51 #define TEST_FUNCTION test_expm1
52 #define TEST_RANDOM_EMIN -36
53 #define TEST_RANDOM_EMAX 36
66 test_expm1 (y, x, MPFR_RNDN);
69 printf ("Error for expm1(NaN)\n");
74 test_expm1 (y, x, MPFR_RNDN);
75 if (!mpfr_inf_p (y) || mpfr_sgn (y) < 0)
77 printf ("Error for expm1(+Inf)\n");
82 test_expm1 (y, x, MPFR_RNDN);
83 if (mpfr_cmp_si (y, -1))
85 printf ("Error for expm1(-Inf)\n");
89 mpfr_set_ui (x, 0, MPFR_RNDN);
90 test_expm1 (y, x, MPFR_RNDN);
91 if (mpfr_cmp_ui (y, 0) || mpfr_sgn (y) < 0)
93 printf ("Error for expm1(+0)\n");
97 mpfr_neg (x, x, MPFR_RNDN);
98 test_expm1 (y, x, MPFR_RNDN);
99 if (mpfr_cmp_ui (y, 0) || mpfr_sgn (y) > 0)
101 printf ("Error for expm1(-0)\n");
105 /* Check overflow of expm1(x) */
107 mpfr_set_str_binary (x, "1.1E1000000000");
108 i = test_expm1 (x, x, MPFR_RNDN);
109 MPFR_ASSERTN (MPFR_IS_INF (x) && MPFR_SIGN (x) > 0);
110 MPFR_ASSERTN (mpfr_overflow_p ());
111 MPFR_ASSERTN (i == 1);
114 mpfr_set_str_binary (x, "1.1E1000000000");
115 i = test_expm1 (x, x, MPFR_RNDU);
116 MPFR_ASSERTN (MPFR_IS_INF (x) && MPFR_SIGN (x) > 0);
117 MPFR_ASSERTN (mpfr_overflow_p ());
118 MPFR_ASSERTN (i == 1);
121 mpfr_set_str_binary (x, "1.1E1000000000");
122 i = test_expm1 (x, x, MPFR_RNDD);
123 MPFR_ASSERTN (!MPFR_IS_INF (x) && MPFR_SIGN (x) > 0);
124 MPFR_ASSERTN (mpfr_overflow_p ());
125 MPFR_ASSERTN (i == -1);
127 /* Check internal underflow of expm1 (x) */
128 mpfr_set_prec (x, 2);
130 mpfr_set_str_binary (x, "-1.1E1000000000");
131 i = test_expm1 (x, x, MPFR_RNDN);
132 MPFR_ASSERTN (mpfr_cmp_si (x, -1) == 0);
133 MPFR_ASSERTN (!mpfr_overflow_p () && !mpfr_underflow_p ());
134 MPFR_ASSERTN (i == -1);
136 mpfr_set_str_binary (x, "-1.1E1000000000");
137 i = test_expm1 (x, x, MPFR_RNDD);
138 MPFR_ASSERTN (mpfr_cmp_si (x, -1) == 0);
139 MPFR_ASSERTN (!mpfr_overflow_p () && !mpfr_underflow_p ());
140 MPFR_ASSERTN (i == -1);
142 mpfr_set_str_binary (x, "-1.1E1000000000");
143 i = test_expm1 (x, x, MPFR_RNDZ);
144 MPFR_ASSERTN (mpfr_cmp_str (x, "-0.11", 2, MPFR_RNDN) == 0);
145 MPFR_ASSERTN (!mpfr_overflow_p () && !mpfr_underflow_p ());
146 MPFR_ASSERTN (i == 1);
148 mpfr_set_str_binary (x, "-1.1E1000000000");
149 i = test_expm1 (x, x, MPFR_RNDU);
150 MPFR_ASSERTN (mpfr_cmp_str (x, "-0.11", 2, MPFR_RNDN) == 0);
151 MPFR_ASSERTN (!mpfr_overflow_p () && !mpfr_underflow_p ());
152 MPFR_ASSERTN (i == 1);
159 main (int argc, char *argv[])
165 test_generic (2, 100, 100);
167 data_check ("data/expm1", mpfr_expm1, "mpfr_expm1");
168 bad_cases (mpfr_expm1, mpfr_log1p, "mpfr_expm1", 256, -256, 255,