summaryrefslogtreecommitdiff
path: root/mpfr/tests/tset_si.c
diff options
context:
space:
mode:
Diffstat (limited to 'mpfr/tests/tset_si.c')
-rw-r--r--mpfr/tests/tset_si.c104
1 files changed, 79 insertions, 25 deletions
diff --git a/mpfr/tests/tset_si.c b/mpfr/tests/tset_si.c
index 0d20cbe4c..1f2f82e1a 100644
--- a/mpfr/tests/tset_si.c
+++ b/mpfr/tests/tset_si.c
@@ -1,20 +1,20 @@
/* Test file for mpfr_set_si and mpfr_set_ui.
-Copyright (C) 1999 Free Software Foundation.
+Copyright (C) 1999, 2001 Free Software Foundation, Inc.
This file is part of the MPFR Library.
The MPFR Library is free software; you can redistribute it and/or modify
-it under the terms of the GNU Library General Public License as published by
-the Free Software Foundation; either version 2 of the License, or (at your
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The 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 Library General Public
+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 Library General Public License
+You should have received a copy of the GNU Lesser General Public License
along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
@@ -27,9 +27,12 @@ MA 02111-1307, USA. */
#include "time.h"
int
-main(int argc, char **argv)
+main (int argc, char *argv[])
{
- mpfr_t x; long k, z, d; unsigned long zl, dl, N;
+ mpfr_t x;
+ long k, z, d;
+ unsigned long zl, dl, N;
+ int inex;
mpfr_init2(x, 100);
@@ -40,51 +43,102 @@ main(int argc, char **argv)
for (k = 1; k <= N; k++)
{
z = random() - (1 << 30);
- mpfr_set_si(x, z, GMP_RNDZ);
- d = (int)mpfr_get_d(x);
+ inex = mpfr_set_si(x, z, GMP_RNDZ);
+ d = (long) mpfr_get_d(x);
if (d != z) {
fprintf(stderr, "Error in mpfr_set_si: expected %ld got %ld\n", z, d); exit(1);
}
+ if (inex)
+ {
+ fprintf(stderr,
+ "Error in mpfr_set_si: inex value incorrect for %ld: %d\n",
+ z, inex);
+ exit(1);
+ }
}
for (k = 1; k <= N; k++)
{
zl = random();
- mpfr_set_ui(x, zl, GMP_RNDZ);
- dl = (unsigned int) mpfr_get_d(x);
+ inex = mpfr_set_ui (x, zl, GMP_RNDZ);
+ dl = (unsigned long) mpfr_get_d (x);
if (dl != zl) {
fprintf(stderr, "Error in mpfr_set_ui: expected %lu got %lu\n", zl, dl); exit(1);
}
+ if (inex)
+ {
+ fprintf(stderr,
+ "Error in mpfr_set_ui: inex value incorrect for %lu: %d\n",
+ zl, inex);
+ exit(1);
+ }
+ }
+
+ mpfr_set_prec (x, 1);
+ if (mpfr_set_si (x, 5, GMP_RNDZ) >= 0)
+ {
+ fprintf (stderr, "Wrong inexact flag for x=5, rnd=GMP_RNDZ\n");
+ exit (1);
+ }
+
+ mpfr_set_prec (x, 1);
+ if (mpfr_set_si (x, -5, GMP_RNDZ) <= 0)
+ {
+ fprintf (stderr, "Wrong inexact flag for x=-5, rnd=GMP_RNDZ\n");
+ exit (1);
}
- mpfr_set_prec(x, 3);
- mpfr_set_si(x, 77617, GMP_RNDD); /* should be 65536 */
- if (MPFR_MANT(x)[0] != ((mp_limb_t)1 << (mp_bits_per_limb-1))) {
+ mpfr_set_prec (x, 3);
+ inex = mpfr_set_si(x, 77617, GMP_RNDD); /* should be 65536 */
+ if (MPFR_MANT(x)[0] != ((mp_limb_t)1 << (mp_bits_per_limb-1))
+ || inex >= 0)
+ {
fprintf(stderr, "Error in mpfr_set_si(x:3, 77617, GMP_RNDD)\n");
mpfr_print_raw(x); putchar('\n');
exit(1);
}
- mpfr_set_ui(x, 77617, GMP_RNDD); /* should be 65536 */
- if (MPFR_MANT(x)[0] != ((mp_limb_t)1 << (mp_bits_per_limb-1))) {
+ inex = mpfr_set_ui(x, 77617, GMP_RNDD); /* should be 65536 */
+ if (MPFR_MANT(x)[0] != ((mp_limb_t)1 << (mp_bits_per_limb-1))
+ || inex >= 0)
+ {
fprintf(stderr, "Error in mpfr_set_ui(x:3, 77617, GMP_RNDD)\n");
mpfr_print_raw(x); putchar('\n');
exit(1);
}
mpfr_set_prec(x, 1);
- mpfr_set_si(x, 33096, GMP_RNDU);
- if (mpfr_get_d(x) != 65536.0) {
- fprintf(stderr, "Error in mpfr_set_si, expected 65536, got %lu\n",
- (unsigned long) mpfr_get_d(x));
+ inex = mpfr_set_si(x, 33096, GMP_RNDU);
+ if (mpfr_get_d(x) != 65536.0 || inex <= 0)
+ {
+ fprintf(stderr, "Error in mpfr_set_si, expected 65536, got %lu, inex %d\n",
+ (unsigned long) mpfr_get_d(x), inex);
exit(1);
}
- mpfr_set_ui(x, 33096, GMP_RNDU);
- if (mpfr_get_d(x) != 65536.0) {
- fprintf(stderr, "Error in mpfr_set_ui, expected 65536, got %lu\n",
- (unsigned long) mpfr_get_d(x));
+ inex = mpfr_set_ui(x, 33096, GMP_RNDU);
+ if (mpfr_get_d(x) != 65536.0)
+ {
+ fprintf(stderr, "Error in mpfr_set_ui, expected 65536, got %lu, inex %d\n",
+ (unsigned long) mpfr_get_d(x), inex);
exit(1);
}
+ mpfr_set_si (x, -1, GMP_RNDN);
+ mpfr_set_ui (x, 0, GMP_RNDN);
+ if (MPFR_SIGN (x) < 0)
+ {
+ fprintf (stderr, "mpfr_set_ui (x, 0) gives -0\n");
+ exit (1);
+ }
+
+ mpfr_set_si (x, -1, GMP_RNDN);
+ mpfr_set_si (x, 0, GMP_RNDN);
+ if (MPFR_SIGN (x) < 0)
+ {
+ fprintf (stderr, "mpfr_set_si (x, 0) gives -0\n");
+ exit (1);
+ }
+
mpfr_clear(x);
- return(0);
+
+ return 0;
}