1 | /* Configuration for math routines. |
2 | Copyright (C) 2017-2020 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 | <https://www.gnu.org/licenses/>. */ |
18 | |
19 | #ifndef _MATH_CONFIG_H |
20 | #define _MATH_CONFIG_H |
21 | |
22 | #include <math.h> |
23 | #include <math_private.h> |
24 | #include <nan-high-order-bit.h> |
25 | #include <stdint.h> |
26 | |
27 | #ifndef WANT_ROUNDING |
28 | /* Correct special case results in non-nearest rounding modes. */ |
29 | # define WANT_ROUNDING 1 |
30 | #endif |
31 | #ifndef WANT_ERRNO |
32 | /* Set errno according to ISO C with (math_errhandling & MATH_ERRNO) != 0. */ |
33 | # define WANT_ERRNO 1 |
34 | #endif |
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) |
38 | #endif |
39 | |
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 |
44 | #endif |
45 | |
46 | #if TOINT_INTRINSICS |
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); |
52 | |
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. */ |
56 | static inline int32_t |
57 | converttoint (double_t x); |
58 | #endif |
59 | |
60 | static inline uint32_t |
61 | asuint (float f) |
62 | { |
63 | union |
64 | { |
65 | float f; |
66 | uint32_t i; |
67 | } u = {f}; |
68 | return u.i; |
69 | } |
70 | |
71 | static inline float |
72 | asfloat (uint32_t i) |
73 | { |
74 | union |
75 | { |
76 | uint32_t i; |
77 | float f; |
78 | } u = {i}; |
79 | return u.f; |
80 | } |
81 | |
82 | static inline uint64_t |
83 | asuint64 (double f) |
84 | { |
85 | union |
86 | { |
87 | double f; |
88 | uint64_t i; |
89 | } u = {f}; |
90 | return u.i; |
91 | } |
92 | |
93 | static inline double |
94 | asdouble (uint64_t i) |
95 | { |
96 | union |
97 | { |
98 | uint64_t i; |
99 | double f; |
100 | } u = {i}; |
101 | return u.f; |
102 | } |
103 | |
104 | #define NOINLINE __attribute__ ((noinline)) |
105 | |
106 | attribute_hidden float __math_oflowf (uint32_t); |
107 | attribute_hidden float __math_uflowf (uint32_t); |
108 | attribute_hidden float __math_may_uflowf (uint32_t); |
109 | attribute_hidden float __math_divzerof (uint32_t); |
110 | attribute_hidden float __math_invalidf (float); |
111 | |
112 | /* Shared between expf, exp2f, exp10f, and powf. */ |
113 | #define EXP2F_TABLE_BITS 5 |
114 | #define EXP2F_POLY_ORDER 3 |
115 | extern const struct exp2f_data |
116 | { |
117 | uint64_t tab[1 << EXP2F_TABLE_BITS]; |
118 | double shift_scaled; |
119 | double poly[EXP2F_POLY_ORDER]; |
120 | double shift; |
121 | double invln2_scaled; |
122 | double poly_scaled[EXP2F_POLY_ORDER]; |
123 | } __exp2f_data attribute_hidden; |
124 | |
125 | #define LOGF_TABLE_BITS 4 |
126 | #define LOGF_POLY_ORDER 4 |
127 | extern const struct logf_data |
128 | { |
129 | struct |
130 | { |
131 | double invc, logc; |
132 | } tab[1 << LOGF_TABLE_BITS]; |
133 | double ln2; |
134 | double poly[LOGF_POLY_ORDER - 1]; /* First order coefficient is 1. */ |
135 | } __logf_data attribute_hidden; |
136 | |
137 | #define LOG2F_TABLE_BITS 4 |
138 | #define LOG2F_POLY_ORDER 4 |
139 | extern const struct log2f_data |
140 | { |
141 | struct |
142 | { |
143 | double invc, logc; |
144 | } tab[1 << LOG2F_TABLE_BITS]; |
145 | double poly[LOG2F_POLY_ORDER]; |
146 | } __log2f_data attribute_hidden; |
147 | |
148 | #define POWF_LOG2_TABLE_BITS 4 |
149 | #define POWF_LOG2_POLY_ORDER 5 |
150 | #if TOINT_INTRINSICS |
151 | # define POWF_SCALE_BITS EXP2F_TABLE_BITS |
152 | #else |
153 | # define POWF_SCALE_BITS 0 |
154 | #endif |
155 | #define POWF_SCALE ((double) (1 << POWF_SCALE_BITS)) |
156 | extern const struct powf_log2_data |
157 | { |
158 | struct |
159 | { |
160 | double invc, logc; |
161 | } tab[1 << POWF_LOG2_TABLE_BITS]; |
162 | double poly[POWF_LOG2_POLY_ORDER]; |
163 | } __powf_log2_data attribute_hidden; |
164 | |
165 | #endif |
166 | |