1 /* Test file for mpfr_check.
3 Copyright 2003, 2004, 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"
29 (printf ("mpfr_check failed " s " Prec=%lu\n", (unsigned long) pr), \
42 for(pr = MPFR_PREC_MIN ; pr < 500 ; pr++)
45 if (!mpfr_check(a)) ERROR("for init");
46 /* Check special cases */
48 if (!mpfr_check(a)) ERROR("for nan");
51 if (!mpfr_check(a)) ERROR("for inf");
53 if (!mpfr_check(a)) ERROR("for zero");
55 mpfr_set_ui(a, 2, MPFR_RNDN);
56 if (!mpfr_check(a)) ERROR("for set_ui");
57 mpfr_clear_overflow();
58 max = 1000; /* Allows max 2^1000 bits for the exponent */
59 while ((!mpfr_overflow_p()) && (max>0))
61 mpfr_mul(a, a, a, MPFR_RNDN);
62 if (!mpfr_check(a)) ERROR("for mul");
65 if (max==0) ERROR("can't reach overflow");
66 mpfr_set_ui(a, 2137, MPFR_RNDN);
67 /* Corrupt a and check for it */
69 if (mpfr_check(a)) ERROR("sgn");
73 if (mpfr_check(a)) ERROR("precmin");
74 #if MPFR_VERSION_MAJOR < 3
75 /* Disable the test with MPFR >= 3 since mpfr_prec_t is now signed.
76 The "if" below is sufficient, but the MPFR_PREC_MAX+1 generates
77 a warning with GCC 4.4.4 even though the test is always false. */
78 if ((mpfr_prec_t) 0 - 1 > 0)
80 MPFR_PREC(a) = MPFR_PREC_MAX+1;
81 if (mpfr_check(a)) ERROR("precmax");
85 if (!mpfr_check(a)) ERROR("prec");
87 MPFR_EXP(a) = MPFR_EXP_INVALID;
88 if (mpfr_check(a)) ERROR("exp invalid");
89 MPFR_EXP(a) = -MPFR_EXP_INVALID;
90 if (mpfr_check(a)) ERROR("-exp invalid");
92 if (!mpfr_check(a)) ERROR("exp 0");
96 if (mpfr_check(a)) ERROR("Mantissa Null Ptr");
99 s = MPFR_GET_ALLOC_SIZE(a);
100 MPFR_SET_ALLOC_SIZE(a, 0);
101 if (mpfr_check(a)) ERROR("0 size");
102 MPFR_SET_ALLOC_SIZE(a, MP_SIZE_T_MIN);
103 if (mpfr_check(a)) ERROR("min size");
104 MPFR_SET_ALLOC_SIZE(a, MPFR_LIMB_SIZE(a)-1 );
105 if (mpfr_check(a)) ERROR("size < prec");
106 MPFR_SET_ALLOC_SIZE(a, s);
107 /* Check normal form */
108 tmp = MPFR_MANT(a)[0];
109 if ((pr % GMP_NUMB_BITS) != 0)
111 MPFR_MANT(a)[0] = ~0;
112 if (mpfr_check(a)) ERROR("last bits non 0");
114 MPFR_MANT(a)[0] = tmp;
115 MPFR_MANT(a)[MPFR_LIMB_SIZE(a)-1] &= MPFR_LIMB_MASK (GMP_NUMB_BITS-1);
116 if (mpfr_check(a)) ERROR("last bits non 0");
118 mpfr_set_ui(a, 2137, MPFR_RNDN);
119 if (!mpfr_check(a)) ERROR("after last set");
121 if (mpfr_check(a)) ERROR("after clear");