]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/ieee754/flt-32/math_config.h
New generic logf
[thirdparty/glibc.git] / sysdeps / ieee754 / flt-32 / math_config.h
1 /* Configuration for math routines.
2 Copyright (C) 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_CONFIG_H
20 #define _MATH_CONFIG_H
21
22 #include <math.h>
23 #include <math_private.h>
24 #include <stdint.h>
25
26 #ifndef WANT_ROUNDING
27 /* Correct special case results in non-nearest rounding modes. */
28 # define WANT_ROUNDING 1
29 #endif
30 #ifndef WANT_ERRNO
31 /* Set errno according to ISO C with (math_errhandling & MATH_ERRNO) != 0. */
32 # define WANT_ERRNO 1
33 #endif
34 #ifndef WANT_ERRNO_UFLOW
35 /* Set errno to ERANGE if result underflows to 0 (in all rounding modes). */
36 # define WANT_ERRNO_UFLOW (WANT_ROUNDING && WANT_ERRNO)
37 #endif
38
39 #ifndef TOINT_INTRINSICS
40 # define TOINT_INTRINSICS 0
41 #endif
42 #ifndef TOINT_RINT
43 # define TOINT_RINT 0
44 #endif
45 #ifndef TOINT_SHIFT
46 # define TOINT_SHIFT 1
47 #endif
48
49 static inline uint32_t
50 asuint (float f)
51 {
52 union
53 {
54 float f;
55 uint32_t i;
56 } u = {f};
57 return u.i;
58 }
59
60 static inline float
61 asfloat (uint32_t i)
62 {
63 union
64 {
65 uint32_t i;
66 float f;
67 } u = {i};
68 return u.f;
69 }
70
71 static inline uint64_t
72 asuint64 (double f)
73 {
74 union
75 {
76 double f;
77 uint64_t i;
78 } u = {f};
79 return u.i;
80 }
81
82 static inline double
83 asdouble (uint64_t i)
84 {
85 union
86 {
87 uint64_t i;
88 double f;
89 } u = {i};
90 return u.f;
91 }
92
93 #define NOINLINE __attribute__ ((noinline))
94
95 attribute_hidden float __math_oflowf (unsigned long);
96 attribute_hidden float __math_uflowf (unsigned long);
97 attribute_hidden float __math_may_uflowf (unsigned long);
98 attribute_hidden float __math_divzerof (unsigned long);
99 attribute_hidden float __math_invalidf (float);
100
101 /* Shared between expf, exp2f and powf. */
102 #define EXP2F_TABLE_BITS 5
103 #define EXP2F_POLY_ORDER 3
104 extern const struct exp2f_data
105 {
106 uint64_t tab[1 << EXP2F_TABLE_BITS];
107 double shift_scaled;
108 double poly[EXP2F_POLY_ORDER];
109 double shift;
110 double invln2_scaled;
111 double poly_scaled[EXP2F_POLY_ORDER];
112 } __exp2f_data attribute_hidden;
113
114 #define LOGF_TABLE_BITS 4
115 #define LOGF_POLY_ORDER 4
116 extern const struct logf_data
117 {
118 struct
119 {
120 double invc, logc;
121 } tab[1 << LOGF_TABLE_BITS];
122 double ln2;
123 double poly[LOGF_POLY_ORDER - 1]; /* First order coefficient is 1. */
124 } __logf_data attribute_hidden;
125
126 #endif