This patch renames all uses of __isinf*, __isnan*, __finite* and __signbit* to use...
[glibc.git] / sysdeps / ieee754 / ldbl-128 / s_nexttoward.c
blob2cd2e5839128187754852eda758b9751436c95ad
1 /* s_nexttoward.c
2 * Conversion from s_nextafter.c by Ulrich Drepper, Cygnus Support,
3 * drepper@cygnus.com and Jakub Jelinek, jj@ultra.linux.cz.
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 * nexttoward(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>
30 #include <float.h>
32 double __nexttoward(double x, long double y)
34 int32_t hx,ix;
35 int64_t hy,iy;
36 u_int32_t lx;
37 u_int64_t ly;
39 EXTRACT_WORDS(hx,lx,x);
40 GET_LDOUBLE_WORDS64(hy,ly,y);
41 ix = hx&0x7fffffff; /* |x| */
42 iy = hy&0x7fffffffffffffffLL; /* |y| */
44 if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) || /* x is nan */
45 ((iy>=0x7fff000000000000LL)&&((iy-0x7fff000000000000LL)|ly)!=0))
46 /* y is nan */
47 return x+y;
48 if((long double) x==y) return y; /* x=y, return y */
49 if((ix|lx)==0) { /* x == 0 */
50 double u;
51 INSERT_WORDS(x,(u_int32_t)((hy>>32)&0x80000000),1);/* return +-minsub */
52 u = math_opt_barrier (x);
53 u = u * u;
54 math_force_eval (u); /* raise underflow flag */
55 return x;
57 if(hx>=0) { /* x > 0 */
58 if (x > y) { /* x -= ulp */
59 if(lx==0) hx -= 1;
60 lx -= 1;
61 } else { /* x < y, x += ulp */
62 lx += 1;
63 if(lx==0) hx += 1;
65 } else { /* x < 0 */
66 if (x < y) { /* x -= ulp */
67 if(lx==0) hx -= 1;
68 lx -= 1;
69 } else { /* x > y, x += ulp */
70 lx += 1;
71 if(lx==0) hx += 1;
74 hy = hx&0x7ff00000;
75 if(hy>=0x7ff00000) {
76 x = x+x; /* overflow */
77 if (FLT_EVAL_METHOD != 0 && FLT_EVAL_METHOD != 1)
78 /* Force conversion to double. */
79 asm ("" : "+m"(x));
80 return x;
82 if(hy<0x00100000) {
83 double u = x*x; /* underflow */
84 math_force_eval (u); /* raise underflow flag */
86 INSERT_WORDS(x,hx,lx);
87 return x;
89 weak_alias (__nexttoward, nexttoward)