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 IEEE quad long double by Jakub Jelinek, jj@ultra.linux.cz.
00003  */
00004 
00005 /*
00006  * ====================================================
00007  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00008  *
00009  * Developed at SunPro, a Sun Microsystems, Inc. business.
00010  * Permission to use, copy, modify, and distribute this
00011  * software is freely granted, provided that this notice
00012  * is preserved.
00013  * ====================================================
00014  */
00015 
00016 #if defined(LIBM_SCCS) && !defined(lint)
00017 static char rcsid[] = "$NetBSD: $";
00018 #endif
00019 
00020 /* IEEE functions
00021  *     nextafterl(x,y)
00022  *     return the next machine floating-point number of x in the
00023  *     direction toward y.
00024  *   Special cases:
00025  */
00026 
00027 #include "math.h"
00028 #include <math_private.h>
00029 
00030 #ifdef __STDC__
00031        long double __nextafterl(long double x, long double y)
00032 #else
00033        long double __nextafterl(x,y)
00034        long double x,y;
00035 #endif
00036 {
00037        int64_t hx,hy,ix,iy;
00038        u_int64_t lx,ly;
00039 
00040        GET_LDOUBLE_WORDS64(hx,lx,x);
00041        GET_LDOUBLE_WORDS64(hy,ly,y);
00042        ix = hx&0x7fffffffffffffffLL;             /* |x| */
00043        iy = hy&0x7fffffffffffffffLL;             /* |y| */
00044 
00045        if(((ix>=0x7fff000000000000LL)&&((ix-0x7fff000000000000LL)|lx)!=0) ||   /* x is nan */
00046           ((iy>=0x7fff000000000000LL)&&((iy-0x7fff000000000000LL)|ly)!=0))     /* y is nan */
00047           return x+y;
00048        if(x==y) return y;          /* x=y, return y */
00049        if((ix|lx)==0) {                   /* x == 0 */
00050            long double u;
00051            SET_LDOUBLE_WORDS64(x,hy&0x8000000000000000ULL,1);/* return +-minsubnormal */
00052            u = math_opt_barrier (x);
00053            u = u * u;
00054            math_force_eval (u);           /* raise underflow flag */
00055            return x;
00056        }
00057        if(hx>=0) {                 /* x > 0 */
00058            if(hx>hy||((hx==hy)&&(lx>ly))) {      /* x > y, x -= ulp */
00059               if(lx==0) hx--;
00060               lx--;
00061            } else {                       /* x < y, x += ulp */
00062               lx++;
00063               if(lx==0) hx++;
00064            }
00065        } else {                           /* x < 0 */
00066            if(hy>=0||hx>hy||((hx==hy)&&(lx>ly))){/* x < y, x -= ulp */
00067               if(lx==0) hx--;
00068               lx--;
00069            } else {                       /* x > y, x += ulp */
00070               lx++;
00071               if(lx==0) hx++;
00072            }
00073        }
00074        hy = hx&0x7fff000000000000LL;
00075        if(hy==0x7fff000000000000LL) return x+x;/* overflow  */
00076        if(hy==0) {
00077            long double u = x*x;           /* underflow */
00078            math_force_eval (u);           /* raise underflow flag */
00079        }
00080        SET_LDOUBLE_WORDS64(x,hx,lx);
00081        return x;
00082 }
00083 weak_alias (__nextafterl, nextafterl)
00084 strong_alias (__nextafterl, __nexttowardl)
00085 weak_alias (__nextafterl, nexttowardl)