Back to index

glibc  2.9
s_nextafterl.c
Go to the documentation of this file.
00001 /* s_nextafterl.c -- long double version of s_nextafter.c.
00002  * Conversion to long double by Ulrich Drepper,
00003  * Cygnus Support, drepper@cygnus.com.
00004  * Fixed for m68k by Andreas Schwab <schwab@suse.de>.
00005  */
00006 
00007 /*
00008  * ====================================================
00009  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00010  *
00011  * Developed at SunPro, a Sun Microsystems, Inc. business.
00012  * Permission to use, copy, modify, and distribute this
00013  * software is freely granted, provided that this notice
00014  * is preserved.
00015  * ====================================================
00016  */
00017 
00018 #if defined(LIBM_SCCS) && !defined(lint)
00019 static char rcsid[] = "$NetBSD: $";
00020 #endif
00021 
00022 /* IEEE functions
00023  *     nextafterl(x,y)
00024  *     return the next machine floating-point number of x in the
00025  *     direction toward y.
00026  *   Special cases:
00027  */
00028 
00029 #include "math.h"
00030 #include "math_private.h"
00031 
00032 #ifdef __STDC__
00033        long double __nextafterl(long double x, long double y)
00034 #else
00035        long double __nextafterl(x,y)
00036        long double x,y;
00037 #endif
00038 {
00039        int32_t ix,iy,esx,esy;
00040        u_int32_t hx,hy,lx,ly;
00041 
00042        GET_LDOUBLE_WORDS(esx,hx,lx,x);
00043        GET_LDOUBLE_WORDS(esy,hy,ly,y);
00044        ix = esx&0x7fff;            /* |x| */
00045        iy = esy&0x7fff;            /* |y| */
00046 
00047        if(((ix==0x7fff)&&((hx&0x7fffffff)|lx)!=0) ||   /* x is nan */
00048           ((iy==0x7fff)&&((hy&0x7fffffff)|ly)!=0))     /* y is nan */
00049           return x+y;
00050        if(x==y) return y;          /* x=y, return y */
00051        if((ix|hx|lx)==0) {                /* x == 0 */
00052            SET_LDOUBLE_WORDS(x,esy&0x8000,0,1);/* return +-minsubnormal */
00053            y = x*x;
00054            if(y==x) return y; else return x;     /* raise underflow flag */
00055        }
00056        if(esx>=0) {                /* x > 0 */
00057            if(esx>esy||((esx==esy) && (hx>hy||((hx==hy)&&(lx>ly))))) {
00058              /* x > y, x -= ulp */
00059               if(lx==0) {
00060                   if (ix != 0 && hx == 0x80000000) hx = 0;
00061                   if (hx==0) esx -= 1;
00062                   hx -= 1;
00063               }
00064               lx -= 1;
00065            } else {                       /* x < y, x += ulp */
00066               lx += 1;
00067               if(lx==0) {
00068                   hx += 1;
00069                   if (hx==0) {
00070                      hx = 0x80000000;
00071                      esx += 1;
00072                   }
00073               }
00074            }
00075        } else {                           /* x < 0 */
00076            if(esy>=0||esx>esy||((esx==esy) && (hx>hy||((hx==hy)&&(lx>ly))))){
00077              /* x < y, x -= ulp */
00078               if(lx==0) {
00079                   if (ix != 0 && hx == 0x80000000) hx = 0;
00080                   if (hx==0) esx -= 1;
00081                   hx -= 1;
00082               }
00083               lx -= 1;
00084            } else {                       /* x > y, x += ulp */
00085               lx += 1;
00086               if(lx==0) {
00087                   hx += 1;
00088                   if (hx==0) {
00089                      hx = 0x80000000;
00090                      esx += 1;
00091                   }
00092               }
00093            }
00094        }
00095        esy = esx&0x7fff;
00096        if(esy==0x7fff) return x+x; /* overflow  */
00097        if(esy==0 && (hx & 0x80000000) == 0) { /* underflow */
00098            y = x*x;
00099            if(y!=x) {              /* raise underflow flag */
00100                SET_LDOUBLE_WORDS(y,esx,hx,lx);
00101               return y;
00102            }
00103        }
00104        SET_LDOUBLE_WORDS(x,esx,hx,lx);
00105        return x;
00106 }
00107 weak_alias (__nextafterl, nextafterl)
00108 strong_alias (__nextafterl, __nexttowardl)
00109 weak_alias (__nextafterl, nexttowardl)