diff options
author | thevenyp <thevenyp@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2013-12-04 16:31:31 +0000 |
---|---|---|
committer | thevenyp <thevenyp@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2013-12-04 16:31:31 +0000 |
commit | bd754e0dcea34c0e7fa0b1dbe79effee8989c7d7 (patch) | |
tree | 063e43215e81e9840d0e9ca64eb0079fe0b40943 | |
parent | 4a311ffd142e0340cc889f8e0682dd6ef6843c98 (diff) | |
download | mpc-bd754e0dcea34c0e7fa0b1dbe79effee8989c7d7.tar.gz |
[tests/] Add again the check for the integrity of mpfr flags.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/branches/benchs_tests@1388 211d60ee-9f03-0410-a15a-8952a2c7a4e4
-rw-r--r-- | tests/Makefile.am | 4 | ||||
-rw-r--r-- | tests/data_check.tpl | 4 | ||||
-rw-r--r-- | tests/mpc-tests.h | 3 | ||||
-rw-r--r-- | tests/mpfr_flags.c | 117 | ||||
-rw-r--r-- | tests/tgeneric.tpl | 3 |
5 files changed, 129 insertions, 2 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 0cf93fd..77e5866 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -39,8 +39,8 @@ check_PROGRAMS = tabs tacos tacosh tadd tadd_fr tadd_si tadd_ui targ \ check_LTLIBRARIES=libmpc-tests.la libmpc_tests_la_SOURCES = mpc-tests.h check_data.c clear_parameters.c \ close_datafile.c comparisons.c copy_parameter.c double_rounding.c \ - init_parameters.c open_datafile.c print_parameter.c random.c \ - read_data.c read_description.c read_line.c rounding.c \ + init_parameters.c mpfr_flags.c open_datafile.c print_parameter.c \ + random.c read_data.c read_description.c read_line.c rounding.c \ setprec_parameters.c tpl_gmp.c tpl_mpc.c tpl_mpfr.c tpl_native.c DESCRIPTIONS = abs.dsc acos.dsc acosh.dsc add.dsc add_fr.dsc add_si.dsc \ diff --git a/tests/data_check.tpl b/tests/data_check.tpl index ddcdaaa..08dfa2a 100644 --- a/tests/data_check.tpl +++ b/tests/data_check.tpl @@ -37,6 +37,8 @@ along with this program. If not, see http://www.gnu.org/licenses/ . int data_check_template (const char* descr_file, const char * data_file) { + static int rand_counter = 0; + mpc_datafile_context_t datafile_context; mpc_datafile_context_t *dc = &datafile_context; @@ -49,7 +51,9 @@ data_check_template (const char* descr_file, const char * data_file) open_datafile (dc, data_file); while (datafile_context.nextchar != EOF) { read_line (dc, ¶ms); + set_mpfr_flags (rand_counter); MPC_FUNCTION_CALL; + check_mpfr_flags (rand_counter++); check_data (dc, ¶ms, 0); #ifdef MPC_FUNCTION_CALL_SYMMETRIC diff --git a/tests/mpc-tests.h b/tests/mpc-tests.h index caed58c..19027a5 100644 --- a/tests/mpc-tests.h +++ b/tests/mpc-tests.h @@ -152,6 +152,9 @@ extern size_t read_string (FILE *fp, char **buffer_ptr, extern void read_mpfr (FILE *fp, mpfr_ptr x, int *known_sign); extern void read_mpc (FILE *fp, mpc_ptr z, known_signs_t *ks); +void set_mpfr_flags (int counter); +void check_mpfr_flags (int counter); + /* function descriptions */ diff --git a/tests/mpfr_flags.c b/tests/mpfr_flags.c new file mode 100644 index 0000000..1ab7b37 --- /dev/null +++ b/tests/mpfr_flags.c @@ -0,0 +1,117 @@ +/* random.c -- Handle seed for random numbers. + +Copyright (C) 2013 INRIA + +This file is part of GNU MPC. + +GNU MPC is free software; you can redistribute it and/or modify it under +the terms of the GNU Lesser General Public License as published by the +Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for +more details. + +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see http://www.gnu.org/licenses/ . +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <mpfr.h> + +/* set MPFR flags to random values */ +void +set_mpfr_flags (int counter) +{ + if (counter & 1) + mpfr_set_underflow (); + else + mpfr_clear_underflow (); + if (counter & 2) + mpfr_set_overflow (); + else + mpfr_clear_overflow (); + /* the divide-by-0 flag was added in MPFR 3.1.0 */ +#ifdef mpfr_set_divby0 + if (counter & 4) + mpfr_set_divby0 (); + else + mpfr_clear_divby0 (); +#endif + if (counter & 8) + mpfr_set_nanflag (); + else + mpfr_clear_nanflag (); + if (counter & 16) + mpfr_set_inexflag (); + else + mpfr_clear_inexflag (); + if (counter & 32) + mpfr_set_erangeflag (); + else + mpfr_clear_erangeflag (); +} + +/* Check MPFR flags: we allow that some flags are set internally by MPC, + for example if MPC does internal computations (using MPFR) which yield + an overflow, even if the final MPC result fits in the exponent range. + However we don't allow MPC to *clear* the MPFR flags */ +void +check_mpfr_flags (int counter) +{ + int old, neu; + + old = (counter & 1) != 0; + neu = mpfr_underflow_p () != 0; + if (old && (neu == 0)) + { + printf ("Error, underflow flag has been modified from %d to %d\n", + old, neu); + exit (1); + } + old = (counter & 2) != 0; + neu = mpfr_overflow_p () != 0; + if (old && (neu == 0)) + { + printf ("Error, overflow flag has been modified from %d to %d\n", + old, neu); + exit (1); + } +#ifdef mpfr_divby0_p + old = (counter & 4) != 0; + neu = mpfr_divby0_p () != 0; + if (old && (neu == 0)) + { + printf ("Error, divby0 flag has been modified from %d to %d\n", + old, neu); + exit (1); + } +#endif + old = (counter & 8) != 0; + neu = mpfr_nanflag_p () != 0; + if (old && (neu == 0)) + { + printf ("Error, nanflag flag has been modified from %d to %d\n", + old, neu); + exit (1); + } + old = (counter & 16) != 0; + neu = mpfr_inexflag_p () != 0; + if (old && (neu == 0)) + { + printf ("Error, inexflag flag has been modified from %d to %d\n", + old, neu); + exit (1); + } + old = (counter & 32) != 0; + neu = mpfr_erangeflag_p () != 0; + if (old && (neu == 0)) + { + printf ("Error, erangeflag flag has been modified from %d to %d\n", + old, neu); + exit (1); + } +} diff --git a/tests/tgeneric.tpl b/tests/tgeneric.tpl index 45d984f..1b0d752 100644 --- a/tests/tgeneric.tpl +++ b/tests/tgeneric.tpl @@ -93,6 +93,7 @@ check_against_quadruple_precision (mpc_fun_param_t *params, mpfr_exp_t exp_min, mpfr_exp_t exp_max, int special) { + static int rand_counter = 0; mpc_operand_t *P = params->P; /* developer-friendly alias, used in macros */ set_input_precision (params, prec); @@ -115,7 +116,9 @@ check_against_quadruple_precision (mpc_fun_param_t *params, } set_output_precision (params, prec); + set_mpfr_flags (rand_counter); MPC_FUNCTION_CALL; + check_mpfr_flags (rand_counter++); check_data (NULL, params, 0); #ifdef MPC_FUNCTION_CALL_SYMMETRIC |