test-isnanl.h | test-isnanl.h | |||
---|---|---|---|---|
/* Test of isnanl() substitute. | /* Test of isnanl() substitute. | |||
Copyright (C) 2007-2010 Free Software Foundation, Inc. | Copyright (C) 2007-2014 Free Software Foundation, Inc. | |||
This program is free software: you can redistribute it and/or modify | This program is free software: you can redistribute it and/or modify | |||
it under the terms of the GNU General Public License as published by | it under the terms of the GNU General Public License as published by | |||
the Free Software Foundation; either version 3 of the License, or | the Free Software Foundation; either version 3 of the License, or | |||
(at your option) any later version. | (at your option) any later version. | |||
This program is distributed in the hope that it will be useful, | This program is distributed in the hope that it will be useful, | |||
but WITHOUT ANY WARRANTY; without even the implied warranty of | but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
GNU General Public License for more details. | GNU General Public License for more details. | |||
You should have received a copy of the GNU General Public License | You should have received a copy of the GNU General Public License | |||
along with this program. If not, see <http://www.gnu.org/licenses/>. * / | along with this program. If not, see <http://www.gnu.org/licenses/>. * / | |||
/* Written by Bruno Haible <bruno@clisp.org>, 2007. */ | /* Written by Bruno Haible <bruno@clisp.org>, 2007. */ | |||
#include <float.h> | #include <float.h> | |||
#include <limits.h> | #include <limits.h> | |||
#include "minus-zero.h" | ||||
#include "infinity.h" | ||||
#include "nan.h" | #include "nan.h" | |||
#include "macros.h" | #include "macros.h" | |||
/* On HP-UX 10.20, negating 0.0L does not yield -0.0L. | ||||
So we use minus_zero instead. | ||||
IRIX cc can't put -0.0L into .data, but can compute at runtime. | ||||
Note that the expression -LDBL_MIN * LDBL_MIN does not work on other | ||||
platforms, such as when cross-compiling to PowerPC on MacOS X 10.5. */ | ||||
#if defined __hpux || defined __sgi | ||||
static long double | ||||
compute_minus_zero (void) | ||||
{ | ||||
return -LDBL_MIN * LDBL_MIN; | ||||
} | ||||
# define minus_zero compute_minus_zero () | ||||
#else | ||||
long double minus_zero = -0.0L; | ||||
#endif | ||||
int | int | |||
main () | main () | |||
{ | { | |||
#define NWORDS \ | #define NWORDS \ | |||
((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)) | ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)) | |||
typedef union { unsigned int word[NWORDS]; long double value; } | typedef union { unsigned int word[NWORDS]; long double value; } | |||
memory_long_double; | memory_long_double; | |||
/* Finite values. */ | /* Finite values. */ | |||
ASSERT (!isnanl (3.141L)); | ASSERT (!isnanl (3.141L)); | |||
ASSERT (!isnanl (3.141e30L)); | ASSERT (!isnanl (3.141e30L)); | |||
ASSERT (!isnanl (3.141e-30L)); | ASSERT (!isnanl (3.141e-30L)); | |||
ASSERT (!isnanl (-2.718L)); | ASSERT (!isnanl (-2.718L)); | |||
ASSERT (!isnanl (-2.718e30L)); | ASSERT (!isnanl (-2.718e30L)); | |||
ASSERT (!isnanl (-2.718e-30L)); | ASSERT (!isnanl (-2.718e-30L)); | |||
ASSERT (!isnanl (0.0L)); | ASSERT (!isnanl (0.0L)); | |||
ASSERT (!isnanl (minus_zero)); | ASSERT (!isnanl (minus_zerol)); | |||
/* Infinite values. */ | /* Infinite values. */ | |||
ASSERT (!isnanl (1.0L / 0.0L)); | ASSERT (!isnanl (Infinityl ())); | |||
ASSERT (!isnanl (-1.0L / 0.0L)); | ASSERT (!isnanl (- Infinityl ())); | |||
/* Quiet NaN. */ | /* Quiet NaN. */ | |||
ASSERT (isnanl (NaNl ())); | ASSERT (isnanl (NaNl ())); | |||
#if defined LDBL_EXPBIT0_WORD && defined LDBL_EXPBIT0_BIT | #if defined LDBL_EXPBIT0_WORD && defined LDBL_EXPBIT0_BIT | |||
/* A bit pattern that is different from a Quiet NaN. With a bit of luck, | /* A bit pattern that is different from a Quiet NaN. With a bit of luck, | |||
it's a Signalling NaN. */ | it's a Signalling NaN. */ | |||
{ | { | |||
#if defined __powerpc__ && LDBL_MANT_DIG == 106 | ||||
/* This is PowerPC "double double", a pair of two doubles. Inf and Nan | ||||
are | ||||
represented as the corresponding 64-bit IEEE values in the first dou | ||||
ble; | ||||
the second is ignored. Manipulate only the first double. */ | ||||
#undef NWORDS | ||||
#define NWORDS \ | ||||
((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int | ||||
)) | ||||
#endif | ||||
memory_long_double m; | memory_long_double m; | |||
m.value = NaNl (); | m.value = NaNl (); | |||
# if LDBL_EXPBIT0_BIT > 0 | # if LDBL_EXPBIT0_BIT > 0 | |||
m.word[LDBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (LDBL_EXPBIT0_BIT - 1) ; | m.word[LDBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (LDBL_EXPBIT0_BIT - 1) ; | |||
# else | # else | |||
m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)] | m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)] | |||
^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1); | ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1); | |||
# endif | # endif | |||
m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)] | m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)] | |||
|= (unsigned int) 1 << LDBL_EXPBIT0_BIT; | |= (unsigned int) 1 << LDBL_EXPBIT0_BIT; | |||
ASSERT (isnanl (m.value)); | ASSERT (isnanl (m.value)); | |||
} | } | |||
#endif | #endif | |||
#if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defi ned __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || d efined _M_IX86 || defined _X86_)) | #if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defi ned __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || d efined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE | |||
/* Representation of an 80-bit 'long double' as an initializer for a sequen ce | /* Representation of an 80-bit 'long double' as an initializer for a sequen ce | |||
of 'unsigned int' words. */ | of 'unsigned int' words. */ | |||
# ifdef WORDS_BIGENDIAN | # ifdef WORDS_BIGENDIAN | |||
# define LDBL80_WORDS(exponent,manthi,mantlo) \ | # define LDBL80_WORDS(exponent,manthi,mantlo) \ | |||
{ ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \ | { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \ | |||
((unsigned int) (manthi) << 16) | (unsigned int) (mantlo) >> 16), \ | ((unsigned int) (manthi) << 16) | (unsigned int) (mantlo) >> 16), \ | |||
(unsigned int) (mantlo) << 16 \ | (unsigned int) (mantlo) << 16 \ | |||
} | } | |||
# else | # else | |||
# define LDBL80_WORDS(exponent,manthi,mantlo) \ | # define LDBL80_WORDS(exponent,manthi,mantlo) \ | |||
End of changes. 7 change blocks. | ||||
21 lines changed or deleted | 19 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |