Remove __STDC__ conditionals from libm.
[platform/upstream/glibc.git] / sysdeps / ieee754 / ldbl-128ibm / s_nexttoward.c
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  */
5
6 /*
7  * ====================================================
8  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9  *
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  * ====================================================
15  */
16
17 #if defined(LIBM_SCCS) && !defined(lint)
18 static char rcsid[] = "$NetBSD: $";
19 #endif
20
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:
26  */
27
28 #include "math.h"
29 #include <math_private.h>
30 #include <math_ldbl_opt.h>
31 #include <float.h>
32
33 double __nexttoward(double x, long double y)
34 {
35         int32_t hx,ix;
36         int64_t hy,iy;
37         u_int32_t lx;
38         u_int64_t ly,uly;
39
40         EXTRACT_WORDS(hx,lx,x);
41         GET_LDOUBLE_WORDS64(hy,ly,y);
42         ix = hx&0x7fffffff;             /* |x| */
43         iy = hy&0x7fffffffffffffffLL;   /* |y| */
44         uly = ly&0x7fffffffffffffffLL;  /* |y| */
45
46         if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) ||   /* x is nan */
47            ((iy>=0x7ff0000000000000LL)&&((iy-0x7ff0000000000000LL)|uly)!=0))
48                                                             /* 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,(u_int32_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;
58         }
59         if(hx>=0) {                             /* x > 0 */
60             if (hy<0||(ix>>20)>(iy>>52)
61                 || ((ix>>20)==(iy>>52)
62                     && (((((int64_t)hx)<<32)|(lx))>(hy&0x000fffffffffffffLL)
63                         || (((((int64_t)hx)<<32)|(lx))==(hy&0x000fffffffffffffLL)
64                             )))) {      /* x > y, x -= ulp */
65                 if(lx==0) hx -= 1;
66                 lx -= 1;
67             } else {                            /* x < y, x += ulp */
68                 lx += 1;
69                 if(lx==0) hx += 1;
70             }
71         } else {                                /* x < 0 */
72             if (hy>=0||(ix>>20)>(iy>>52)
73                 || ((ix>>20)==(iy>>52)
74                     && (((((int64_t)hx)<<32)|(lx))>(hy&0x000fffffffffffffLL)
75                         || (((((int64_t)hx)<<32)|(lx))==(hy&0x000fffffffffffffLL)
76                            )))) {       /* x < y, x -= ulp */
77                 if(lx==0) hx -= 1;
78                 lx -= 1;
79             } else {                            /* x > y, x += ulp */
80                 lx += 1;
81                 if(lx==0) hx += 1;
82             }
83         }
84         hy = hx&0x7ff00000;
85         if(hy>=0x7ff00000) {
86           x = x+x;      /* overflow  */
87           if (FLT_EVAL_METHOD != 0 && FLT_EVAL_METHOD != 1)
88             /* Force conversion to double.  */
89             asm ("" : "+m"(x));
90           return x;
91         }
92         if(hy<0x00100000) {
93             double u = x*x;                     /* underflow */
94             math_force_eval (u);                /* raise underflow flag */
95         }
96         INSERT_WORDS(x,hx,lx);
97         return x;
98 }
99 long_double_symbol (libm, __nexttoward, nexttoward);