|
Packit |
6c4009 |
/* s_rintf.c -- float version of s_rint.c.
|
|
Packit |
6c4009 |
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
/* Adapted for use as nearbyint by Ulrich Drepper <drepper@cygnus.com>. */
|
|
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 |
|
|
Packit |
6c4009 |
#include <fenv.h>
|
|
Packit |
6c4009 |
#include <math.h>
|
|
Packit |
6c4009 |
#include <math-barriers.h>
|
|
Packit |
6c4009 |
#include <math_private.h>
|
|
Packit |
6c4009 |
#include <libm-alias-float.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static const float
|
|
Packit |
6c4009 |
TWO23[2]={
|
|
Packit |
6c4009 |
8.3886080000e+06, /* 0x4b000000 */
|
|
Packit |
6c4009 |
-8.3886080000e+06, /* 0xcb000000 */
|
|
Packit |
6c4009 |
};
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
float
|
|
Packit |
6c4009 |
__nearbyintf(float x)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
fenv_t env;
|
|
Packit |
6c4009 |
int32_t i0,j0,sx;
|
|
Packit |
6c4009 |
float w,t;
|
|
Packit |
6c4009 |
GET_FLOAT_WORD(i0,x);
|
|
Packit |
6c4009 |
sx = (i0>>31)&1;
|
|
Packit |
6c4009 |
j0 = ((i0>>23)&0xff)-0x7f;
|
|
Packit |
6c4009 |
if(j0<23) {
|
|
Packit |
6c4009 |
if(j0<0) {
|
|
Packit |
6c4009 |
libc_feholdexceptf (&env;;
|
|
Packit |
6c4009 |
w = TWO23[sx] + math_opt_barrier (x);
|
|
Packit |
6c4009 |
t = w-TWO23[sx];
|
|
Packit |
6c4009 |
math_force_eval (t);
|
|
Packit |
6c4009 |
libc_fesetenvf (&env;;
|
|
Packit |
6c4009 |
GET_FLOAT_WORD(i0,t);
|
|
Packit |
6c4009 |
SET_FLOAT_WORD(t,(i0&0x7fffffff)|(sx<<31));
|
|
Packit |
6c4009 |
return t;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
} else {
|
|
Packit |
6c4009 |
if(__builtin_expect(j0==0x80, 0)) return x+x; /* inf or NaN */
|
|
Packit |
6c4009 |
else return x; /* x is integral */
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
libc_feholdexceptf (&env;;
|
|
Packit |
6c4009 |
w = TWO23[sx] + math_opt_barrier (x);
|
|
Packit |
6c4009 |
t = w-TWO23[sx];
|
|
Packit |
6c4009 |
math_force_eval (t);
|
|
Packit |
6c4009 |
libc_fesetenvf (&env;;
|
|
Packit |
6c4009 |
return t;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
libm_alias_float (__nearbyint, nearbyint)
|