|
Packit |
6c4009 |
/* Single precision version of nexttoward.c.
|
|
Packit |
6c4009 |
Conversion to IEEE single float by Jakub Jelinek, jj@ultra.linux.cz. */
|
|
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 |
/* IEEE functions
|
|
Packit |
6c4009 |
* nexttowardf(x,y)
|
|
Packit |
6c4009 |
* return the next machine floating-point number of x in the
|
|
Packit |
6c4009 |
* direction toward y.
|
|
Packit |
6c4009 |
* This is for machines which use the same binary type for double and
|
|
Packit |
6c4009 |
* long double.
|
|
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 <float.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
float __nexttowardf(float x, long double y)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
int32_t hx,hy,ix,iy;
|
|
Packit |
6c4009 |
uint32_t ly;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
GET_FLOAT_WORD(hx,x);
|
|
Packit |
6c4009 |
EXTRACT_WORDS(hy,ly,y);
|
|
Packit |
6c4009 |
ix = hx&0x7fffffff; /* |x| */
|
|
Packit |
6c4009 |
iy = hy&0x7fffffff; /* |y| */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if((ix>0x7f800000) || /* x is nan */
|
|
Packit |
6c4009 |
((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0)) /* 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&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 |
} else { /* 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 |
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)
|