1/* Entry points to finite-math-only compiler runs.
2 Copyright (C) 2011-2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _MATH_H
20# error "Never use <bits/math-finite.h> directly; include <math.h> instead."
21#endif
22
23#define __REDIRFROM_X(function, reentrant, suffix) \
24 function ## suffix ## reentrant
25#define __REDIRFROM(...) __REDIRFROM_X(__VA_ARGS__)
26
27/* Redirect long double versions of the functions to the corresponding
28 double version if __NO_LONG_DOUBLE_MATH is defined. */
29#if __MATH_DECLARING_LDOUBLE && defined __NO_LONG_DOUBLE_MATH
30# define __REDIRTO_X(function, reentrant, suffix) \
31 __ ## function ## reentrant ## _finite
32#else
33# define __REDIRTO_X(function, reentrant, suffix) \
34 __ ## function ## suffix ## reentrant ## _finite
35#endif
36#define __REDIRTO(...) __REDIRTO_X(__VA_ARGS__)
37
38#define __MATH_REDIRCALL_X(from, args, to) \
39 extern _Mdouble_ __REDIRECT_NTH (from, args, to)
40#define __MATH_REDIRCALL(function, reentrant, args) \
41 __MATH_REDIRCALL_X \
42 (__REDIRFROM (function, reentrant, _MSUF_), args, \
43 __REDIRTO (function, reentrant, _MSUF_))
44#define __MATH_REDIRCALL_2(from, reentrant, args, to) \
45 __MATH_REDIRCALL_X \
46 (__REDIRFROM (from, reentrant, _MSUF_), args, \
47 __REDIRTO (to, reentrant, _MSUF_))
48
49#define __MATH_REDIRCALL_INTERNAL(function, reentrant, args) \
50 __MATH_REDIRCALL_X \
51 (__REDIRFROM (__CONCAT (__, function), \
52 __CONCAT (reentrant, _finite), _MSUF_), \
53 args, __REDIRTO (function, _r, _MSUF_))
54
55
56/* acos. */
57__MATH_REDIRCALL (acos, , (_Mdouble_));
58
59#if defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99
60/* acosh. */
61__MATH_REDIRCALL (acosh, , (_Mdouble_));
62#endif
63
64/* asin. */
65__MATH_REDIRCALL (asin, , (_Mdouble_));
66
67/* atan2. */
68__MATH_REDIRCALL (atan2, , (_Mdouble_, _Mdouble_));
69
70#if defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99
71/* atanh. */
72__MATH_REDIRCALL (atanh, , (_Mdouble_));
73#endif
74
75/* cosh. */
76__MATH_REDIRCALL (cosh, , (_Mdouble_));
77
78/* exp. */
79__MATH_REDIRCALL (exp, , (_Mdouble_));
80
81#ifdef __USE_GNU
82/* exp10. */
83__MATH_REDIRCALL (exp10, , (_Mdouble_));
84
85/* pow10. */
86# if !__MATH_DECLARING_FLOATN
87__MATH_REDIRCALL_2 (pow10, , (_Mdouble_), exp10);
88# endif
89#endif
90
91#ifdef __USE_ISOC99
92/* exp2. */
93__MATH_REDIRCALL (exp2, , (_Mdouble_));
94#endif
95
96/* fmod. */
97__MATH_REDIRCALL (fmod, , (_Mdouble_, _Mdouble_));
98
99#if defined __USE_XOPEN || defined __USE_ISOC99
100/* hypot. */
101__MATH_REDIRCALL (hypot, , (_Mdouble_, _Mdouble_));
102#endif
103
104#if (__MATH_DECLARING_DOUBLE && (defined __USE_MISC || defined __USE_XOPEN)) \
105 || (!__MATH_DECLARING_DOUBLE && defined __USE_MISC)
106/* j0. */
107__MATH_REDIRCALL (j0, , (_Mdouble_));
108
109/* y0. */
110__MATH_REDIRCALL (y0, , (_Mdouble_));
111
112/* j1. */
113__MATH_REDIRCALL (j1, , (_Mdouble_));
114
115/* y1. */
116__MATH_REDIRCALL (y1, , (_Mdouble_));
117
118/* jn. */
119__MATH_REDIRCALL (jn, , (int, _Mdouble_));
120
121/* yn. */
122__MATH_REDIRCALL (yn, , (int, _Mdouble_));
123#endif
124
125#ifdef __USE_MISC
126/* lgamma_r. */
127__MATH_REDIRCALL (lgamma, _r, (_Mdouble_, int *));
128#endif
129
130/* Redirect __lgammal_r_finite to __lgamma_r_finite when __NO_LONG_DOUBLE_MATH
131 is set and to itself otherwise. It also redirects __lgamma_r_finite and
132 __lgammaf_r_finite to themselves. */
133__MATH_REDIRCALL_INTERNAL (lgamma, _r, (_Mdouble_, int *));
134
135#if ((defined __USE_XOPEN || defined __USE_ISOC99) \
136 && defined __extern_always_inline)
137/* lgamma. */
138__extern_always_inline _Mdouble_
139__NTH (__REDIRFROM (lgamma, , _MSUF_) (_Mdouble_ __d))
140{
141# if defined __USE_MISC || defined __USE_XOPEN
142 return __REDIRTO (lgamma, _r, _MSUF_) (__d, &signgam);
143# else
144 int __local_signgam = 0;
145 return __REDIRTO (lgamma, _r, _MSUF_) (__d, &__local_signgam);
146# endif
147}
148#endif
149
150#if ((defined __USE_MISC || (defined __USE_XOPEN && !defined __USE_XOPEN2K)) \
151 && defined __extern_always_inline) && !__MATH_DECLARING_FLOATN
152/* gamma. */
153__extern_always_inline _Mdouble_
154__NTH (__REDIRFROM (gamma, , _MSUF_) (_Mdouble_ __d))
155{
156 return __REDIRTO (lgamma, _r, _MSUF_) (__d, &signgam);
157}
158#endif
159
160/* log. */
161__MATH_REDIRCALL (log, , (_Mdouble_));
162
163/* log10. */
164__MATH_REDIRCALL (log10, , (_Mdouble_));
165
166#ifdef __USE_ISOC99
167/* log2. */
168__MATH_REDIRCALL (log2, , (_Mdouble_));
169#endif
170
171/* pow. */
172__MATH_REDIRCALL (pow, , (_Mdouble_, _Mdouble_));
173
174#if defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99
175/* remainder. */
176__MATH_REDIRCALL (remainder, , (_Mdouble_, _Mdouble_));
177#endif
178
179#if ((__MATH_DECLARING_DOUBLE \
180 && (defined __USE_MISC \
181 || (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8))) \
182 || (!defined __MATH_DECLARE_LDOUBLE && defined __USE_MISC)) \
183 && !__MATH_DECLARING_FLOATN
184/* scalb. */
185__MATH_REDIRCALL (scalb, , (_Mdouble_, _Mdouble_));
186#endif
187
188/* sinh. */
189__MATH_REDIRCALL (sinh, , (_Mdouble_));
190
191/* sqrt. */
192__MATH_REDIRCALL (sqrt, , (_Mdouble_));
193
194#if defined __USE_ISOC99 && defined __extern_always_inline
195/* tgamma. */
196extern _Mdouble_
197__REDIRFROM (__gamma, _r_finite, _MSUF_) (_Mdouble_, int *);
198
199__extern_always_inline _Mdouble_
200__NTH (__REDIRFROM (tgamma, , _MSUF_) (_Mdouble_ __d))
201{
202 int __local_signgam = 0;
203 _Mdouble_ __res = __REDIRTO (gamma, _r, _MSUF_) (__d, &__local_signgam);
204 return __local_signgam < 0 ? -__res : __res;
205}
206#endif
207
208#undef __REDIRFROM
209#undef __REDIRFROM_X
210#undef __REDIRTO
211#undef __REDIRTO_X
212#undef __MATH_REDIRCALL
213#undef __MATH_REDIRCALL_2
214#undef __MATH_REDIRCALL_INTERNAL
215#undef __MATH_REDIRCALL_X
216