Optimized generic expf and exp2f with wrappers
[glibc.git] / sysdeps / ieee754 / flt-32 / math_errf.c
blobab546e24cfdda661967c2297b1bc8c6195790f83
1 /* Single-precision math error handling.
2 Copyright (C) 2017 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 <http://www.gnu.org/licenses/>. */
19 #include "math_config.h"
21 #if WANT_ERRNO
22 # include <errno.h>
23 /* NOINLINE reduces code size. */
24 NOINLINE static float
25 with_errnof (float y, int e)
27 errno = e;
28 return y;
30 #else
31 # define with_errnof(x, e) (x)
32 #endif
34 /* NOINLINE prevents fenv semantics breaking optimizations. */
35 NOINLINE static float
36 xflowf (unsigned long sign, float y)
38 y = (sign ? -y : y) * y;
39 return with_errnof (y, ERANGE);
42 attribute_hidden float
43 __math_uflowf (unsigned long sign)
45 return xflowf (sign, 0x1p-95f);
48 #if WANT_ERRNO_UFLOW
49 /* Underflows to zero in some non-nearest rounding mode, setting errno
50 is valid even if the result is non-zero, but in the subnormal range. */
51 attribute_hidden float
52 __math_may_uflowf (unsigned long sign)
54 return xflowf (sign, 0x1.4p-75f);
56 #endif
58 attribute_hidden float
59 __math_oflowf (unsigned long sign)
61 return xflowf (sign, 0x1p97f);
64 attribute_hidden float
65 __math_divzerof (unsigned long sign)
67 float y = 0;
68 return with_errnof ((sign ? -1 : 1) / y, ERANGE);
71 attribute_hidden float
72 __math_invalidf (float x)
74 float y = (x - x) / (x - x);
75 return isnan (x) ? y : with_errnof (y, EDOM);