]>
Commit | Line | Data |
---|---|---|
228a78c2 | 1 | /* Return positive difference between arguments. i386 version. |
688903eb | 2 | Copyright (C) 1997-2018 Free Software Foundation, Inc. |
228a78c2 JM |
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 | |
17 | <http://www.gnu.org/licenses/>. */ | |
18 | ||
19 | #include <errno.h> | |
20 | #include <fpu_control.h> | |
21 | #include <math.h> | |
22 | #include <math_private.h> | |
bc4e8f9b | 23 | #include <libm-alias-double.h> |
228a78c2 JM |
24 | |
25 | double | |
26 | __fdim (double x, double y) | |
27 | { | |
28 | if (islessequal (x, y)) | |
29 | return 0.0; | |
30 | ||
31 | /* To avoid double rounding, set double precision for the | |
32 | subtraction. math_narrow_eval is still needed to eliminate | |
33 | excess range in the case of overflow. If the result of the | |
34 | subtraction is in the subnormal range for double, it is exact, so | |
35 | no issues of double rounding for subnormals arise. */ | |
36 | fpu_control_t cw, cw_double; | |
37 | _FPU_GETCW (cw); | |
38 | cw_double = (cw & ~_FPU_EXTENDED) | _FPU_DOUBLE; | |
39 | _FPU_SETCW (cw_double); | |
40 | double r = math_narrow_eval (x - y); | |
41 | _FPU_SETCW (cw); | |
42 | if (isinf (r) && !isinf (x) && !isinf (y)) | |
43 | __set_errno (ERANGE); | |
44 | ||
45 | return r; | |
46 | } | |
bc4e8f9b | 47 | libm_alias_double (__fdim, fdim) |