2 * Double-precision math error handling.
4 * Copyright (c) 2018, Arm Limited.
5 * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
8 #include "math_config.h"
12 /* NOINLINE reduces code size and avoids making math functions non-leaf
13 when the error handling is inlined. */
14 NOINLINE static double
15 with_errno (double y, int e)
21 #define with_errno(x, e) (x)
24 /* NOINLINE reduces code size. */
25 NOINLINE static double
26 xflow (uint32_t sign, double y)
28 y = eval_as_double (opt_barrier_double (sign ? -y : y) * y);
29 return with_errno (y, ERANGE);
33 __math_uflow (uint32_t sign)
35 return xflow (sign, 0x1p-767);
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_uflow (uint32_t sign)
44 return xflow (sign, 0x1.8p-538);
49 __math_oflow (uint32_t sign)
51 return xflow (sign, 0x1p769);
55 __math_divzero (uint32_t sign)
57 double y = opt_barrier_double (sign ? -1.0 : 1.0) / 0.0;
58 return with_errno (y, ERANGE);
62 __math_invalid (double x)
64 double y = (x - x) / (x - x);
65 return isnan (x) ? y : with_errno (y, EDOM);
68 /* Check result and set errno if necessary. */
71 __math_check_uflow (double y)
73 return y == 0.0 ? with_errno (y, ERANGE) : y;
77 __math_check_oflow (double y)
79 return isinf (y) ? with_errno (y, ERANGE) : y;