1 /* s_rintf.c -- float version of s_rint.c.
5 * ====================================================
6 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8 * Developed at SunPro, a Sun Microsystems, Inc. business.
9 * Permission to use, copy, modify, and distribute this
10 * software is freely granted, provided that this notice
12 * ====================================================
18 #include <math-barriers.h>
19 #include <math_private.h>
20 #include <fenv_private.h>
21 #include <libm-alias-float.h>
22 #include <math-use-builtins.h>
25 __nearbyintf (float x
)
27 #if USE_NEARBYINTF_BUILTIN
28 return __builtin_nearbyintf (x
);
30 /* Use generic implementation. */
33 8.3886080000e+06, /* 0x4b000000 */
34 -8.3886080000e+06, /* 0xcb000000 */
39 GET_FLOAT_WORD (i0
, x
);
41 j0
= ((i0
>> 23) & 0xff) - 0x7f;
46 libc_feholdexceptf (&env
);
47 w
= TWO23
[sx
] + math_opt_barrier (x
);
50 libc_fesetenvf (&env
);
51 GET_FLOAT_WORD (i0
, t
);
52 SET_FLOAT_WORD (t
, (i0
& 0x7fffffff) | (sx
<< 31));
58 if (__glibc_unlikely (j0
== 0x80))
59 return x
+ x
; /* inf or NaN */
61 return x
; /* x is integral */
63 libc_feholdexceptf (&env
);
64 w
= TWO23
[sx
] + math_opt_barrier (x
);
67 libc_fesetenvf (&env
);
69 #endif /* ! USE_NEARBYINT_BUILTIN */
71 libm_alias_float (__nearbyint
, nearbyint
)