m68k: use math_force_eval in nextafterl
[platform/upstream/glibc.git] / ports / sysdeps / m68k / m680x0 / fpu / s_nextafterl.c
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  * Fixed for m68k by Andreas Schwab <schwab@suse.de>.
5  */
6
7 /*
8  * ====================================================
9  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10  *
11  * Developed at SunPro, a Sun Microsystems, Inc. business.
12  * Permission to use, copy, modify, and distribute this
13  * software is freely granted, provided that this notice
14  * is preserved.
15  * ====================================================
16  */
17
18 #if defined(LIBM_SCCS) && !defined(lint)
19 static char rcsid[] = "$NetBSD: $";
20 #endif
21
22 /* IEEE functions
23  *      nextafterl(x,y)
24  *      return the next machine floating-point number of x in the
25  *      direction toward y.
26  *   Special cases:
27  */
28
29 #include <math.h>
30 #include <math_private.h>
31
32 long double __nextafterl(long double x, long double y)
33 {
34         int32_t ix,iy,esx,esy;
35         u_int32_t hx,hy,lx,ly;
36
37         GET_LDOUBLE_WORDS(esx,hx,lx,x);
38         GET_LDOUBLE_WORDS(esy,hy,ly,y);
39         ix = esx&0x7fff;                /* |x| */
40         iy = esy&0x7fff;                /* |y| */
41
42         if(((ix==0x7fff)&&((hx&0x7fffffff)|lx)!=0) ||   /* x is nan */
43            ((iy==0x7fff)&&((hy&0x7fffffff)|ly)!=0))     /* y is nan */
44            return x+y;
45         if(x==y) return y;              /* x=y, return y */
46         if((ix|hx|lx)==0) {                     /* x == 0 */
47             SET_LDOUBLE_WORDS(x,esy&0x8000,0,1);/* return +-minsubnormal */
48             y = x*x;
49             math_force_eval (y);                /* raise underflow flag */
50             return x;
51         }
52         if(esx>=0) {                    /* x > 0 */
53             if(esx>esy||((esx==esy) && (hx>hy||((hx==hy)&&(lx>ly))))) {
54               /* x > y, x -= ulp */
55                 if(lx==0) {
56                     if (ix != 0 && hx == 0x80000000) hx = 0;
57                     if (hx==0) esx -= 1;
58                     hx -= 1;
59                 }
60                 lx -= 1;
61             } else {                            /* x < y, x += ulp */
62                 lx += 1;
63                 if(lx==0) {
64                     hx += 1;
65                     if (hx==0) {
66                         hx = 0x80000000;
67                         esx += 1;
68                     }
69                 }
70             }
71         } else {                                /* x < 0 */
72             if(esy>=0||esx>esy||((esx==esy) && (hx>hy||((hx==hy)&&(lx>ly))))){
73               /* x < y, x -= ulp */
74                 if(lx==0) {
75                     if (ix != 0 && hx == 0x80000000) hx = 0;
76                     if (hx==0) esx -= 1;
77                     hx -= 1;
78                 }
79                 lx -= 1;
80             } else {                            /* x > y, x += ulp */
81                 lx += 1;
82                 if(lx==0) {
83                     hx += 1;
84                     if (hx==0) {
85                         hx = 0x80000000;
86                         esx += 1;
87                     }
88                 }
89             }
90         }
91         esy = esx&0x7fff;
92         if(esy==0x7fff) return x+x;     /* overflow  */
93         if(esy==0 && (hx & 0x80000000) == 0) { /* underflow */
94             y = x*x;
95             math_force_eval (y);                /* raise underflow flag */
96         }
97         SET_LDOUBLE_WORDS(x,esx,hx,lx);
98         return x;
99 }
100 weak_alias (__nextafterl, nextafterl)
101 strong_alias (__nextafterl, __nexttowardl)
102 weak_alias (__nextafterl, nexttowardl)