1 /* Test file for mpfr_sec.
3 Copyright 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"
28 #define TEST_FUNCTION mpfr_sec
29 #define REDUCE_EMAX 262143 /* otherwise arg. reduction is too expensive */
41 mpfr_sec (y, x, MPFR_RNDN);
44 printf ("Error: sec(NaN) != NaN\n");
49 mpfr_sec (y, x, MPFR_RNDN);
52 printf ("Error: sec(Inf) != NaN\n");
57 mpfr_sec (y, x, MPFR_RNDN);
60 printf ("Error: sec(-Inf) != NaN\n");
65 mpfr_set_ui (x, 0, MPFR_RNDN);
66 mpfr_sec (y, x, MPFR_RNDN);
67 if (mpfr_cmp_ui (y, 1))
69 printf ("Error: sec(+0) != 1\n");
72 mpfr_neg (x, x, MPFR_RNDN);
73 mpfr_sec (y, x, MPFR_RNDN);
74 if (mpfr_cmp_ui (y, 1))
76 printf ("Error: sec(-0) != 1\n");
85 overflowed_sec0 (void)
88 int emax, i, inex, rnd, err = 0;
91 old_emax = mpfr_get_emax ();
96 for (emax = -1; emax <= 0; emax++)
98 mpfr_set_ui_2exp (y, 1, emax, MPFR_RNDN);
100 set_emax (emax); /* 1 is not representable. */
101 for (i = -1; i <= 1; i++)
104 mpfr_set_si_2exp (x, i, -512 * ABS (i), MPFR_RNDN);
106 inex = mpfr_sec (x, x, (mpfr_rnd_t) rnd);
107 if (! mpfr_overflow_p ())
109 printf ("Error in overflowed_sec0 (i = %d, rnd = %s):\n"
110 " The overflow flag is not set.\n",
111 i, mpfr_print_rnd_mode ((mpfr_rnd_t) rnd));
114 if (rnd == MPFR_RNDZ || rnd == MPFR_RNDD)
118 printf ("Error in overflowed_sec0 (i = %d, rnd = %s):\n"
119 " The inexact value must be negative.\n",
120 i, mpfr_print_rnd_mode ((mpfr_rnd_t) rnd));
123 if (! mpfr_equal_p (x, y))
125 printf ("Error in overflowed_sec0 (i = %d, rnd = %s):\n"
126 " Got ", i, mpfr_print_rnd_mode ((mpfr_rnd_t) rnd));
127 mpfr_print_binary (x);
128 printf (" instead of 0.11111111E%d.\n", emax);
136 printf ("Error in overflowed_sec0 (i = %d, rnd = %s):\n"
137 " The inexact value must be positive.\n",
138 i, mpfr_print_rnd_mode ((mpfr_rnd_t) rnd));
141 if (! (mpfr_inf_p (x) && MPFR_SIGN (x) > 0))
143 printf ("Error in overflowed_sec0 (i = %d, rnd = %s):\n"
144 " Got ", i, mpfr_print_rnd_mode ((mpfr_rnd_t) rnd));
145 mpfr_print_binary (x);
146 printf (" instead of +Inf.\n");
161 main (int argc, char *argv[])
167 test_generic (2, 200, 10);