Blame gettext-tools/gnulib-tests/test-isnanl.h

Packit Bot 06c835
/* Test of isnanl() substitute.
Packit Bot 06c835
   Copyright (C) 2007-2015 Free Software Foundation, Inc.
Packit Bot 06c835
Packit Bot 06c835
   This program is free software: you can redistribute it and/or modify
Packit Bot 06c835
   it under the terms of the GNU General Public License as published by
Packit Bot 06c835
   the Free Software Foundation; either version 3 of the License, or
Packit Bot 06c835
   (at your option) any later version.
Packit Bot 06c835
Packit Bot 06c835
   This program is distributed in the hope that it will be useful,
Packit Bot 06c835
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Bot 06c835
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Bot 06c835
   GNU General Public License for more details.
Packit Bot 06c835
Packit Bot 06c835
   You should have received a copy of the GNU General Public License
Packit Bot 06c835
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit Bot 06c835
Packit Bot 06c835
/* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
Packit Bot 06c835
Packit Bot 06c835
#include <float.h>
Packit Bot 06c835
#include <limits.h>
Packit Bot 06c835
Packit Bot 06c835
#include "minus-zero.h"
Packit Bot 06c835
#include "infinity.h"
Packit Bot 06c835
#include "nan.h"
Packit Bot 06c835
#include "macros.h"
Packit Bot 06c835
Packit Bot 06c835
int
Packit Bot 06c835
main ()
Packit Bot 06c835
{
Packit Bot 06c835
  #define NWORDS \
Packit Bot 06c835
    ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
Packit Bot 06c835
  typedef union { unsigned int word[NWORDS]; long double value; }
Packit Bot 06c835
          memory_long_double;
Packit Bot 06c835
Packit Bot 06c835
  /* Finite values.  */
Packit Bot 06c835
  ASSERT (!isnanl (3.141L));
Packit Bot 06c835
  ASSERT (!isnanl (3.141e30L));
Packit Bot 06c835
  ASSERT (!isnanl (3.141e-30L));
Packit Bot 06c835
  ASSERT (!isnanl (-2.718L));
Packit Bot 06c835
  ASSERT (!isnanl (-2.718e30L));
Packit Bot 06c835
  ASSERT (!isnanl (-2.718e-30L));
Packit Bot 06c835
  ASSERT (!isnanl (0.0L));
Packit Bot 06c835
  ASSERT (!isnanl (minus_zerol));
Packit Bot 06c835
  /* Infinite values.  */
Packit Bot 06c835
  ASSERT (!isnanl (Infinityl ()));
Packit Bot 06c835
  ASSERT (!isnanl (- Infinityl ()));
Packit Bot 06c835
  /* Quiet NaN.  */
Packit Bot 06c835
  ASSERT (isnanl (NaNl ()));
Packit Bot 06c835
Packit Bot 06c835
#if defined LDBL_EXPBIT0_WORD && defined LDBL_EXPBIT0_BIT
Packit Bot 06c835
  /* A bit pattern that is different from a Quiet NaN.  With a bit of luck,
Packit Bot 06c835
     it's a Signalling NaN.  */
Packit Bot 06c835
  {
Packit Bot 06c835
#if defined __powerpc__ && LDBL_MANT_DIG == 106
Packit Bot 06c835
    /* This is PowerPC "double double", a pair of two doubles.  Inf and Nan are
Packit Bot 06c835
       represented as the corresponding 64-bit IEEE values in the first double;
Packit Bot 06c835
       the second is ignored.  Manipulate only the first double.  */
Packit Bot 06c835
    #undef NWORDS
Packit Bot 06c835
    #define NWORDS \
Packit Bot 06c835
      ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
Packit Bot 06c835
#endif
Packit Bot 06c835
Packit Bot 06c835
    memory_long_double m;
Packit Bot 06c835
    m.value = NaNl ();
Packit Bot 06c835
# if LDBL_EXPBIT0_BIT > 0
Packit Bot 06c835
    m.word[LDBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (LDBL_EXPBIT0_BIT - 1);
Packit Bot 06c835
# else
Packit Bot 06c835
    m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
Packit Bot 06c835
      ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
Packit Bot 06c835
# endif
Packit Bot 06c835
    m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
Packit Bot 06c835
      |= (unsigned int) 1 << LDBL_EXPBIT0_BIT;
Packit Bot 06c835
    ASSERT (isnanl (m.value));
Packit Bot 06c835
  }
Packit Bot 06c835
#endif
Packit Bot 06c835
Packit Bot 06c835
#if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
Packit Bot 06c835
/* Representation of an 80-bit 'long double' as an initializer for a sequence
Packit Bot 06c835
   of 'unsigned int' words.  */
Packit Bot 06c835
# ifdef WORDS_BIGENDIAN
Packit Bot 06c835
#  define LDBL80_WORDS(exponent,manthi,mantlo) \
Packit Bot 06c835
     { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
Packit Bot 06c835
       ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16),   \
Packit Bot 06c835
       (unsigned int) (mantlo) << 16                                        \
Packit Bot 06c835
     }
Packit Bot 06c835
# else
Packit Bot 06c835
#  define LDBL80_WORDS(exponent,manthi,mantlo) \
Packit Bot 06c835
     { mantlo, manthi, exponent }
Packit Bot 06c835
# endif
Packit Bot 06c835
  { /* Quiet NaN.  */
Packit Bot 06c835
    static memory_long_double x =
Packit Bot 06c835
      { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
Packit Bot 06c835
    ASSERT (isnanl (x.value));
Packit Bot 06c835
  }
Packit Bot 06c835
  {
Packit Bot 06c835
    /* Signalling NaN.  */
Packit Bot 06c835
    static memory_long_double x =
Packit Bot 06c835
      { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
Packit Bot 06c835
    ASSERT (isnanl (x.value));
Packit Bot 06c835
  }
Packit Bot 06c835
  /* isnanl should return something for noncanonical values.  */
Packit Bot 06c835
  { /* Pseudo-NaN.  */
Packit Bot 06c835
    static memory_long_double x =
Packit Bot 06c835
      { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
Packit Bot 06c835
    ASSERT (isnanl (x.value) || !isnanl (x.value));
Packit Bot 06c835
  }
Packit Bot 06c835
  { /* Pseudo-Infinity.  */
Packit Bot 06c835
    static memory_long_double x =
Packit Bot 06c835
      { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
Packit Bot 06c835
    ASSERT (isnanl (x.value) || !isnanl (x.value));
Packit Bot 06c835
  }
Packit Bot 06c835
  { /* Pseudo-Zero.  */
Packit Bot 06c835
    static memory_long_double x =
Packit Bot 06c835
      { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
Packit Bot 06c835
    ASSERT (isnanl (x.value) || !isnanl (x.value));
Packit Bot 06c835
  }
Packit Bot 06c835
  { /* Unnormalized number.  */
Packit Bot 06c835
    static memory_long_double x =
Packit Bot 06c835
      { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
Packit Bot 06c835
    ASSERT (isnanl (x.value) || !isnanl (x.value));
Packit Bot 06c835
  }
Packit Bot 06c835
  { /* Pseudo-Denormal.  */
Packit Bot 06c835
    static memory_long_double x =
Packit Bot 06c835
      { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
Packit Bot 06c835
    ASSERT (isnanl (x.value) || !isnanl (x.value));
Packit Bot 06c835
  }
Packit Bot 06c835
#endif
Packit Bot 06c835
Packit Bot 06c835
  return 0;
Packit Bot 06c835
}