]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/ieee754/dbl-64/math_err.c
c27cd939484a19f2f1ae00c4ab264e52954e6e25
1 /* Double-precision math error handling.
2 Copyright (C) 2018-2019 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-barriers.h>
20 #include "math_config.h"
24 /* NOINLINE reduces code size and avoids making math functions non-leaf
25 when the error handling is inlined. */
26 NOINLINE
static double
27 with_errno (double y
, int e
)
33 #define with_errno(x, e) (x)
36 /* NOINLINE reduces code size. */
37 NOINLINE
static double
38 xflow (uint32_t sign
, double y
)
40 y
= math_opt_barrier (sign
? -y
: y
) * y
;
41 return with_errno (y
, ERANGE
);
44 attribute_hidden
double
45 __math_uflow (uint32_t sign
)
47 return xflow (sign
, 0x1p
-767);
51 /* Underflows to zero in some non-nearest rounding mode, setting errno
52 is valid even if the result is non-zero, but in the subnormal range. */
53 attribute_hidden
double
54 __math_may_uflow (uint32_t sign
)
56 return xflow (sign
, 0x1.8p
-538);
60 attribute_hidden
double
61 __math_oflow (uint32_t sign
)
63 return xflow (sign
, 0x1p
769);
66 attribute_hidden
double
67 __math_divzero (uint32_t sign
)
69 double y
= math_opt_barrier (sign
? -1.0 : 1.0) / 0.0;
70 return with_errno (y
, ERANGE
);
73 attribute_hidden
double
74 __math_invalid (double x
)
76 double y
= (x
- x
) / (x
- x
);
77 return isnan (x
) ? y
: with_errno (y
, EDOM
);
80 /* Check result and set errno if necessary. */
82 attribute_hidden
double
83 __math_check_uflow (double y
)
85 return y
== 0.0 ? with_errno (y
, ERANGE
) : y
;
88 attribute_hidden
double
89 __math_check_oflow (double y
)
91 return isinf (y
) ? with_errno (y
, ERANGE
) : y
;