Back to index

glibc  2.9
mathinline.h
Go to the documentation of this file.
00001 /* Inline math functions for Alpha.
00002    Copyright (C) 1996, 1997, 1999-2001, 2004, 2007
00003    Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005    Contributed by David Mosberger-Tang.
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 #ifndef _MATH_H
00023 # error "Never use <bits/mathinline.h> directly; include <math.h> instead."
00024 #endif
00025 
00026 #ifndef __extern_inline
00027 # define __MATH_INLINE __inline
00028 #else
00029 # define __MATH_INLINE __extern_inline
00030 #endif
00031 
00032 #if defined __USE_ISOC99 && defined __GNUC__ && !__GNUC_PREREQ(3,0)
00033 # undef isgreater
00034 # undef isgreaterequal
00035 # undef isless
00036 # undef islessequal
00037 # undef islessgreater
00038 # undef isunordered
00039 # define isunordered(u, v)                       \
00040   (__extension__                                 \
00041    ({ double __r, __u = (u), __v = (v);                 \
00042       __asm ("cmptun/su %1,%2,%0\n\ttrapb"              \
00043             : "=&f" (__r) : "f" (__u), "f"(__v));       \
00044       __r != 0; }))
00045 #endif /* ISO C99 */
00046 
00047 #if (!defined __NO_MATH_INLINES || defined __LIBC_INTERNAL_MATH_INLINES) \
00048     && defined __OPTIMIZE__
00049 
00050 #if !__GNUC_PREREQ (4, 0)
00051 # define __inline_copysign(NAME, TYPE)                                \
00052 __MATH_INLINE TYPE                                             \
00053 __NTH (NAME (TYPE __x, TYPE __y))                              \
00054 {                                                              \
00055   TYPE __z;                                                    \
00056   __asm ("cpys %1, %2, %0" : "=f" (__z) : "f" (__y), "f" (__x));      \
00057   return __z;                                                  \
00058 }
00059 
00060 __inline_copysign (__copysignf, float)
00061 __inline_copysign (copysignf, float)
00062 __inline_copysign (__copysign, double)
00063 __inline_copysign (copysign, double)
00064 
00065 # undef __inline_copysign
00066 #endif
00067 
00068 
00069 #if !__GNUC_PREREQ (2, 8)
00070 # define __inline_fabs(NAME, TYPE)               \
00071 __MATH_INLINE TYPE                               \
00072 __NTH (NAME (TYPE __x))                                 \
00073 {                                                \
00074   TYPE __z;                                      \
00075   __asm ("cpys $f31, %1, %0" : "=f" (__z) : "f" (__x)); \
00076   return __z;                                    \
00077 }
00078 
00079 __inline_fabs (__fabsf, float)
00080 __inline_fabs (fabsf, float)
00081 __inline_fabs (__fabs, double)
00082 __inline_fabs (fabs, double)
00083 
00084 # undef __inline_fabs
00085 #endif
00086 
00087 #ifdef __USE_ISOC99
00088 
00089 /* Test for negative number.  Used in the signbit() macro.  */
00090 __MATH_INLINE int
00091 __NTH (__signbitf (float __x))
00092 {
00093 #if !__GNUC_PREREQ (4, 0)
00094   __extension__ union { float __f; int __i; } __u = { __f: __x };
00095   return __u.__i < 0;
00096 #else
00097   return __builtin_signbitf (__x);
00098 #endif
00099 }
00100 
00101 __MATH_INLINE int
00102 __NTH (__signbit (double __x))
00103 {
00104 #if !__GNUC_PREREQ (4, 0)
00105   __extension__ union { double __d; long __i; } __u = { __d: __x };
00106   return __u.__i < 0;
00107 #else
00108   return __builtin_signbit (__x);
00109 #endif
00110 }
00111 
00112 __MATH_INLINE int
00113 __NTH (__signbitl (long double __x))
00114 {
00115 #if !__GNUC_PREREQ (4, 0)
00116   __extension__ union {
00117     long double __d;
00118     long __i[sizeof(long double)/sizeof(long)];
00119   } __u = { __d: __x };
00120   return __u.__i[sizeof(long double)/sizeof(long) - 1] < 0;
00121 #else
00122   return __builtin_signbitl (__x);
00123 #endif
00124 }
00125 
00126 /* Test for NaN.  Used in the isnan() macro.  */
00127 
00128 __MATH_INLINE int
00129 __NTH (__isnanf (float __x))
00130 {
00131   return isunordered (__x, __x);
00132 }
00133 
00134 __MATH_INLINE int
00135 __NTH (__isnan (double __x))
00136 {
00137   return isunordered (__x, __x);
00138 }
00139 
00140 #ifndef __NO_LONG_DOUBLE_MATH
00141 __MATH_INLINE int
00142 __NTH (__isnanl (long double __x))
00143 {
00144   return isunordered (__x, __x);
00145 }
00146 #endif
00147 
00148 #endif /* C99 */
00149 
00150 #endif /* __NO_MATH_INLINES */