Blame sysdeps/ieee754/ldbl-128/s_nextafterl.c

Packit 6c4009
/* s_nextafterl.c -- long double version of s_nextafter.c.
Packit 6c4009
 * Conversion to IEEE quad long double by Jakub Jelinek, jj@ultra.linux.cz.
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * ====================================================
Packit 6c4009
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
Packit 6c4009
 *
Packit 6c4009
 * Developed at SunPro, a Sun Microsystems, Inc. business.
Packit 6c4009
 * Permission to use, copy, modify, and distribute this
Packit 6c4009
 * software is freely granted, provided that this notice
Packit 6c4009
 * is preserved.
Packit 6c4009
 * ====================================================
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
#if defined(LIBM_SCCS) && !defined(lint)
Packit 6c4009
static char rcsid[] = "$NetBSD: $";
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
/* IEEE functions
Packit 6c4009
 *	nextafterl(x,y)
Packit 6c4009
 *	return the next machine floating-point number of x in the
Packit 6c4009
 *	direction toward y.
Packit 6c4009
 *   Special cases:
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
#include <errno.h>
Packit 6c4009
#include <math.h>
Packit 6c4009
#include <math-barriers.h>
Packit 6c4009
#include <math_private.h>
Packit 6c4009
#include <libm-alias-ldouble.h>
Packit 6c4009
Packit 6c4009
_Float128 __nextafterl(_Float128 x, _Float128 y)
Packit 6c4009
{
Packit 6c4009
	int64_t hx,hy,ix,iy;
Packit 6c4009
	uint64_t lx,ly;
Packit 6c4009
Packit 6c4009
	GET_LDOUBLE_WORDS64(hx,lx,x);
Packit 6c4009
	GET_LDOUBLE_WORDS64(hy,ly,y);
Packit 6c4009
	ix = hx&0x7fffffffffffffffLL;		/* |x| */
Packit 6c4009
	iy = hy&0x7fffffffffffffffLL;		/* |y| */
Packit 6c4009
Packit 6c4009
	if(((ix>=0x7fff000000000000LL)&&((ix-0x7fff000000000000LL)|lx)!=0) ||   /* x is nan */
Packit 6c4009
	   ((iy>=0x7fff000000000000LL)&&((iy-0x7fff000000000000LL)|ly)!=0))     /* y is nan */
Packit 6c4009
	   return x+y;
Packit 6c4009
	if(x==y) return y;		/* x=y, return y */
Packit 6c4009
	if((ix|lx)==0) {			/* x == 0 */
Packit 6c4009
	    _Float128 u;
Packit 6c4009
	    SET_LDOUBLE_WORDS64(x,hy&0x8000000000000000ULL,1);/* return +-minsubnormal */
Packit 6c4009
	    u = math_opt_barrier (x);
Packit 6c4009
	    u = u * u;
Packit 6c4009
	    math_force_eval (u);		/* raise underflow flag */
Packit 6c4009
	    return x;
Packit 6c4009
	}
Packit 6c4009
	if(hx>=0) {			/* x > 0 */
Packit 6c4009
	    if(hx>hy||((hx==hy)&&(lx>ly))) {	/* x > y, x -= ulp */
Packit 6c4009
		if(lx==0) hx--;
Packit 6c4009
		lx--;
Packit 6c4009
	    } else {				/* x < y, x += ulp */
Packit 6c4009
		lx++;
Packit 6c4009
		if(lx==0) hx++;
Packit 6c4009
	    }
Packit 6c4009
	} else {				/* x < 0 */
Packit 6c4009
	    if(hy>=0||hx>hy||((hx==hy)&&(lx>ly))){/* x < y, x -= ulp */
Packit 6c4009
		if(lx==0) hx--;
Packit 6c4009
		lx--;
Packit 6c4009
	    } else {				/* x > y, x += ulp */
Packit 6c4009
		lx++;
Packit 6c4009
		if(lx==0) hx++;
Packit 6c4009
	    }
Packit 6c4009
	}
Packit 6c4009
	hy = hx&0x7fff000000000000LL;
Packit 6c4009
	if(hy==0x7fff000000000000LL) {
Packit 6c4009
	    _Float128 u = x + x;		/* overflow  */
Packit 6c4009
	    math_force_eval (u);
Packit 6c4009
	    __set_errno (ERANGE);
Packit 6c4009
	}
Packit 6c4009
	if(hy==0) {
Packit 6c4009
	    _Float128 u = x*x;		/* underflow */
Packit 6c4009
	    math_force_eval (u);		/* raise underflow flag */
Packit 6c4009
	    __set_errno (ERANGE);
Packit 6c4009
	}
Packit 6c4009
	SET_LDOUBLE_WORDS64(x,hx,lx);
Packit 6c4009
	return x;
Packit 6c4009
}
Packit 6c4009
libm_alias_ldouble (__nextafter, nextafter)
Packit 6c4009
strong_alias (__nextafterl, __nexttowardl)
Packit 6c4009
weak_alias (__nextafterl, nexttowardl)