|
Packit |
6c4009 |
/* s_nextafterl.c -- long double version of s_nextafter.c.
|
|
Packit |
6c4009 |
* Conversion to long double by Ulrich Drepper,
|
|
Packit |
6c4009 |
* Cygnus Support, drepper@cygnus.com.
|
|
Packit |
6c4009 |
* Fixed for m68k by Andreas Schwab <schwab@suse.de>.
|
|
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 |
|
|
Packit |
6c4009 |
long double __nextafterl(long double x, long double y)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
int32_t ix,iy,esx,esy;
|
|
Packit |
6c4009 |
uint32_t hx,hy,lx,ly;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
GET_LDOUBLE_WORDS(esx,hx,lx,x);
|
|
Packit |
6c4009 |
GET_LDOUBLE_WORDS(esy,hy,ly,y);
|
|
Packit |
6c4009 |
ix = esx&0x7fff; /* |x| */
|
|
Packit |
6c4009 |
iy = esy&0x7fff; /* |y| */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if(((ix==0x7fff)&&((hx&0x7fffffff)|lx)!=0) || /* x is nan */
|
|
Packit |
6c4009 |
((iy==0x7fff)&&((hy&0x7fffffff)|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|hx|lx)==0) { /* x == 0 */
|
|
Packit |
6c4009 |
SET_LDOUBLE_WORDS(x,esy&0x8000,0,1);/* return +-minsubnormal */
|
|
Packit |
6c4009 |
y = x*x;
|
|
Packit |
6c4009 |
math_force_eval (y); /* raise underflow flag */
|
|
Packit |
6c4009 |
return x;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
if(esx>=0) { /* x > 0 */
|
|
Packit |
6c4009 |
if(esx>esy||((esx==esy) && (hx>hy||((hx==hy)&&(lx>ly))))) {
|
|
Packit |
6c4009 |
/* x > y, x -= ulp */
|
|
Packit |
6c4009 |
if(lx==0) {
|
|
Packit |
6c4009 |
if (ix != 0 && hx == 0x80000000) hx = 0;
|
|
Packit |
6c4009 |
if (hx==0) esx -= 1;
|
|
Packit |
6c4009 |
hx -= 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
lx -= 1;
|
|
Packit |
6c4009 |
} else { /* x < y, x += ulp */
|
|
Packit |
6c4009 |
lx += 1;
|
|
Packit |
6c4009 |
if(lx==0) {
|
|
Packit |
6c4009 |
hx += 1;
|
|
Packit |
6c4009 |
if (hx==0) {
|
|
Packit |
6c4009 |
hx = 0x80000000;
|
|
Packit |
6c4009 |
esx += 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
} else { /* x < 0 */
|
|
Packit |
6c4009 |
if(esy>=0||esx>esy||((esx==esy) && (hx>hy||((hx==hy)&&(lx>ly))))){
|
|
Packit |
6c4009 |
/* x < y, x -= ulp */
|
|
Packit |
6c4009 |
if(lx==0) {
|
|
Packit |
6c4009 |
if (ix != 0 && hx == 0x80000000) hx = 0;
|
|
Packit |
6c4009 |
if (hx==0) esx -= 1;
|
|
Packit |
6c4009 |
hx -= 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
lx -= 1;
|
|
Packit |
6c4009 |
} else { /* x > y, x += ulp */
|
|
Packit |
6c4009 |
lx += 1;
|
|
Packit |
6c4009 |
if(lx==0) {
|
|
Packit |
6c4009 |
hx += 1;
|
|
Packit |
6c4009 |
if (hx==0) {
|
|
Packit |
6c4009 |
hx = 0x80000000;
|
|
Packit |
6c4009 |
esx += 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
esy = esx&0x7fff;
|
|
Packit |
6c4009 |
if(esy==0x7fff) {
|
|
Packit |
6c4009 |
long double u = x + x; /* overflow */
|
|
Packit |
6c4009 |
math_force_eval (u);
|
|
Packit |
6c4009 |
__set_errno (ERANGE);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
if(esy==0 && (hx & 0x80000000) == 0) { /* underflow */
|
|
Packit |
6c4009 |
y = x*x;
|
|
Packit |
6c4009 |
math_force_eval (y); /* raise underflow flag */
|
|
Packit |
6c4009 |
__set_errno (ERANGE);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
SET_LDOUBLE_WORDS(x,esx,hx,lx);
|
|
Packit |
6c4009 |
return x;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
weak_alias (__nextafterl, nextafterl)
|
|
Packit |
6c4009 |
strong_alias (__nextafterl, __nexttowardl)
|
|
Packit |
6c4009 |
weak_alias (__nextafterl, nexttowardl)
|