Cygwin: (mostly) drop NT4 and Samba < 3.0 support
[newlib-cygwin.git] / winsup / cygwin / math / nextafterl.c
blobb1e479a95e1d98527dd7c482fbb664df3f7e0659
1 /**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6 /*
7 nextafterl.c
8 Contributed by Danny Smith <dannysmith@users.sourceforge.net>
9 No copyright claimed, absolutely no warranties.
11 2005-05-09
14 #include <math.h>
16 long double
17 nextafterl (long double x, long double y)
19 union {
20 long double ld;
21 struct {
22 /* packed attribute is unnecessary on x86/x64 for these three variables */
23 unsigned long long mantissa;
24 unsigned short expn;
25 unsigned short pad;
26 } parts;
27 } u;
29 /* The normal bit is explicit for long doubles, unlike
30 float and double. */
31 static const unsigned long long normal_bit = 0x8000000000000000ull;
32 u.ld = 0.0L;
33 if (isnan (y) || isnan (x))
34 return x + y;
36 if (x == y )
37 /* nextafter (0.0, -O.0) should return -0.0. */
38 return y;
40 u.ld = x;
41 if (x == 0.0L)
43 u.parts.mantissa = 1ull;
44 return y > 0.0L ? u.ld : -u.ld;
47 if (((x > 0.0L) ^ (y > x)) == 0)
49 u.parts.mantissa++;
50 if ((u.parts.mantissa & ~normal_bit) == 0ull)
51 u.parts.expn++;
53 else
55 if ((u.parts.mantissa & ~normal_bit) == 0ull)
56 u.parts.expn--;
57 u.parts.mantissa--;
60 /* If we have updated the expn of a normal number,
61 or moved from denormal to normal, [re]set the normal bit. */
62 if (u.parts.expn & 0x7fff)
63 u.parts.mantissa |= normal_bit;
65 return u.ld;
68 /* nexttowardl is the same function with a different name. */
69 long double
70 nexttowardl (long double, long double) __attribute__ ((alias("nextafterl")));