[BZ #2510, BZ #2830, BZ #3137, BZ #3313, BZ #3426, BZ #3465, BZ #3480, BZ #3483,...
[glibc.git] / sysdeps / ieee754 / ldbl-96 / s_nextafterl.c
blob1798261b2808085986218d0c2cc9a24d8522a28f
1 /* s_nextafterl.c -- long double version of s_nextafter.c.
2 * Conversion to long double by Ulrich Drepper,
3 * Cygnus Support, drepper@cygnus.com.
4 */
6 /*
7 * ====================================================
8 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10 * Developed at SunPro, a Sun Microsystems, Inc. business.
11 * Permission to use, copy, modify, and distribute this
12 * software is freely granted, provided that this notice
13 * is preserved.
14 * ====================================================
17 #if defined(LIBM_SCCS) && !defined(lint)
18 static char rcsid[] = "$NetBSD: $";
19 #endif
21 /* IEEE functions
22 * nextafterl(x,y)
23 * return the next machine floating-point number of x in the
24 * direction toward y.
25 * Special cases:
28 #include "math.h"
29 #include "math_private.h"
31 #ifdef __STDC__
32 long double __nextafterl(long double x, long double y)
33 #else
34 long double __nextafterl(x,y)
35 long double x,y;
36 #endif
38 int32_t hx,hy,ix,iy;
39 u_int32_t lx,ly,esx,esy;
41 GET_LDOUBLE_WORDS(esx,hx,lx,x);
42 GET_LDOUBLE_WORDS(esy,hy,ly,y);
43 ix = esx&0x7fff; /* |x| */
44 iy = esy&0x7fff; /* |y| */
46 if (((ix==0x7fff)&&((hx|lx)!=0)) || /* x is nan */
47 ((iy==0x7fff)&&((hy|ly)!=0))) /* y is nan */
48 return x+y;
49 if(x==y) return y; /* x=y, return y */
50 if((ix|hx|lx)==0) { /* x == 0 */
51 SET_LDOUBLE_WORDS(x,esy&0x8000,0,1);/* return +-minsubnormal */
52 y = x*x;
53 if(y==x) return y; else return x; /* raise underflow flag */
55 if(esx<0x8000) { /* x > 0 */
56 if(ix>iy||((ix==iy) && (hx>hy||((hx==hy)&&(lx>ly))))) {
57 /* x > y, x -= ulp */
58 if(lx==0) {
59 if (hx==0) esx -= 1;
60 hx -= 1;
62 lx -= 1;
63 } else { /* x < y, x += ulp */
64 lx += 1;
65 if(lx==0) {
66 hx += 1;
67 if (hx==0)
68 esx += 1;
71 } else { /* x < 0 */
72 if(esy>=0||(ix>iy||((ix==iy)&&(hx>hy||((hx==hy)&&(lx>ly)))))){
73 /* x < y, x -= ulp */
74 if(lx==0) {
75 if (hx==0) esx -= 1;
76 hx -= 1;
78 lx -= 1;
79 } else { /* x > y, x += ulp */
80 lx += 1;
81 if(lx==0) {
82 hx += 1;
83 if (hx==0) esx += 1;
87 esy = esx&0x7fff;
88 if(esy==0x7fff) return x+x; /* overflow */
89 if(esy==0) { /* underflow */
90 y = x*x;
91 if(y!=x) { /* raise underflow flag */
92 SET_LDOUBLE_WORDS(y,esx,hx,lx);
93 return y;
96 SET_LDOUBLE_WORDS(x,esx,hx,lx);
97 return x;
99 weak_alias (__nextafterl, nextafterl)
100 strong_alias (__nextafterl, __nexttowardl)
101 weak_alias (__nextafterl, nexttowardl)