source: patches/mpfr-3.1.2-fixes-1.patch@ e680587

clfs-3.0.0-systemd clfs-3.0.0-sysvinit systemd sysvinit
Last change on this file since e680587 was d42579b, checked in by William Harrington <kb0iic@…>, 11 years ago

Create mpfr 3.1.2 fixes patch.

  • Property mode set to 100644
File size: 22.3 KB
  • mpfr-3.1.2

    Submitted By: William Harrington (kb0iic at cross-lfs dot org)
    Date: 2013-11-11
    Initial Package Version: 3.1.2
    Origin: Upstream
    Upstream Status: Applied
    Description: Contains all upstream patches of mpfr current.
    
    diff -Naur mpfr-3.1.2.orig/PATCHES mpfr-3.1.2/PATCHES
    old new  
     1clang-divby0
     2fits-smallneg
     3exp_2
  • mpfr-3.1.2

    diff -Naur mpfr-3.1.2.orig/VERSION mpfr-3.1.2/VERSION
    old new  
    1 3.1.2
     13.1.2-p3
  • src/exp_2.c

    diff -Naur mpfr-3.1.2.orig/src/exp_2.c mpfr-3.1.2/src/exp_2.c
    old new  
    204204          for (k = 0; k < K; k++)
    205205            {
    206206              mpz_mul (ss, ss, ss);
    207               exps <<= 1;
     207              exps *= 2;
    208208              exps += mpz_normalize (ss, ss, q);
    209209            }
    210210          mpfr_set_z (s, ss, MPFR_RNDN);
  • src/fits_u.h

    diff -Naur mpfr-3.1.2.orig/src/fits_u.h mpfr-3.1.2/src/fits_u.h
    old new  
    3232  int res;
    3333
    3434  if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (f)))
    35     /* Zero always fit */
    36     return MPFR_IS_ZERO (f) ? 1 : 0;
    37   else if (MPFR_IS_NEG (f))
    38     /* Negative numbers don't fit */
    39     return 0;
    40   /* now it fits if
    41      (a) f <= MAXIMUM
    42      (b) round(f, prec(slong), rnd) <= MAXIMUM */
     35    return MPFR_IS_ZERO (f) ? 1 : 0;  /* Zero always fits */
    4336
    4437  e = MPFR_GET_EXP (f);
    4538
     39  if (MPFR_IS_NEG (f))
     40    return e >= 1 ? 0  /* f <= -1 does not fit */
     41      : rnd != MPFR_RNDN ? MPFR_IS_LIKE_RNDU (rnd, -1)  /* directed mode */
     42      : e < 0 ? 1  /* f > -1/2 fits in MPFR_RNDN */
     43      : mpfr_powerof2_raw(f);  /* -1/2 fits, -1 < f < -1/2 don't */
     44
     45  /* Now it fits if
     46     (a) f <= MAXIMUM
     47     (b) round(f, prec(slong), rnd) <= MAXIMUM */
     48
    4649  /* first compute prec(MAXIMUM); fits in an int */
    4750  for (s = MAXIMUM, prec = 0; s != 0; s /= 2, prec ++);
    4851
  • src/fits_uintmax.c

    diff -Naur mpfr-3.1.2.orig/src/fits_uintmax.c mpfr-3.1.2/src/fits_uintmax.c
    old new  
    2727#include "mpfr-intmax.h"
    2828#include "mpfr-impl.h"
    2929
    30 #ifdef _MPFR_H_HAVE_INTMAX_T
    31 
    32 /* We can't use fits_u.h <= mpfr_cmp_ui */
    33 int
    34 mpfr_fits_uintmax_p (mpfr_srcptr f, mpfr_rnd_t rnd)
    35 {
    36   mpfr_exp_t e;
    37   int prec;
    38   uintmax_t s;
    39   mpfr_t x;
    40   int res;
    41 
    42   if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (f)))
    43     /* Zero always fit */
    44     return MPFR_IS_ZERO (f) ? 1 : 0;
    45   else if (MPFR_IS_NEG (f))
    46     /* Negative numbers don't fit */
    47     return 0;
    48   /* now it fits if
    49      (a) f <= MAXIMUM
    50      (b) round(f, prec(slong), rnd) <= MAXIMUM */
    51 
    52   e = MPFR_GET_EXP (f);
     30/* Note: though mpfr-impl.h is included in fits_u.h, we also include it
     31   above so that it gets included even when _MPFR_H_HAVE_INTMAX_T is not
     32   defined; this is necessary to avoid an empty translation unit, which
     33   is forbidden by ISO C. Without this, a failing test can be reproduced
     34   by creating an invalid stdint.h somewhere in the default include path
     35   and by compiling MPFR with "gcc -ansi -pedantic-errors". */
    5336
    54   /* first compute prec(MAXIMUM); fits in an int */
    55   for (s = MPFR_UINTMAX_MAX, prec = 0; s != 0; s /= 2, prec ++);
    56 
    57   /* MAXIMUM needs prec bits, i.e. MAXIMUM = 2^prec - 1 */
    58 
    59   /* if e <= prec - 1, then f < 2^(prec-1) < MAXIMUM */
    60   if (e <= prec - 1)
    61     return 1;
    62 
    63   /* if e >= prec + 1, then f >= 2^prec > MAXIMUM */
    64   if (e >= prec + 1)
    65     return 0;
     37#ifdef _MPFR_H_HAVE_INTMAX_T
    6638
    67   MPFR_ASSERTD (e == prec);
     39#define FUNCTION   mpfr_fits_uintmax_p
     40#define MAXIMUM    MPFR_UINTMAX_MAX
     41#define TYPE       uintmax_t
    6842
    69   /* hard case: first round to prec bits, then check */
    70   mpfr_init2 (x, prec);
    71   mpfr_set (x, f, rnd);
    72   res = MPFR_GET_EXP (x) == e;
    73   mpfr_clear (x);
    74   return res;
    75 }
     43#include "fits_u.h"
    7644
    7745#endif
  • src/mpfr-impl.h

    diff -Naur mpfr-3.1.2.orig/src/mpfr-impl.h mpfr-3.1.2/src/mpfr-impl.h
    old new  
    468468#define MPFR_LIMBS_PER_FLT ((IEEE_FLT_MANT_DIG-1)/GMP_NUMB_BITS+1)
    469469
    470470/* Visual C++ doesn't support +1.0/0.0, -1.0/0.0 and 0.0/0.0
    471    at compile time. */
    472 #if defined(_MSC_VER) && defined(_WIN32) && (_MSC_VER >= 1200)
     471   at compile time.
     472   Clang with -fsanitize=undefined is a bit similar due to a bug:
     473     http://llvm.org/bugs/show_bug.cgi?id=17381
     474   but even without its sanitizer, it may be better to use the
     475   double_zero version until IEEE 754 division by zero is properly
     476   supported:
     477     http://llvm.org/bugs/show_bug.cgi?id=17000
     478*/
     479#if (defined(_MSC_VER) && defined(_WIN32) && (_MSC_VER >= 1200)) || \
     480    defined(__clang__)
    473481static double double_zero = 0.0;
    474482# define DBL_NAN (double_zero/double_zero)
    475483# define DBL_POS_INF ((double) 1.0/double_zero)
     
    501509   (with Xcode 2.4.1, i.e. the latest one). */
    502510#define LVALUE(x) (&(x) == &(x) || &(x) != &(x))
    503511#define DOUBLE_ISINF(x) (LVALUE(x) && ((x) > DBL_MAX || (x) < -DBL_MAX))
     512/* The DOUBLE_ISNAN(x) macro is also valid on long double x
     513   (assuming that the compiler isn't too broken). */
    504514#ifdef MPFR_NANISNAN
    505515/* Avoid MIPSpro / IRIX64 / gcc -ffast-math (incorrect) optimizations.
    506516   The + must not be replaced by a ||. With gcc -ffast-math, NaN is
  • src/mpfr.h

    diff -Naur mpfr-3.1.2.orig/src/mpfr.h mpfr-3.1.2/src/mpfr.h
    old new  
    2727#define MPFR_VERSION_MAJOR 3
    2828#define MPFR_VERSION_MINOR 1
    2929#define MPFR_VERSION_PATCHLEVEL 2
    30 #define MPFR_VERSION_STRING "3.1.2"
     30#define MPFR_VERSION_STRING "3.1.2-p3"
    3131
    3232/* Macros dealing with MPFR VERSION */
    3333#define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
  • src/version.c

    diff -Naur mpfr-3.1.2.orig/src/version.c mpfr-3.1.2/src/version.c
    old new  
    2525const char *
    2626mpfr_get_version (void)
    2727{
    28   return "3.1.2";
     28  return "3.1.2-p3";
    2929}
  • tests/tfits.c

    diff -Naur mpfr-3.1.2.orig/tests/tfits.c mpfr-3.1.2/tests/tfits.c
    old new  
    3333#include "mpfr-intmax.h"
    3434#include "mpfr-test.h"
    3535
    36 #define ERROR1 { printf("Initial error for x="); mpfr_dump(x); exit(1); }
    37 #define ERROR2 { printf("Error for x="); mpfr_dump(x); exit(1); }
     36#define ERROR1(N)                                               \
     37  do                                                            \
     38    {                                                           \
     39      printf("Error %d for rnd = %s and x = ", N,               \
     40             mpfr_print_rnd_mode ((mpfr_rnd_t) r));             \
     41      mpfr_dump(x);                                             \
     42      exit(1);                                                  \
     43    }                                                           \
     44  while (0)
    3845
    3946static void check_intmax (void);
    4047
    4148int
    4249main (void)
    4350{
    44   mpfr_t x;
     51  mpfr_t x, y;
     52  int i, r;
    4553
    4654  tests_start_mpfr ();
    4755
    4856  mpfr_init2 (x, 256);
     57  mpfr_init2 (y, 8);
    4958
    50   /* Check NAN */
    51   mpfr_set_nan (x);
    52   if (mpfr_fits_ulong_p (x, MPFR_RNDN))
    53     ERROR1;
    54   if (mpfr_fits_slong_p (x, MPFR_RNDN))
    55     ERROR1;
    56   if (mpfr_fits_uint_p (x, MPFR_RNDN))
    57     ERROR1;
    58   if (mpfr_fits_sint_p (x, MPFR_RNDN))
    59     ERROR1;
    60   if (mpfr_fits_ushort_p (x, MPFR_RNDN))
    61     ERROR1;
    62   if (mpfr_fits_sshort_p (x, MPFR_RNDN))
    63     ERROR1;
    64 
    65   /* Check INF */
    66   mpfr_set_inf (x, 1);
    67   if (mpfr_fits_ulong_p (x, MPFR_RNDN))
    68     ERROR1;
    69   if (mpfr_fits_slong_p (x, MPFR_RNDN))
    70     ERROR1;
    71   if (mpfr_fits_uint_p (x, MPFR_RNDN))
    72     ERROR1;
    73   if (mpfr_fits_sint_p (x, MPFR_RNDN))
    74     ERROR1;
    75   if (mpfr_fits_ushort_p (x, MPFR_RNDN))
    76     ERROR1;
    77   if (mpfr_fits_sshort_p (x, MPFR_RNDN))
    78     ERROR1;
    79 
    80   /* Check Zero */
    81   MPFR_SET_ZERO (x);
    82   if (!mpfr_fits_ulong_p (x, MPFR_RNDN))
    83     ERROR2;
    84   if (!mpfr_fits_slong_p (x, MPFR_RNDN))
    85     ERROR2;
    86   if (!mpfr_fits_uint_p (x, MPFR_RNDN))
    87     ERROR2;
    88   if (!mpfr_fits_sint_p (x, MPFR_RNDN))
    89     ERROR2;
    90   if (!mpfr_fits_ushort_p (x, MPFR_RNDN))
    91     ERROR2;
    92   if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
    93     ERROR2;
    94 
    95   /* Check small op */
    96   mpfr_set_str1 (x, "1@-1");
    97   if (!mpfr_fits_ulong_p (x, MPFR_RNDN))
    98     ERROR2;
    99   if (!mpfr_fits_slong_p (x, MPFR_RNDN))
    100     ERROR2;
    101   if (!mpfr_fits_uint_p (x, MPFR_RNDN))
    102     ERROR2;
    103   if (!mpfr_fits_sint_p (x, MPFR_RNDN))
    104     ERROR2;
    105   if (!mpfr_fits_ushort_p (x, MPFR_RNDN))
    106     ERROR2;
    107   if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
    108     ERROR2;
    109 
    110   /* Check 17 */
    111   mpfr_set_ui (x, 17, MPFR_RNDN);
    112   if (!mpfr_fits_ulong_p (x, MPFR_RNDN))
    113     ERROR2;
    114   if (!mpfr_fits_slong_p (x, MPFR_RNDN))
    115     ERROR2;
    116   if (!mpfr_fits_uint_p (x, MPFR_RNDN))
    117     ERROR2;
    118   if (!mpfr_fits_sint_p (x, MPFR_RNDN))
    119     ERROR2;
    120   if (!mpfr_fits_ushort_p (x, MPFR_RNDN))
    121     ERROR2;
    122   if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
    123     ERROR2;
    124 
    125   /* Check all other values */
    126   mpfr_set_ui (x, ULONG_MAX, MPFR_RNDN);
    127   mpfr_mul_2exp (x, x, 1, MPFR_RNDN);
    128   if (mpfr_fits_ulong_p (x, MPFR_RNDN))
    129     ERROR1;
    130   if (mpfr_fits_slong_p (x, MPFR_RNDN))
    131     ERROR1;
    132   mpfr_mul_2exp (x, x, 40, MPFR_RNDN);
    133   if (mpfr_fits_ulong_p (x, MPFR_RNDN))
    134     ERROR1;
    135   if (mpfr_fits_uint_p (x, MPFR_RNDN))
    136     ERROR1;
    137   if (mpfr_fits_sint_p (x, MPFR_RNDN))
    138     ERROR1;
    139   if (mpfr_fits_ushort_p (x, MPFR_RNDN))
    140     ERROR1;
    141   if (mpfr_fits_sshort_p (x, MPFR_RNDN))
    142     ERROR1;
    143 
    144   mpfr_set_ui (x, ULONG_MAX, MPFR_RNDN);
    145   if (!mpfr_fits_ulong_p (x, MPFR_RNDN))
    146     ERROR2;
    147   mpfr_set_ui (x, LONG_MAX, MPFR_RNDN);
    148   if (!mpfr_fits_slong_p (x, MPFR_RNDN))
    149     ERROR2;
    150   mpfr_set_ui (x, UINT_MAX, MPFR_RNDN);
    151   if (!mpfr_fits_uint_p (x, MPFR_RNDN))
    152     ERROR2;
    153   mpfr_set_ui (x, INT_MAX, MPFR_RNDN);
    154   if (!mpfr_fits_sint_p (x, MPFR_RNDN))
    155     ERROR2;
    156   mpfr_set_ui (x, USHRT_MAX, MPFR_RNDN);
    157   if (!mpfr_fits_ushort_p (x, MPFR_RNDN))
    158     ERROR2;
    159   mpfr_set_ui (x, SHRT_MAX, MPFR_RNDN);
    160   if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
    161     ERROR2;
    162 
    163   mpfr_set_si (x, 1, MPFR_RNDN);
    164   if (!mpfr_fits_sint_p (x, MPFR_RNDN))
    165     ERROR2;
    166   if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
    167     ERROR2;
    168 
    169   /* Check negative value */
    170   mpfr_set_si (x, -1, MPFR_RNDN);
    171   if (!mpfr_fits_sint_p (x, MPFR_RNDN))
    172     ERROR2;
    173   if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
    174     ERROR2;
    175   if (!mpfr_fits_slong_p (x, MPFR_RNDN))
    176     ERROR2;
    177   if (mpfr_fits_uint_p (x, MPFR_RNDN))
    178     ERROR1;
    179   if (mpfr_fits_ushort_p (x, MPFR_RNDN))
    180     ERROR1;
    181   if (mpfr_fits_ulong_p (x, MPFR_RNDN))
    182     ERROR1;
     59  RND_LOOP (r)
     60    {
     61
     62      /* Check NAN */
     63      mpfr_set_nan (x);
     64      if (mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
     65        ERROR1 (1);
     66      if (mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
     67        ERROR1 (2);
     68      if (mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
     69        ERROR1 (3);
     70      if (mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
     71        ERROR1 (4);
     72      if (mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
     73        ERROR1 (5);
     74      if (mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
     75        ERROR1 (6);
     76
     77      /* Check INF */
     78      mpfr_set_inf (x, 1);
     79      if (mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
     80        ERROR1 (7);
     81      if (mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
     82        ERROR1 (8);
     83      if (mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
     84        ERROR1 (9);
     85      if (mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
     86        ERROR1 (10);
     87      if (mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
     88        ERROR1 (11);
     89      if (mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
     90        ERROR1 (12);
     91
     92      /* Check Zero */
     93      MPFR_SET_ZERO (x);
     94      if (!mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
     95        ERROR1 (13);
     96      if (!mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
     97        ERROR1 (14);
     98      if (!mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
     99        ERROR1 (15);
     100      if (!mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
     101        ERROR1 (16);
     102      if (!mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
     103        ERROR1 (17);
     104      if (!mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
     105        ERROR1 (18);
     106
     107      /* Check small positive op */
     108      mpfr_set_str1 (x, "1@-1");
     109      if (!mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
     110        ERROR1 (19);
     111      if (!mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
     112        ERROR1 (20);
     113      if (!mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
     114        ERROR1 (21);
     115      if (!mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
     116        ERROR1 (22);
     117      if (!mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
     118        ERROR1 (23);
     119      if (!mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
     120        ERROR1 (24);
     121
     122      /* Check 17 */
     123      mpfr_set_ui (x, 17, MPFR_RNDN);
     124      if (!mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
     125        ERROR1 (25);
     126      if (!mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
     127        ERROR1 (26);
     128      if (!mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
     129        ERROR1 (27);
     130      if (!mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
     131        ERROR1 (28);
     132      if (!mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
     133        ERROR1 (29);
     134      if (!mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
     135        ERROR1 (30);
     136
     137      /* Check all other values */
     138      mpfr_set_ui (x, ULONG_MAX, MPFR_RNDN);
     139      mpfr_mul_2exp (x, x, 1, MPFR_RNDN);
     140      if (mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
     141        ERROR1 (31);
     142      if (mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
     143        ERROR1 (32);
     144      mpfr_mul_2exp (x, x, 40, MPFR_RNDN);
     145      if (mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
     146        ERROR1 (33);
     147      if (mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
     148        ERROR1 (34);
     149      if (mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
     150        ERROR1 (35);
     151      if (mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
     152        ERROR1 (36);
     153      if (mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
     154        ERROR1 (37);
     155
     156      mpfr_set_ui (x, ULONG_MAX, MPFR_RNDN);
     157      if (!mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
     158        ERROR1 (38);
     159      mpfr_set_ui (x, LONG_MAX, MPFR_RNDN);
     160      if (!mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
     161        ERROR1 (39);
     162      mpfr_set_ui (x, UINT_MAX, MPFR_RNDN);
     163      if (!mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
     164        ERROR1 (40);
     165      mpfr_set_ui (x, INT_MAX, MPFR_RNDN);
     166      if (!mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
     167        ERROR1 (41);
     168      mpfr_set_ui (x, USHRT_MAX, MPFR_RNDN);
     169      if (!mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
     170        ERROR1 (42);
     171      mpfr_set_ui (x, SHRT_MAX, MPFR_RNDN);
     172      if (!mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
     173        ERROR1 (43);
     174
     175      mpfr_set_si (x, 1, MPFR_RNDN);
     176      if (!mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
     177        ERROR1 (44);
     178      if (!mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
     179        ERROR1 (45);
     180
     181      /* Check negative op */
     182      for (i = 1; i <= 4; i++)
     183        {
     184          int inv;
     185
     186          mpfr_set_si_2exp (x, -i, -2, MPFR_RNDN);
     187          mpfr_rint (y, x, (mpfr_rnd_t) r);
     188          inv = MPFR_NOTZERO (y);
     189          if (!mpfr_fits_ulong_p (x, (mpfr_rnd_t) r) ^ inv)
     190            ERROR1 (46);
     191          if (!mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
     192            ERROR1 (47);
     193          if (!mpfr_fits_uint_p (x, (mpfr_rnd_t) r) ^ inv)
     194            ERROR1 (48);
     195          if (!mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
     196            ERROR1 (49);
     197          if (!mpfr_fits_ushort_p (x, (mpfr_rnd_t) r) ^ inv)
     198            ERROR1 (50);
     199          if (!mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
     200            ERROR1 (51);
     201        }
     202    }
    183203
    184204  mpfr_clear (x);
     205  mpfr_clear (y);
    185206
    186207  check_intmax ();
    187208
     
    189210  return 0;
    190211}
    191212
    192 static void check_intmax (void)
     213static void
     214check_intmax (void)
    193215{
    194216#ifdef _MPFR_H_HAVE_INTMAX_T
    195   mpfr_t x;
     217  mpfr_t x, y;
     218  int i, r;
    196219
    197   mpfr_init2 (x, sizeof (uintmax_t)*CHAR_BIT);
     220  mpfr_init2 (x, sizeof (uintmax_t) * CHAR_BIT);
     221  mpfr_init2 (y, 8);
    198222
    199   /* Check NAN */
    200   mpfr_set_nan (x);
    201   if (mpfr_fits_uintmax_p (x, MPFR_RNDN))
    202     ERROR1;
    203   if (mpfr_fits_intmax_p (x, MPFR_RNDN))
    204     ERROR1;
    205 
    206   /* Check INF */
    207   mpfr_set_inf (x, 1);
    208   if (mpfr_fits_uintmax_p (x, MPFR_RNDN))
    209     ERROR1;
    210   if (mpfr_fits_intmax_p (x, MPFR_RNDN))
    211     ERROR1;
    212 
    213   /* Check Zero */
    214   MPFR_SET_ZERO (x);
    215   if (!mpfr_fits_uintmax_p (x, MPFR_RNDN))
    216     ERROR2;
    217   if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
    218     ERROR2;
    219 
    220   /* Check small op */
    221   mpfr_set_str1 (x, "1@-1");
    222   if (!mpfr_fits_uintmax_p (x, MPFR_RNDN))
    223     ERROR2;
    224   if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
    225     ERROR2;
    226 
    227   /* Check 17 */
    228   mpfr_set_ui (x, 17, MPFR_RNDN);
    229   if (!mpfr_fits_uintmax_p (x, MPFR_RNDN))
    230     ERROR2;
    231   if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
    232     ERROR2;
    233 
    234   /* Check hugest */
    235   mpfr_set_ui_2exp (x, 42, sizeof (uintmax_t) * 32, MPFR_RNDN);
    236   if (mpfr_fits_uintmax_p (x, MPFR_RNDN))
    237     ERROR1;
    238   if (mpfr_fits_intmax_p (x, MPFR_RNDN))
    239     ERROR1;
    240 
    241   /* Check all other values */
    242   mpfr_set_uj (x, MPFR_UINTMAX_MAX, MPFR_RNDN);
    243   mpfr_add_ui (x, x, 1, MPFR_RNDN);
    244   if (mpfr_fits_uintmax_p (x, MPFR_RNDN))
    245     ERROR1;
    246   mpfr_set_uj (x, MPFR_UINTMAX_MAX, MPFR_RNDN);
    247   if (!mpfr_fits_uintmax_p (x, MPFR_RNDN))
    248     ERROR2;
    249   mpfr_set_sj (x, MPFR_INTMAX_MAX, MPFR_RNDN);
    250   mpfr_add_ui (x, x, 1, MPFR_RNDN);
    251   if (mpfr_fits_intmax_p (x, MPFR_RNDN))
    252     ERROR1;
    253   mpfr_set_sj (x, MPFR_INTMAX_MAX, MPFR_RNDN);
    254   if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
    255     ERROR2;
    256   mpfr_set_sj (x, MPFR_INTMAX_MIN, MPFR_RNDN);
    257   if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
    258     ERROR2;
    259   mpfr_sub_ui (x, x, 1, MPFR_RNDN);
    260   if (mpfr_fits_intmax_p (x, MPFR_RNDN))
    261     ERROR1;
    262 
    263   /* Check negative value */
    264   mpfr_set_si (x, -1, MPFR_RNDN);
    265   if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
    266     ERROR2;
    267   if (mpfr_fits_uintmax_p (x, MPFR_RNDN))
    268     ERROR1;
     223  RND_LOOP (r)
     224    {
     225      /* Check NAN */
     226      mpfr_set_nan (x);
     227      if (mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
     228        ERROR1 (52);
     229      if (mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
     230        ERROR1 (53);
     231
     232      /* Check INF */
     233      mpfr_set_inf (x, 1);
     234      if (mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
     235        ERROR1 (54);
     236      if (mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
     237        ERROR1 (55);
     238
     239      /* Check Zero */
     240      MPFR_SET_ZERO (x);
     241      if (!mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
     242        ERROR1 (56);
     243      if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
     244        ERROR1 (57);
     245
     246      /* Check positive small op */
     247      mpfr_set_str1 (x, "1@-1");
     248      if (!mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
     249        ERROR1 (58);
     250      if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
     251        ERROR1 (59);
     252
     253      /* Check 17 */
     254      mpfr_set_ui (x, 17, MPFR_RNDN);
     255      if (!mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
     256        ERROR1 (60);
     257      if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
     258        ERROR1 (61);
     259
     260      /* Check hugest */
     261      mpfr_set_ui_2exp (x, 42, sizeof (uintmax_t) * 32, MPFR_RNDN);
     262      if (mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
     263        ERROR1 (62);
     264      if (mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
     265        ERROR1 (63);
     266
     267      /* Check all other values */
     268      mpfr_set_uj (x, MPFR_UINTMAX_MAX, MPFR_RNDN);
     269      mpfr_add_ui (x, x, 1, MPFR_RNDN);
     270      if (mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
     271        ERROR1 (64);
     272      mpfr_set_uj (x, MPFR_UINTMAX_MAX, MPFR_RNDN);
     273      if (!mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
     274        ERROR1 (65);
     275      mpfr_set_sj (x, MPFR_INTMAX_MAX, MPFR_RNDN);
     276      mpfr_add_ui (x, x, 1, MPFR_RNDN);
     277      if (mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
     278        ERROR1 (66);
     279      mpfr_set_sj (x, MPFR_INTMAX_MAX, MPFR_RNDN);
     280      if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
     281        ERROR1 (67);
     282      mpfr_set_sj (x, MPFR_INTMAX_MIN, MPFR_RNDN);
     283      if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
     284        ERROR1 (68);
     285      mpfr_sub_ui (x, x, 1, MPFR_RNDN);
     286      if (mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
     287        ERROR1 (69);
     288
     289      /* Check negative op */
     290      for (i = 1; i <= 4; i++)
     291        {
     292          int inv;
     293
     294          mpfr_set_si_2exp (x, -i, -2, MPFR_RNDN);
     295          mpfr_rint (y, x, (mpfr_rnd_t) r);
     296          inv = MPFR_NOTZERO (y);
     297          if (!mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r) ^ inv)
     298            ERROR1 (70);
     299          if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
     300            ERROR1 (71);
     301        }
     302    }
    269303
    270304  mpfr_clear (x);
     305  mpfr_clear (y);
    271306#endif
    272307}
    273 
  • tests/tget_flt.c

    diff -Naur mpfr-3.1.2.orig/tests/tget_flt.c mpfr-3.1.2/tests/tget_flt.c
    old new  
    2828main (void)
    2929{
    3030  mpfr_t x, y;
    31   float f, g, infp;
     31  float f, g;
    3232  int i;
     33#if !defined(MPFR_ERRDIVZERO)
     34  float infp;
     35#endif
    3336
     37  tests_start_mpfr ();
     38
     39#if !defined(MPFR_ERRDIVZERO)
     40  /* The definition of DBL_POS_INF involves a division by 0. This makes
     41     "clang -O2 -fsanitize=undefined -fno-sanitize-recover" fail. */
    3442  infp = (float) DBL_POS_INF;
    3543  if (infp * 0.5 != infp)
    3644    {
     
    3846      fprintf (stderr, "(this is probably a compiler bug, please report)\n");
    3947      exit (1);
    4048    }
    41 
    42   tests_start_mpfr ();
     49#endif
    4350
    4451  mpfr_init2 (x, 24);
    4552  mpfr_init2 (y, 24);
     
    353360      printf ("expected %.8e, got %.8e\n", g, f);
    354361      exit (1);
    355362    }
     363#if !defined(MPFR_ERRDIVZERO)
    356364  f = mpfr_get_flt (x, MPFR_RNDN); /* first round to 2^128 (even rule),
    357365                                      thus we should get +Inf */
    358366  g = infp;
     
    376384      printf ("expected %.8e, got %.8e\n", g, f);
    377385      exit (1);
    378386    }
     387#endif
    379388
    380389  mpfr_clear (x);
    381390  mpfr_clear (y);
  • tests/tset_ld.c

    diff -Naur mpfr-3.1.2.orig/tests/tset_ld.c mpfr-3.1.2/tests/tset_ld.c
    old new  
    4747static int
    4848Isnan_ld (long double d)
    4949{
    50   double e = (double) d;
    51   if (DOUBLE_ISNAN (e))
     50  /* Do not convert d to double as this can give an overflow, which
     51     may confuse compilers without IEEE 754 support (such as clang
     52     -fsanitize=undefined), or trigger a trap if enabled.
     53     The DOUBLE_ISNAN macro should work fine on long double. */
     54  if (DOUBLE_ISNAN (d))
    5255    return 1;
    5356  LONGDOUBLE_NAN_ACTION (d, goto yes);
    5457  return 0;
Note: See TracBrowser for help on using the repository browser.