1/* Return the least floating-point number greater than X.
2 Copyright (C) 2016-2018 Free Software Foundation, Inc.
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 <math.h>
20#include <math_private.h>
21#include <libm-alias-ldouble.h>
22
23/* Return the least floating-point number greater than X. */
24long double
25__nextupl (long double x)
26{
27 uint32_t hx, ix;
28 uint32_t lx;
29 int32_t esx;
30
31 GET_LDOUBLE_WORDS (esx, hx, lx, x);
32 ix = esx & 0x7fff;
33
34 if (((ix == 0x7fff) && (((hx & 0x7fffffff) | lx) != 0))) /* x is nan. */
35 return x + x;
36 if ((ix | hx | lx) == 0)
37 return LDBL_TRUE_MIN;
38 if (esx >= 0)
39 { /* x > 0. */
40 if (isinf (x))
41 return x;
42 lx += 1;
43 if (lx == 0)
44 {
45 hx += 1;
46#if LDBL_MIN_EXP == -16381
47 if (hx == 0 || (esx == 0 && hx == 0x80000000))
48#else
49 if (hx == 0)
50#endif
51 {
52 esx += 1;
53 hx |= 0x80000000;
54 }
55 }
56 }
57 else
58 { /* x < 0. */
59 if (lx == 0)
60 {
61#if LDBL_MIN_EXP == -16381
62 if (hx <= 0x80000000 && esx != 0xffff8000)
63 {
64 esx -= 1;
65 hx = hx - 1;
66 if ((esx & 0x7fff) > 0)
67 hx |= 0x80000000;
68 }
69 else
70 hx -= 1;
71#else
72 if (ix != 0 && hx == 0x80000000)
73 hx = 0;
74 if (hx == 0)
75 esx -= 1;
76 hx -= 1;
77#endif
78 }
79 lx -= 1;
80 }
81 SET_LDOUBLE_WORDS (x, esx, hx, lx);
82 return x;
83}
84
85libm_alias_ldouble (__nextup, nextup)
86