1 | /* s_rintf.c -- float version of s_rint.c. |
2 | */ |
3 | |
4 | /* |
5 | * ==================================================== |
6 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
7 | * |
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 |
11 | * is preserved. |
12 | * ==================================================== |
13 | */ |
14 | |
15 | #define NO_MATH_REDIRECT |
16 | #include <math.h> |
17 | #include <math_private.h> |
18 | #include <libm-alias-float.h> |
19 | #include <math-use-builtins.h> |
20 | |
21 | float |
22 | __rintf (float x) |
23 | { |
24 | #if USE_RINTF_BUILTIN |
25 | return __builtin_rintf (x); |
26 | #else |
27 | /* Use generic implementation. */ |
28 | static const float |
29 | TWO23[2] = { |
30 | 8.3886080000e+06, /* 0x4b000000 */ |
31 | -8.3886080000e+06, /* 0xcb000000 */ |
32 | }; |
33 | int32_t i0, j0, sx; |
34 | float w, t; |
35 | GET_FLOAT_WORD (i0, x); |
36 | sx = (i0 >> 31) & 1; |
37 | j0 = ((i0 >> 23) & 0xff) - 0x7f; |
38 | if (j0 < 23) |
39 | { |
40 | if(j0 < 0) |
41 | { |
42 | w = TWO23[sx] + x; |
43 | t = w - TWO23[sx]; |
44 | GET_FLOAT_WORD (i0, t); |
45 | SET_FLOAT_WORD (t, (i0 & 0x7fffffff) | (sx << 31)); |
46 | return t; |
47 | } |
48 | } |
49 | else |
50 | { |
51 | if (j0 == 0x80) |
52 | return x + x; /* inf or NaN */ |
53 | else |
54 | return x; /* x is integral */ |
55 | } |
56 | w = TWO23[sx] + x; |
57 | return w - TWO23[sx]; |
58 | #endif /* ! USE_RINTF_BUILTIN */ |
59 | } |
60 | #ifndef __rintf |
61 | libm_alias_float (__rint, rint) |
62 | #endif |
63 | |