diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2018-03-24 00:28:27 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2018-03-24 00:28:27 +0000 |
commit | c3a432c61175dbb9b790135429f92a7b81eb7ccf (patch) | |
tree | 6e164f2419b10f8f7f3ee6e52378c1fd4cbe1975 /tests/ttotal_order.c | |
parent | 01e3e197ec7f7a051b4cb3ba995460cc58d183e4 (diff) | |
download | mpfr-c3a432c61175dbb9b790135429f92a7b81eb7ccf.tar.gz |
[tests] Renamed total_order.c to ttotal_order.c.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@12494 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/ttotal_order.c')
-rw-r--r-- | tests/ttotal_order.c | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/tests/ttotal_order.c b/tests/ttotal_order.c new file mode 100644 index 000000000..0fa019c22 --- /dev/null +++ b/tests/ttotal_order.c @@ -0,0 +1,121 @@ +/* Test file for mpfr_total_order. + +Copyright 2018 Free Software Foundation, Inc. +Contributed by the AriC and Caramba projects, INRIA. + +This file is part of the GNU MPFR Library. + +The GNU MPFR Library 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. + +The GNU MPFR Library 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 the GNU MPFR Library; see the file COPYING.LESSER. If not, see +http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include "mpfr-test.h" + +int +main (void) +{ + mpfr_t x, y; + + tests_start_mpfr (); + + mpfr_init (x); + mpfr_init (y); + + /* If x < y, totalOrder(x, y) is true */ + mpfr_set_ui (x, 1, MPFR_RNDN); + mpfr_set_ui (y, 2, MPFR_RNDN); + MPFR_ASSERTN(mpfr_total_order (x, y) != 0); + + /* If x > y, totalOrder(x, y) is false */ + mpfr_set_ui (x, 2, MPFR_RNDN); + mpfr_set_ui (y, 1, MPFR_RNDN); + MPFR_ASSERTN(mpfr_total_order (x, y) == 0); + + /* totalOrder(-0, +0) is true */ + mpfr_set_ui (x, 0, MPFR_RNDN); + mpfr_neg (x, x, MPFR_RNDN); + mpfr_set_ui (y, 0, MPFR_RNDN); + MPFR_ASSERTN(mpfr_total_order (x, y) != 0); + + /* totalOrder(+0, -0) is false */ + mpfr_set_ui (x, 0, MPFR_RNDN); + mpfr_set_ui (y, 0, MPFR_RNDN); + mpfr_neg (y, y, MPFR_RNDN); + MPFR_ASSERTN(mpfr_total_order (x, y) == 0); + + /* Case x = y */ + mpfr_set_si (x, -1, MPFR_RNDN); + mpfr_set_si (y, -1, MPFR_RNDN); + MPFR_ASSERTN(mpfr_total_order (x, y) != 0); + + mpfr_set_si (x, 1, MPFR_RNDN); + mpfr_set_si (y, 1, MPFR_RNDN); + MPFR_ASSERTN(mpfr_total_order (x, y) != 0); + + /* Case x = -NaN */ + mpfr_set_nan (x); + /* warning: the sign of x is unspecified in mpfr_set_nan */ + if (!mpfr_signbit (x)) + mpfr_neg (x, x, MPFR_RNDN); + /* now x = -NaN */ + mpfr_set_si (y, 1, MPFR_RNDN); + MPFR_ASSERTN(mpfr_total_order (x, y) != 0); + mpfr_set_inf (y, -1); + MPFR_ASSERTN(mpfr_total_order (x, y) != 0); + mpfr_set_inf (y, +1); + MPFR_ASSERTN(mpfr_total_order (x, y) != 0); + + /* Case y = +NaN */ + mpfr_set_nan (y); + if (mpfr_signbit (y)) + mpfr_neg (y, y, MPFR_RNDN); + /* now y = +NaN */ + mpfr_set_si (x, 1, MPFR_RNDN); + MPFR_ASSERTN(mpfr_total_order (x, y) != 0); + mpfr_set_inf (x, -1); + MPFR_ASSERTN(mpfr_total_order (x, y) != 0); + mpfr_set_inf (x, +1); + MPFR_ASSERTN(mpfr_total_order (x, y) != 0); + + /* Both x and y are NaN */ + mpfr_set_nan (x); + if (!mpfr_signbit (x)) + mpfr_neg (x, x, MPFR_RNDN); + /* now x = -NaN */ + mpfr_set_nan (y); + if (mpfr_signbit (y)) + mpfr_neg (y, y, MPFR_RNDN); + /* now y = +NaN */ + MPFR_ASSERTN(mpfr_total_order (x, y) != 0); + mpfr_neg (y, y, MPFR_RNDN); + MPFR_ASSERTN(mpfr_total_order (x, y) != 0); + + mpfr_set_nan (x); + if (mpfr_signbit (x)) + mpfr_neg (x, x, MPFR_RNDN); + /* now x = +NaN */ + mpfr_set_nan (y); + if (mpfr_signbit (y)) + mpfr_neg (y, y, MPFR_RNDN); + /* now y = +NaN */ + MPFR_ASSERTN(mpfr_total_order (x, y) != 0); + mpfr_neg (y, y, MPFR_RNDN); + MPFR_ASSERTN(mpfr_total_order (x, y) == 0); + + mpfr_clear (x); + mpfr_clear (y); + + tests_end_mpfr (); + return 0; +} |