]>
Commit | Line | Data |
---|---|---|
ce6698ea | 1 | /* Helper macros for type generic function implementations within libm. |
2b778ceb | 2 | Copyright (C) 2016-2021 Free Software Foundation, Inc. |
ce6698ea PM |
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 | |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
ce6698ea PM |
18 | |
19 | #ifndef _MATH_TYPE_MACROS | |
20 | #define _MATH_TYPE_MACROS | |
21 | ||
22 | /* Each type imports a header which is expected to | |
23 | define: | |
24 | ||
25 | M_LIT(x) - Paste the type specific suffix onto the constant x. | |
26 | M_MLIT(x) - Paste the type specific suffix used by the macro | |
27 | constants in math.h, i.e M_PI or M_PIl. | |
28 | M_PFX - The prefixed used by float.h macros like FLT_MANT_DIG. | |
29 | M_SUF(x) - Paste the the type specific suffix used by functions | |
30 | i.e expf expl exp. | |
31 | FLOAT - Resolves to the C typename of M_TYPE. | |
32 | CFLOAT - Resolves to the complex typename of M_TYPE. | |
2c46d114 PM |
33 | M_STRTO_NAN - Resolves to the internal libc function which |
34 | converts a string into the appropriate FLOAT nan | |
35 | value. | |
ce6698ea | 36 | |
ce6698ea PM |
37 | declare_mgen_alias(from,to) |
38 | This exposes the appropriate symbol(s) for a | |
a8dce619 JM |
39 | function f of type FLOAT. |
40 | ||
41 | declare_mgen_alias_r(from,to) | |
42 | This exposes the appropriate symbol(s) for a | |
9761bf4d FW |
43 | function f_r of type FLOAT. |
44 | ||
45 | SET_NAN_PAYLOAD(flt, mant) | |
46 | Set the NaN payload bits of the variable FLT of type FLOAT to | |
47 | the mantissa MANT. */ | |
ce6698ea PM |
48 | |
49 | #ifndef M_PFX | |
50 | # error "M_PFX must be defined." | |
51 | #endif | |
52 | #ifndef M_LIT | |
53 | # error "M_LIT must be defined." | |
54 | #endif | |
55 | #ifndef M_MLIT | |
56 | # error "M_MLIT must be defined." | |
57 | #endif | |
58 | #ifndef M_SUF | |
59 | # error "M_SUF must be defined." | |
60 | #endif | |
61 | #ifndef FLOAT | |
62 | # error "FLOAT must be defined." | |
63 | #endif | |
64 | #ifndef CFLOAT | |
65 | # error "CFLOAT must be defined." | |
66 | #endif | |
a8dce619 JM |
67 | #ifndef declare_mgen_alias |
68 | # error "declare_mgen_alias must be defined." | |
69 | #endif | |
70 | #ifndef declare_mgen_alias_r | |
71 | # error "declare_mgen_alias_r must be defined." | |
72 | #endif | |
9761bf4d FW |
73 | #ifndef SET_NAN_PAYLOAD |
74 | # error "SET_NAN_PAYLOAD must be defined." | |
75 | #endif | |
ce6698ea | 76 | |
badba23c | 77 | #ifndef declare_mgen_finite_alias_x |
220622dd WD |
78 | #define declare_mgen_finite_alias_x(from, to) \ |
79 | libm_alias_finite (from, to) | |
badba23c TMQMF |
80 | #endif |
81 | ||
82 | #ifndef declare_mgen_finite_alias_s | |
83 | # define declare_mgen_finite_alias_s(from,to) \ | |
84 | declare_mgen_finite_alias_x (from, to) | |
85 | #endif | |
86 | ||
87 | #ifndef declare_mgen_finite_alias | |
88 | # define declare_mgen_finite_alias(from, to) \ | |
89 | declare_mgen_finite_alias_s (M_SUF (from), M_SUF (to)) | |
90 | #endif | |
91 | ||
ce6698ea PM |
92 | #define __M_CONCAT(a,b) a ## b |
93 | #define __M_CONCATX(a,b) __M_CONCAT(a,b) | |
94 | ||
fc7f4691 | 95 | #define M_NAN M_SUF (__builtin_nan) ("") |
7620dc12 | 96 | #define M_MIN_EXP __M_CONCATX (M_PFX, _MIN_EXP) |
ce6698ea PM |
97 | #define M_MAX_EXP __M_CONCATX (M_PFX, _MAX_EXP) |
98 | #define M_MIN __M_CONCATX (M_PFX, _MIN) | |
99 | #define M_MAX __M_CONCATX (M_PFX, _MAX) | |
100 | #define M_MANT_DIG __M_CONCATX (M_PFX, _MANT_DIG) | |
101 | #define M_HUGE_VAL (M_SUF (__builtin_huge_val) ()) | |
102 | ||
103 | /* Helper macros for commonly used functions. */ | |
81dca813 | 104 | #define M_COPYSIGN M_SUF (copysign) |
ce6698ea PM |
105 | #define M_FABS M_SUF (fabs) |
106 | #define M_SINCOS M_SUF (__sincos) | |
107 | #define M_SCALBN M_SUF (__scalbn) | |
108 | #define M_LOG1P M_SUF (__log1p) | |
109 | ||
110 | #define M_ATAN2 M_SUF (__ieee754_atan2) | |
111 | #define M_COSH M_SUF (__ieee754_cosh) | |
112 | #define M_EXP M_SUF (__ieee754_exp) | |
113 | #define M_HYPOT M_SUF (__ieee754_hypot) | |
114 | #define M_LOG M_SUF (__ieee754_log) | |
115 | #define M_SINH M_SUF (__ieee754_sinh) | |
700593fd | 116 | #define M_SQRT M_SUF (sqrt) |
ce6698ea PM |
117 | |
118 | /* Needed to evaluate M_MANT_DIG below. */ | |
119 | #include <float.h> | |
220622dd | 120 | #include <libm-alias-finite.h> |
ce6698ea PM |
121 | |
122 | /* Use a special epsilon value for IBM long double | |
123 | to avoid spurious overflows/underflows. */ | |
124 | #if M_MANT_DIG != 106 | |
125 | # define M_EPSILON __M_CONCATX (M_PFX, _EPSILON) | |
126 | #else | |
127 | # define M_EPSILON M_LIT (0x1p-106) | |
128 | #endif | |
129 | ||
130 | /* Enable overloading of function name to assist reuse. */ | |
131 | #ifndef M_DECL_FUNC | |
132 | # define M_DECL_FUNC(f) M_SUF (f) | |
133 | #endif | |
134 | ||
ce6698ea | 135 | #endif /* _MATH_TYPE_MACROS */ |