]>
Commit | Line | Data |
---|---|---|
72aa6233 | 1 | /* Single-precision math error handling. |
6d7e8eda | 2 | Copyright (C) 2017-2023 Free Software Foundation, Inc. |
72aa6233 SN |
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/>. */ |
72aa6233 SN |
18 | |
19 | #include "math_config.h" | |
20 | ||
21 | #if WANT_ERRNO | |
22 | # include <errno.h> | |
23 | /* NOINLINE reduces code size. */ | |
24 | NOINLINE static float | |
25 | with_errnof (float y, int e) | |
26 | { | |
27 | errno = e; | |
28 | return y; | |
29 | } | |
30 | #else | |
31 | # define with_errnof(x, e) (x) | |
32 | #endif | |
33 | ||
16439f41 AZN |
34 | attribute_hidden float |
35 | __math_edomf (float y) | |
36 | { | |
37 | return with_errnof (y, EDOM); | |
38 | } | |
39 | ||
72aa6233 SN |
40 | /* NOINLINE prevents fenv semantics breaking optimizations. */ |
41 | NOINLINE static float | |
2b445206 | 42 | xflowf (uint32_t sign, float y) |
72aa6233 SN |
43 | { |
44 | y = (sign ? -y : y) * y; | |
45 | return with_errnof (y, ERANGE); | |
46 | } | |
47 | ||
48 | attribute_hidden float | |
2b445206 | 49 | __math_uflowf (uint32_t sign) |
72aa6233 SN |
50 | { |
51 | return xflowf (sign, 0x1p-95f); | |
52 | } | |
53 | ||
54 | #if WANT_ERRNO_UFLOW | |
55 | /* Underflows to zero in some non-nearest rounding mode, setting errno | |
56 | is valid even if the result is non-zero, but in the subnormal range. */ | |
57 | attribute_hidden float | |
2b445206 | 58 | __math_may_uflowf (uint32_t sign) |
72aa6233 SN |
59 | { |
60 | return xflowf (sign, 0x1.4p-75f); | |
61 | } | |
62 | #endif | |
63 | ||
64 | attribute_hidden float | |
2b445206 | 65 | __math_oflowf (uint32_t sign) |
72aa6233 SN |
66 | { |
67 | return xflowf (sign, 0x1p97f); | |
68 | } | |
69 | ||
70 | attribute_hidden float | |
2b445206 | 71 | __math_divzerof (uint32_t sign) |
72aa6233 SN |
72 | { |
73 | float y = 0; | |
74 | return with_errnof ((sign ? -1 : 1) / y, ERANGE); | |
75 | } | |
76 | ||
77 | attribute_hidden float | |
78 | __math_invalidf (float x) | |
79 | { | |
80 | float y = (x - x) / (x - x); | |
81 | return isnan (x) ? y : with_errnof (y, EDOM); | |
82 | } |