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,2004,2006 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #ifndef _MATH_H
00021 # error "Never use <bits/nan.h> directly; include <math.h> instead."
00022 #endif
00023 
00024 
00025 /* IEEE Not A Number.  */
00026 
00027 #if __GNUC_PREREQ(3,3)
00028 
00029 # define NAN  (__builtin_nanf (""))
00030 
00031 #elif defined __GNUC__
00032 
00033 # define NAN \
00034   (__extension__                                                     \
00035    ((union { unsigned __l __attribute__ ((__mode__ (__SI__))); float __d; })  \
00036     { __l: 0x7fc00000UL }).__d)
00037 
00038 #else
00039 
00040 # include <endian.h>
00041 
00042 # if __BYTE_ORDER == __BIG_ENDIAN
00043 #  define __nan_bytes              { 0x7f, 0xc0, 0, 0 }
00044 # endif
00045 # if __BYTE_ORDER == __LITTLE_ENDIAN
00046 #  define __nan_bytes              { 0, 0, 0xc0, 0x7f }
00047 # endif
00048 
00049 static union { unsigned char __c[4]; float __d; } __nan_union
00050     __attribute_used__ = { __nan_bytes };
00051 # define NAN  (__nan_union.__d)
00052 
00053 #endif /* GCC.  */