1 | /* s_floorf.c -- float version of s_floor.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 | /* |
16 | * floorf(x) |
17 | * Return x rounded toward -inf to integral value |
18 | * Method: |
19 | * Bit twiddling. |
20 | */ |
21 | |
22 | #define NO_MATH_REDIRECT |
23 | #include <math.h> |
24 | #include <math_private.h> |
25 | #include <libm-alias-float.h> |
26 | #include <math-use-builtins.h> |
27 | |
28 | float |
29 | __floorf (float x) |
30 | { |
31 | #if USE_FLOORF_BUILTIN |
32 | return __builtin_floorf (x); |
33 | #else |
34 | /* Use generic implementation. */ |
35 | int32_t i0, j0; |
36 | uint32_t i; |
37 | GET_FLOAT_WORD (i0, x); |
38 | j0 = ((i0 >> 23) & 0xff) - 0x7f; |
39 | if (j0 < 23) |
40 | { |
41 | if (j0 < 0) |
42 | { |
43 | /* return 0 * sign (x) if |x| < 1 */ |
44 | if (i0 >= 0) |
45 | i0 = 0; |
46 | else if ((i0 & 0x7fffffff) != 0) |
47 | i0 = 0xbf800000; |
48 | } |
49 | else |
50 | { |
51 | i = (0x007fffff) >> j0; |
52 | if ((i0 & i) == 0) |
53 | return x; /* x is integral */ |
54 | if (i0 < 0) |
55 | i0 += (0x00800000) >> j0; |
56 | i0 &= (~i); |
57 | } |
58 | } |
59 | else |
60 | { |
61 | if (__glibc_unlikely (j0 == 0x80)) |
62 | return x + x; /* inf or NaN */ |
63 | else |
64 | return x; /* x is integral */ |
65 | } |
66 | SET_FLOAT_WORD (x, i0); |
67 | return x; |
68 | #endif /* ! USE_FLOORF_BUILTIN */ |
69 | } |
70 | #ifndef __floorf |
71 | libm_alias_float (__floor, floor) |
72 | #endif |
73 | |