Back to index

glibc  2.9
s_isnan.c
Go to the documentation of this file.
00001 /* Return 1 if argument is a NaN, else 0.
00002    Copyright (C) 1997, 2000, 2002, 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 /* Ugly kludge to avoid declarations.  */
00021 #define __isnanf __Xisnanf
00022 #define isnanf Xisnanf
00023 #define __GI___isnanf __GI___Xisnanf
00024 
00025 #include "math.h"
00026 #include <math_ldbl_opt.h>
00027 #include <fenv_libc.h>
00028 
00029 #undef __isnanf
00030 #undef isnanf
00031 #undef __GI___isnanf
00032 
00033 
00034 /* The hidden_proto in include/math.h was obscured by the macro hackery.  */
00035 __typeof (__isnan) __isnanf;
00036 hidden_proto (__isnanf)
00037 
00038 
00039 int
00040 __isnan (x)
00041      double x;
00042 {
00043   fenv_t savedstate;
00044   int result;
00045   savedstate = fegetenv_register ();
00046   reset_fpscr_bit (FPSCR_VE);
00047   result = !(x == x);
00048   fesetenv_register (savedstate);
00049   return result;
00050 }
00051 hidden_def (__isnan)
00052 weak_alias (__isnan, isnan)
00053 
00054 
00055 /* It turns out that the 'double' version will also always work for
00056    single-precision.  */
00057 strong_alias (__isnan, __isnanf)
00058 hidden_def (__isnanf)
00059 weak_alias (__isnanf, isnanf)
00060 
00061 #ifdef NO_LONG_DOUBLE
00062 strong_alias (__isnan, __isnanl)
00063 weak_alias (__isnan, isnanl)
00064 #endif