]>
Commit | Line | Data |
---|---|---|
b3539abf | 1 | /* Inline math functions for Alpha. |
bebc4903 RH |
2 | Copyright (C) 1996, 1997, 1999-2001, 2004, 2007 |
3 | Free Software Foundation, Inc. | |
b3539abf UD |
4 | This file is part of the GNU C Library. |
5 | Contributed by David Mosberger-Tang. | |
6 | ||
7 | The GNU C Library is free software; you can redistribute it and/or | |
3214b89b AJ |
8 | modify it under the terms of the GNU Lesser General Public |
9 | License as published by the Free Software Foundation; either | |
10 | version 2.1 of the License, or (at your option) any later version. | |
b3539abf UD |
11 | |
12 | The GNU C Library is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
3214b89b | 15 | Lesser General Public License for more details. |
b3539abf | 16 | |
3214b89b | 17 | You should have received a copy of the GNU Lesser General Public |
ab84e3ff PE |
18 | License along with the GNU C Library. If not, see |
19 | <http://www.gnu.org/licenses/>. */ | |
b3539abf | 20 | |
9ba8164e RH |
21 | #ifndef _MATH_H |
22 | # error "Never use <bits/mathinline.h> directly; include <math.h> instead." | |
23 | #endif | |
24 | ||
c393be3d | 25 | #ifndef __extern_inline |
9ba8164e RH |
26 | # define __MATH_INLINE __inline |
27 | #else | |
8d4fccc4 | 28 | # define __MATH_INLINE __extern_inline |
9ba8164e RH |
29 | #endif |
30 | ||
15d7e992 UD |
31 | #if defined __USE_ISOC99 && defined __GNUC__ && !__GNUC_PREREQ(3,0) |
32 | # undef isgreater | |
33 | # undef isgreaterequal | |
34 | # undef isless | |
35 | # undef islessequal | |
36 | # undef islessgreater | |
37 | # undef isunordered | |
38 | # define isunordered(u, v) \ | |
9ba8164e | 39 | (__extension__ \ |
15d7e992 | 40 | ({ double __r, __u = (u), __v = (v); \ |
9ba8164e | 41 | __asm ("cmptun/su %1,%2,%0\n\ttrapb" \ |
15d7e992 | 42 | : "=&f" (__r) : "f" (__u), "f"(__v)); \ |
9ba8164e | 43 | __r != 0; })) |
6c555ab5 | 44 | #endif /* ISO C99 */ |
9ba8164e | 45 | |
981e63c8 RH |
46 | #if (!defined __NO_MATH_INLINES || defined __LIBC_INTERNAL_MATH_INLINES) \ |
47 | && defined __OPTIMIZE__ | |
b72a1aa9 | 48 | |
a795af47 RH |
49 | #if !__GNUC_PREREQ (4, 0) |
50 | # define __inline_copysign(NAME, TYPE) \ | |
9ba8164e | 51 | __MATH_INLINE TYPE \ |
6d74bdcd | 52 | __NTH (NAME (TYPE __x, TYPE __y)) \ |
9ba8164e RH |
53 | { \ |
54 | TYPE __z; \ | |
55 | __asm ("cpys %1, %2, %0" : "=f" (__z) : "f" (__y), "f" (__x)); \ | |
56 | return __z; \ | |
57 | } | |
58 | ||
6d74bdcd UD |
59 | __inline_copysign (__copysignf, float) |
60 | __inline_copysign (copysignf, float) | |
61 | __inline_copysign (__copysign, double) | |
62 | __inline_copysign (copysign, double) | |
9ba8164e | 63 | |
a795af47 RH |
64 | # undef __inline_copysign |
65 | #endif | |
9ba8164e RH |
66 | |
67 | ||
a795af47 | 68 | #if !__GNUC_PREREQ (2, 8) |
6d74bdcd | 69 | # define __inline_fabs(NAME, TYPE) \ |
9ba8164e | 70 | __MATH_INLINE TYPE \ |
6d74bdcd | 71 | __NTH (NAME (TYPE __x)) \ |
9ba8164e RH |
72 | { \ |
73 | TYPE __z; \ | |
74 | __asm ("cpys $f31, %1, %0" : "=f" (__z) : "f" (__x)); \ | |
75 | return __z; \ | |
76 | } | |
77 | ||
6d74bdcd UD |
78 | __inline_fabs (__fabsf, float) |
79 | __inline_fabs (fabsf, float) | |
80 | __inline_fabs (__fabs, double) | |
81 | __inline_fabs (fabs, double) | |
9ba8164e | 82 | |
6d74bdcd | 83 | # undef __inline_fabs |
9ba8164e RH |
84 | #endif |
85 | ||
d3d5b656 UD |
86 | #ifdef __USE_ISOC99 |
87 | ||
981e63c8 | 88 | /* Test for negative number. Used in the signbit() macro. */ |
6d74bdcd UD |
89 | __MATH_INLINE int |
90 | __NTH (__signbitf (float __x)) | |
981e63c8 | 91 | { |
bebc4903 | 92 | #if !__GNUC_PREREQ (4, 0) |
981e63c8 RH |
93 | __extension__ union { float __f; int __i; } __u = { __f: __x }; |
94 | return __u.__i < 0; | |
bebc4903 RH |
95 | #else |
96 | return __builtin_signbitf (__x); | |
97 | #endif | |
981e63c8 RH |
98 | } |
99 | ||
6d74bdcd UD |
100 | __MATH_INLINE int |
101 | __NTH (__signbit (double __x)) | |
981e63c8 | 102 | { |
bebc4903 | 103 | #if !__GNUC_PREREQ (4, 0) |
981e63c8 RH |
104 | __extension__ union { double __d; long __i; } __u = { __d: __x }; |
105 | return __u.__i < 0; | |
bebc4903 RH |
106 | #else |
107 | return __builtin_signbit (__x); | |
108 | #endif | |
981e63c8 RH |
109 | } |
110 | ||
9ea0d865 RH |
111 | __MATH_INLINE int |
112 | __NTH (__signbitl (long double __x)) | |
113 | { | |
bebc4903 | 114 | #if !__GNUC_PREREQ (4, 0) |
9ea0d865 RH |
115 | __extension__ union { |
116 | long double __d; | |
117 | long __i[sizeof(long double)/sizeof(long)]; | |
118 | } __u = { __d: __x }; | |
119 | return __u.__i[sizeof(long double)/sizeof(long) - 1] < 0; | |
bebc4903 RH |
120 | #else |
121 | return __builtin_signbitl (__x); | |
122 | #endif | |
9ea0d865 RH |
123 | } |
124 | ||
bebc4903 RH |
125 | /* Test for NaN. Used in the isnan() macro. */ |
126 | ||
127 | __MATH_INLINE int | |
128 | __NTH (__isnanf (float __x)) | |
129 | { | |
130 | return isunordered (__x, __x); | |
131 | } | |
132 | ||
133 | __MATH_INLINE int | |
134 | __NTH (__isnan (double __x)) | |
135 | { | |
136 | return isunordered (__x, __x); | |
137 | } | |
138 | ||
91d46f8a | 139 | #ifndef __NO_LONG_DOUBLE_MATH |
bebc4903 RH |
140 | __MATH_INLINE int |
141 | __NTH (__isnanl (long double __x)) | |
142 | { | |
143 | return isunordered (__x, __x); | |
144 | } | |
91d46f8a RH |
145 | #endif |
146 | ||
b72a1aa9 UD |
147 | #endif /* C99 */ |
148 | ||
149 | #endif /* __NO_MATH_INLINES */ |