Back to index

glibc  2.9
nan.h
Go to the documentation of this file.
00001 /* `NAN' constant for IEEE 754 machines.
00002    Copyright (C) 1992, 1996, 1997, 1999, 2002, 2004
00003    Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #ifndef _MATH_H
00022 # error "Never use <bits/nan.h> directly; include <math.h> instead."
00023 #endif
00024 
00025 
00026 /* IEEE Not A Number (QNaN). Note that MIPS has the QNaN and SNaN patterns
00027    reversed compared to most other architectures. The IEEE spec left
00028    the definition of this open to implementations, and for MIPS the top
00029    bit of the mantissa must be SET to indicate a SNaN.  */
00030 
00031 #if __GNUC_PREREQ(3,3)
00032 
00033 # define NAN  (__builtin_nanf(""))
00034 
00035 #elif defined __GNUC__
00036 
00037 # define NAN \
00038   (__extension__                                                            \
00039    ((union { unsigned __l __attribute__((__mode__(__SI__))); float __d; })  \
00040     { __l: 0x7fbfffffUL }).__d)
00041 
00042 #else
00043 
00044 # include <endian.h>
00045 
00046 # if __BYTE_ORDER == __BIG_ENDIAN
00047 #  define __nan_bytes              { 0x7f, 0xbf, 0xff, 0xff }
00048 # endif
00049 # if __BYTE_ORDER == __LITTLE_ENDIAN
00050 #  define __nan_bytes              { 0xff, 0xff, 0xbf, 0x7f }
00051 # endif
00052 
00053 static union { unsigned char __c[4]; float __d; } __nan_union = { __nan_bytes };
00054 # define NAN  (__nan_union.__d)
00055 
00056 #endif /* GCC.  */