1 /* Configuration for math routines.
2 Copyright (C) 2017-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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 <https://www.gnu.org/licenses/>. */
19 #ifndef _MATH_CONFIG_H
20 #define _MATH_CONFIG_H
23 #include <math_private.h>
24 #include <nan-high-order-bit.h>
28 /* Correct special case results in non-nearest rounding modes. */
29 # define WANT_ROUNDING 1
32 /* Set errno according to ISO C with (math_errhandling & MATH_ERRNO) != 0. */
35 #ifndef WANT_ERRNO_UFLOW
36 /* Set errno to ERANGE if result underflows to 0 (in all rounding modes). */
37 # define WANT_ERRNO_UFLOW (WANT_ROUNDING && WANT_ERRNO)
40 #ifndef TOINT_INTRINSICS
41 /* When set, the roundtoint and converttoint functions are provided with
42 the semantics documented below. */
43 # define TOINT_INTRINSICS 0
47 /* Round x to nearest int in all rounding modes, ties have to be rounded
48 consistently with converttoint so the results match. If the result
49 would be outside of [-2^31, 2^31-1] then the semantics is unspecified. */
50 static inline double_t
51 roundtoint (double_t x
);
53 /* Convert x to nearest int in all rounding modes, ties have to be rounded
54 consistently with roundtoint. If the result is not representible in an
55 int32_t then the semantics is unspecified. */
57 converttoint (double_t x
);
60 static inline uint32_t
82 static inline uint64_t
105 issignalingf_inline (float x
)
107 uint32_t ix
= asuint (x
);
108 if (HIGH_ORDER_BIT_IS_SET_FOR_SNAN
)
109 return (ix
& 0x7fc00000) == 0x7fc00000;
110 return 2 * (ix
^ 0x00400000) > 2 * 0x7fc00000UL
;
114 #define MANTISSA_WIDTH 23
115 #define EXPONENT_WIDTH 8
116 #define MANTISSA_MASK 0x007fffff
117 #define EXPONENT_MASK 0x7f800000
118 #define EXP_MANT_MASK 0x7fffffff
119 #define QUIET_NAN_MASK 0x00400000
120 #define SIGN_MASK 0x80000000
125 return (x
& EXP_MANT_MASK
) > EXPONENT_MASK
;
128 static inline uint32_t
129 get_mantissa (uint32_t x
)
131 return x
& MANTISSA_MASK
;
134 /* Convert integer number X, unbiased exponent EP, and sign S to double:
136 result = X * 2^(EP+1 - exponent_bias)
138 NB: zero is not supported. */
140 make_float (uint32_t x
, int ep
, uint32_t s
)
142 int lz
= __builtin_clz (x
) - EXPONENT_WIDTH
;
146 if (__glibc_unlikely (ep
< 0 || x
== 0))
151 return asfloat (s
+ x
+ (ep
<< MANTISSA_WIDTH
));
154 #define NOINLINE __attribute__ ((noinline))
156 attribute_hidden
float __math_oflowf (uint32_t);
157 attribute_hidden
float __math_uflowf (uint32_t);
158 attribute_hidden
float __math_may_uflowf (uint32_t);
159 attribute_hidden
float __math_divzerof (uint32_t);
160 attribute_hidden
float __math_invalidf (float);
161 attribute_hidden
float __math_edomf (float x
);
163 /* Shared between expf, exp2f, exp10f, and powf. */
164 #define EXP2F_TABLE_BITS 5
165 #define EXP2F_POLY_ORDER 3
166 extern const struct exp2f_data
168 uint64_t tab
[1 << EXP2F_TABLE_BITS
];
170 double poly
[EXP2F_POLY_ORDER
];
172 double invln2_scaled
;
173 double poly_scaled
[EXP2F_POLY_ORDER
];
174 } __exp2f_data attribute_hidden
;
176 #define LOGF_TABLE_BITS 4
177 #define LOGF_POLY_ORDER 4
178 extern const struct logf_data
183 } tab
[1 << LOGF_TABLE_BITS
];
185 double poly
[LOGF_POLY_ORDER
- 1]; /* First order coefficient is 1. */
186 } __logf_data attribute_hidden
;
188 #define LOG2F_TABLE_BITS 4
189 #define LOG2F_POLY_ORDER 4
190 extern const struct log2f_data
195 } tab
[1 << LOG2F_TABLE_BITS
];
196 double poly
[LOG2F_POLY_ORDER
];
197 } __log2f_data attribute_hidden
;
199 #define POWF_LOG2_TABLE_BITS 4
200 #define POWF_LOG2_POLY_ORDER 5
202 # define POWF_SCALE_BITS EXP2F_TABLE_BITS
204 # define POWF_SCALE_BITS 0
206 #define POWF_SCALE ((double) (1 << POWF_SCALE_BITS))
207 extern const struct powf_log2_data
212 } tab
[1 << POWF_LOG2_TABLE_BITS
];
213 double poly
[POWF_LOG2_POLY_ORDER
];
214 } __powf_log2_data attribute_hidden
;