.
[glibc.git] / sysdeps / m68k / fpu / __math.h
bloba9ae2d966c3a59735459d8bccd9cd5a73c43970a
1 /* Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
19 #ifdef __GNUC__
21 #include <sys/cdefs.h>
23 #ifdef __NO_MATH_INLINES
24 /* This is used when defining the functions themselves. Define them with
25 __ names, and with `static inline' instead of `extern inline' so the
26 bodies will always be used, never an external function call. */
27 #define __m81_u(x) __CONCAT(__,x)
28 #define __m81_inline static __inline
29 #else
30 #define __m81_u(x) x
31 #define __m81_inline exter __inline
32 #define __MATH_INLINES 1
33 #endif
35 #define __inline_mathop2(func, op) \
36 __m81_inline __CONSTVALUE double \
37 __m81_u(func)(double __mathop_x) \
38 { \
39 double __result; \
40 __asm("f" __STRING(op) "%.x %1, %0" : "=f" (__result) : "f" (__mathop_x));\
41 return __result; \
43 #define __inline_mathop(op) __inline_mathop2(op, op)
45 __inline_mathop(acos)
46 __inline_mathop(asin)
47 __inline_mathop(atan)
48 __inline_mathop(cos)
49 __inline_mathop(sin)
50 __inline_mathop(tan)
51 __inline_mathop(cosh)
52 __inline_mathop(sinh)
53 __inline_mathop(tanh)
54 __inline_mathop2(exp, etox)
55 __inline_mathop2(fabs, abs)
56 __inline_mathop(log10)
57 __inline_mathop2(log, logn)
58 __inline_mathop2(floor, intrz)
59 __inline_mathop(sqrt)
61 __inline_mathop2(__rint, int)
62 __inline_mathop2(__expm1, etoxm1)
64 #ifdef __USE_MISC
65 __inline_mathop2(rint, int)
66 __inline_mathop2(expm1, etoxm1)
67 __inline_mathop2(log1p, lognp1)
68 __inline_mathop(atanh)
69 #endif
71 __m81_inline __CONSTVALUE double
72 __m81_u(__drem)(double __x, double __y)
74 double __result;
75 __asm("frem%.x %1, %0" : "=f" (__result) : "f" (__y), "0" (__x));
76 return __result;
79 __m81_inline __CONSTVALUE double
80 __m81_u(ldexp)(double __x, int __e)
82 double __result;
83 double __double_e = (double) __e;
84 __asm("fscale%.x %1, %0" : "=f" (__result) : "f" (__double_e), "0" (__x));
85 return __result;
88 __m81_inline __CONSTVALUE double
89 __m81_u(fmod)(double __x, double __y)
91 double __result;
92 __asm("fmod%.x %1, %0" : "=f" (__result) : "f" (__y), "0" (__x));
93 return __result;
96 __m81_inline double
97 __m81_u(frexp)(double __value, int *__expptr)
99 double __mantissa, __exponent;
100 __asm("fgetexp%.x %1, %0" : "=f" (__exponent) : "f" (__value));
101 __asm("fgetman%.x %1, %0" : "=f" (__mantissa) : "f" (__value));
102 *__expptr = (int) __exponent;
103 return __mantissa;
106 __m81_inline __CONSTVALUE double
107 __m81_u(pow)(double __x, double __y)
109 double __result;
110 if (__y == 0.0 || __x == 1.0)
111 __result = 1.0;
112 else if (__y == 1.0)
113 __result = __x;
114 else if (__y == 2.0)
115 __result = __x * __x;
116 else if (__x == 10.0)
117 __asm("ftentox%.x %1, %0" : "=f" (__result) : "f" (__y));
118 else if (__x == 2.0)
119 __asm("ftwotox%.x %1, %0" : "=f" (__result) : "f" (__y));
120 else
121 __result = __m81_u(exp)(__y * __m81_u(log)(__x));
122 return __result;
125 __m81_inline __CONSTVALUE double
126 __m81_u(ceil)(double __x)
128 double __result;
129 unsigned long int __ctrl_reg;
130 __asm("fmove%.l fpcr, %0" : "=g" (__ctrl_reg));
131 /* Set rounding towards positive infinity. */
132 __asm("fmove%.l %0, fpcr" : /* No outputs. */ : "g" (__ctrl_reg | 0x30));
133 /* Convert X to an integer, using +Inf rounding. */
134 __asm("fint%.x %1, %0" : "=f" (__result) : "f" (__x));
135 /* Restore the previous rounding mode. */
136 __asm("fmove%.l %0, fpcr" : /* No outputs. */ : "g" (__ctrl_reg));
137 return __result;
140 __m81_inline double
141 __m81_u(modf)(double __value, double *__iptr)
143 double __modf_int = __m81_u(floor)(__value);
144 *__iptr = __modf_int;
145 return __value - __modf_int;
148 __m81_inline __CONSTVALUE int
149 __m81_u(__isinf)(double __value)
151 /* There is no branch-condition for infinity,
152 so we must extract and examine the condition codes manually. */
153 unsigned long int __fpsr;
154 __asm("ftst%.x %1\n"
155 "fmove%.l fpsr, %0" : "=g" (__fpsr) : "f" (__value));
156 return (__fpsr & (2 << (3 * 8))) ? (__value < 0 ? -1 : 1) : 0;
159 __m81_inline __CONSTVALUE int
160 __m81_u(__isnan)(double __value)
162 char __result;
163 __asm("ftst%.x %1\n"
164 "fsun %0" : "=g" (__result) : "f" (__value));
165 return __result;
168 #endif /* GCC. */