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