2 * Single-precision math error handling.
4 * Copyright (c) 2017-2020, Arm Limited.
5 * SPDX-License-Identifier: MIT
8 #include "math_config.h"
12 /* NOINLINE reduces code size and avoids making math functions non-leaf
13 when the error handling is inlined. */
15 with_errnof (float y, int e)
21 #define with_errnof(x, e) (x)
24 /* NOINLINE reduces code size. */
26 xflowf (uint32_t sign, float y)
28 y = eval_as_float (opt_barrier_float (sign ? -y : y) * y);
29 return with_errnof (y, ERANGE);
33 __math_uflowf (uint32_t sign)
35 return xflowf (sign, 0x1p-95f);
39 /* Underflows to zero in some non-nearest rounding mode, setting errno
40 is valid even if the result is non-zero, but in the subnormal range. */
42 __math_may_uflowf (uint32_t sign)
44 return xflowf (sign, 0x1.4p-75f);
49 __math_oflowf (uint32_t sign)
51 return xflowf (sign, 0x1p97f);
55 __math_divzerof (uint32_t sign)
57 float y = opt_barrier_float (sign ? -1.0f : 1.0f) / 0.0f;
58 return with_errnof (y, ERANGE);
62 __math_invalidf (float x)
64 float y = (x - x) / (x - x);
65 return isnan (x) ? y : with_errnof (y, EDOM);
68 /* Check result and set errno if necessary. */
71 __math_check_uflowf (float y)
73 return y == 0.0f ? with_errnof (y, ERANGE) : y;
77 __math_check_oflowf (float y)
79 return isinf (y) ? with_errnof (y, ERANGE) : y;