Back to index

glibc  2.9
s_fpclassifyl.c
Go to the documentation of this file.
00001 /* Return classification value corresponding to argument.
00002    Copyright (C) 1997,1999,2002,2004,2006,2007 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997 and
00005                 Jakub Jelinek <jj@ultra.linux.cz>, 1999.
00006 
00007    The GNU C Library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Lesser General Public
00009    License as published by the Free Software Foundation; either
00010    version 2.1 of the License, or (at your option) any later version.
00011 
00012    The GNU C Library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Lesser General Public License for more details.
00016 
00017    You should have received a copy of the GNU Lesser General Public
00018    License along with the GNU C Library; if not, write to the Free
00019    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00020    02111-1307 USA.  */
00021 
00022 #include <math.h>
00023 
00024 #include "math_private.h"
00025 #include <math_ldbl_opt.h>
00026 
00027   /*
00028    *          hx                  lx
00029    * +NaN     7ffn nnnn nnnn nnnn xxxx xxxx xxxx xxxx
00030    * -NaN     fffn nnnn nnnn nnnn xxxx xxxx xxxx xxxx
00031    * +Inf     7ff0 0000 0000 0000 xxxx xxxx xxxx xxxx
00032    * -Inf     fff0 0000 0000 0000 xxxx xxxx xxxx xxxx
00033    * +0              0000 0000 0000 0000 xxxx xxxx xxxx xxxx
00034    * -0              8000 0000 0000 0000 xxxx xxxx xxxx xxxx
00035    * +normal  0360 0000 0000 0000 0000 0000 0000 0000 (smallest)
00036    * -normal  8360 0000 0000 0000 0000 0000 0000 0000 (smallest)
00037    * +normal  7fef ffff ffff ffff 7c8f ffff ffff fffe (largest)
00038    * +normal  ffef ffff ffff ffff fc8f ffff ffff fffe (largest)
00039    * +denorm  0360 0000 0000 0000 8000 0000 0000 0001 (largest)
00040    * -denorm  8360 0000 0000 0000 0000 0000 0000 0001 (largest)
00041    * +denorm  000n nnnn nnnn nnnn xxxx xxxx xxxx xxxx
00042    * -denorm  800n nnnn nnnn nnnn xxxx xxxx xxxx xxxx
00043    */
00044 
00045 int
00046 ___fpclassifyl (long double x)
00047 {
00048   u_int64_t hx, lx;
00049   int retval = FP_NORMAL;
00050 
00051   GET_LDOUBLE_WORDS64 (hx, lx, x);
00052   if ((hx & 0x7ff0000000000000ULL) == 0x7ff0000000000000ULL) {
00053       /* +/-NaN or +/-Inf */
00054       if (hx & 0x000fffffffffffffULL) {
00055          /* +/-NaN */
00056          retval = FP_NAN;
00057       } else {
00058          retval = FP_INFINITE;
00059       }
00060   } else {
00061       /* +/-zero or +/- normal or +/- denormal */
00062       if (hx & 0x7fffffffffffffffULL) {
00063          /* +/- normal or +/- denormal */
00064          if ((hx & 0x7ff0000000000000ULL) > 0x0360000000000000ULL) {
00065              /* +/- normal */
00066              retval = FP_NORMAL;
00067          } else {
00068              if ((hx & 0x7ff0000000000000ULL) == 0x0360000000000000ULL) {
00069                 if ((lx & 0x7fffffffffffffff)    /* lower is non-zero */
00070                 && ((lx^hx) & 0x8000000000000000ULL)) { /* and sign differs */
00071                     /* +/- denormal */
00072                     retval = FP_SUBNORMAL;
00073                 } else {
00074                     /* +/- normal */
00075                     retval = FP_NORMAL;
00076                 }
00077              } else {
00078                 /* +/- denormal */
00079                 retval = FP_SUBNORMAL;
00080              }
00081          }
00082       } else {
00083          /* +/- zero */
00084          retval = FP_ZERO;
00085       }
00086   }
00087 
00088   return retval;
00089 }
00090 long_double_symbol (libm, ___fpclassifyl, __fpclassifyl);
00091 #ifdef __LONG_DOUBLE_MATH_OPTIONAL
00092 libm_hidden_ver (___fpclassifyl, __fpclassifyl)
00093 #else
00094 libm_hidden_def (__fpclassifyl)
00095 #endif