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

Packit 6c4009
/* s_nexttowardf.c -- float version of s_nextafter.c.
Packit 6c4009
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com
Packit 6c4009
 * and 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
#include <errno.h>
Packit 6c4009
#include <math.h>
Packit 6c4009
#include <math-barriers.h>
Packit 6c4009
#include <math_private.h>
Packit 6c4009
Packit 6c4009
float __nexttowardf(float x, long double y)
Packit 6c4009
{
Packit 6c4009
	int32_t hx,ix;
Packit 6c4009
	int64_t hy,iy;
Packit 6c4009
	uint64_t ly;
Packit 6c4009
Packit 6c4009
	GET_FLOAT_WORD(hx,x);
Packit 6c4009
	GET_LDOUBLE_WORDS64(hy,ly,y);
Packit 6c4009
	ix = hx&0x7fffffff;		/* |x| */
Packit 6c4009
	iy = hy&0x7fffffffffffffffLL;	/* |y| */
Packit 6c4009
Packit 6c4009
	if((ix>0x7f800000) ||   /* x is nan */
Packit 6c4009
	   ((iy>=0x7fff000000000000LL)&&((iy-0x7fff000000000000LL)|ly)!=0))
Packit 6c4009
				/* y is nan */
Packit 6c4009
	   return x+y;
Packit 6c4009
	if((long double) x==y) return y;	/* x=y, return y */
Packit 6c4009
	if(ix==0) {				/* x == 0 */
Packit 6c4009
	    float u;
Packit 6c4009
	    SET_FLOAT_WORD(x,(uint32_t)((hy>>32)&0x80000000)|1);/* return +-minsub*/
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(x > y) {				/* x -= ulp */
Packit 6c4009
		hx -= 1;
Packit 6c4009
	    } else {				/* x < y, x += ulp */
Packit 6c4009
		hx += 1;
Packit 6c4009
	    }
Packit 6c4009
	} else {				/* x < 0 */
Packit 6c4009
	    if(x < y) {				/* x < y, x -= ulp */
Packit 6c4009
		hx -= 1;
Packit 6c4009
	    } else {				/* x > y, x += ulp */
Packit 6c4009
		hx += 1;
Packit 6c4009
	    }
Packit 6c4009
	}
Packit 6c4009
	hy = hx&0x7f800000;
Packit 6c4009
	if(hy>=0x7f800000) {
Packit 6c4009
	  float u = x+x;		/* overflow  */
Packit 6c4009
	  math_force_eval (u);
Packit 6c4009
	  __set_errno (ERANGE);
Packit 6c4009
	}
Packit 6c4009
	if(hy<0x00800000) {
Packit 6c4009
	    float u = x*x;		/* underflow */
Packit 6c4009
	    math_force_eval (u);	/* raise underflow flag */
Packit 6c4009
	    __set_errno (ERANGE);
Packit 6c4009
	}
Packit 6c4009
	SET_FLOAT_WORD(x,hx);
Packit 6c4009
	return x;
Packit 6c4009
}
Packit 6c4009
weak_alias (__nexttowardf, nexttowardf)