malloc: Do not compile mcheck-init.o as libc module
[glibc.git] / sysdeps / ieee754 / ldbl-128ibm / s_nexttoward.c
blobd8f4fc652340f60974089c9347ead3e7d5164395
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 <errno.h>
29 #include <math.h>
30 #include <math_private.h>
31 #include <math_ldbl_opt.h>
32 #include <float.h>
34 double __nexttoward(double x, long double y)
36 int32_t hx,ix;
37 int64_t hy,iy;
38 uint32_t lx;
39 double yhi;
41 EXTRACT_WORDS(hx,lx,x);
42 yhi = ldbl_high (y);
43 EXTRACT_WORDS64(hy,yhi);
44 ix = hx&0x7fffffff; /* |x| */
45 iy = hy&0x7fffffffffffffffLL; /* |y| */
47 if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) || /* x is nan */
48 iy>0x7ff0000000000000LL) /* y is nan */
49 return x+y;
50 if((long double) x==y) return y; /* x=y, return y */
51 if((ix|lx)==0) { /* x == 0 */
52 double u;
53 INSERT_WORDS(x,(uint32_t)((hy>>32)&0x80000000),1);/* return +-minsub */
54 u = math_opt_barrier (x);
55 u = u * u;
56 math_force_eval (u); /* raise underflow flag */
57 return x;
59 if(hx>=0) { /* x > 0 */
60 if (x > y) { /* x > 0 */
61 if(lx==0) hx -= 1;
62 lx -= 1;
63 } else { /* x < y, x += ulp */
64 lx += 1;
65 if(lx==0) hx += 1;
67 } else { /* x < 0 */
68 if (x < y) { /* x < 0 */
69 if(lx==0) hx -= 1;
70 lx -= 1;
71 } else { /* x > y, x += ulp */
72 lx += 1;
73 if(lx==0) hx += 1;
76 hy = hx&0x7ff00000;
77 if(hy>=0x7ff00000) {
78 double u = x+x; /* overflow */
79 math_force_eval (u);
80 __set_errno (ERANGE);
82 if(hy<0x00100000) {
83 double u = x*x; /* underflow */
84 math_force_eval (u); /* raise underflow flag */
85 __set_errno (ERANGE);
87 INSERT_WORDS(x,hx,lx);
88 return x;
90 long_double_symbol (libm, __nexttoward, nexttoward);