1 /* Return the least floating-point number greater than X.
2 Copyright (C) 2016 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/>. */
20 #include <math_private.h>
21 #include <math_ldbl_opt.h>
23 /* Return the least floating-point number greater than X. */
25 __nextupl (long double x
)
30 ldbl_unpack (x
, &xhi
, &xlo
);
31 EXTRACT_WORDS64 (hx
, xhi
);
32 EXTRACT_WORDS64 (lx
, xlo
);
33 ihx
= hx
& 0x7fffffffffffffffLL
;
35 if (ihx
> 0x7ff0000000000000LL
) /* x is nan. */
36 return x
+ x
; /* Signal the nan. */
41 if ((hx
== 0x7fefffffffffffffLL
) && (lx
== 0x7c8ffffffffffffeLL
))
43 if ((uint64_t) hx
>= 0xfff0000000000000ULL
)
45 u
= -0x1.fffffffffffff7ffffffffffff8p
+1023L;
48 if (ihx
<= 0x0360000000000000LL
)
49 { /* x <= LDBL_MIN. */
51 if (x
== 0.0L) /* Handle negative LDBL_TRUE_MIN case. */
55 /* If the high double is an exact power of two and the low
56 double is the opposite sign, then 1ulp is one less than
57 what we might determine from the high double. Similarly
58 if X is an exact power of two, and negative, because
59 making it a little larger will result in the exponent
60 decreasing by one and normalisation of the mantissa. */
61 if ((hx
& 0x000fffffffffffffLL
) == 0
62 && ((lx
!= 0 && lx
!= 0x8000000000000000LL
&& (hx
^ lx
) < 0)
63 || ((lx
== 0 || lx
== 0x8000000000000000LL
) && hx
< 0)))
65 if (ihx
< (106LL << 52))
66 { /* ulp will denormal. */
67 INSERT_WORDS64 (yhi
, ihx
& (0x7ffLL
<< 52));
72 INSERT_WORDS64 (yhi
, (ihx
& (0x7ffLL
<< 52)) - (105LL << 52));
78 weak_alias (__nextupl
, nextupl
)