]>
Commit | Line | Data |
---|---|---|
f7eac6eb | 1 | /* s_ceilf.c -- float version of s_ceil.c. |
f7eac6eb RM |
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 | |
ad0f5cad | 10 | * software is freely granted, provided that this notice |
f7eac6eb RM |
11 | * is preserved. |
12 | * ==================================================== | |
13 | */ | |
14 | ||
71223ef9 | 15 | #define NO_MATH_REDIRECT |
1ed0291c RH |
16 | #include <math.h> |
17 | #include <math_private.h> | |
2f49ce7d | 18 | #include <libm-alias-float.h> |
62560ee8 | 19 | #include <math-use-builtins.h> |
ad0f5cad | 20 | |
ad0f5cad | 21 | float |
171d23d7 | 22 | __ceilf (float x) |
f7eac6eb | 23 | { |
62560ee8 SL |
24 | #if USE_CEILF_BUILTIN |
25 | return __builtin_ceilf (x); | |
26 | #else | |
27 | /* Use generic implementation. */ | |
171d23d7 SL |
28 | int32_t i0, j0; |
29 | uint32_t i; | |
f7eac6eb | 30 | |
171d23d7 SL |
31 | GET_FLOAT_WORD (i0, x); |
32 | j0 = ((i0 >> 23) & 0xff) - 0x7f; | |
33 | if (j0 < 23) | |
34 | { | |
35 | if (j0 < 0) | |
36 | { | |
37 | /* return 0 * sign (x) if |x| < 1 */ | |
38 | if (i0 < 0) | |
39 | i0 = 0x80000000; | |
40 | else if (i0 != 0) | |
41 | i0 = 0x3f800000; | |
f7eac6eb | 42 | } |
171d23d7 SL |
43 | else |
44 | { | |
45 | i = (0x007fffff) >> j0; | |
46 | if ((i0 & i) == 0) | |
47 | return x; /* x is integral */ | |
48 | if (i0 > 0) | |
49 | i0 += (0x00800000) >> j0; | |
50 | i0 &= (~i); | |
51 | } | |
52 | } | |
53 | else | |
54 | { | |
55 | if (__glibc_unlikely (j0 == 0x80)) | |
56 | return x + x; /* inf or NaN */ | |
57 | else | |
58 | return x; /* x is integral */ | |
59 | } | |
60 | SET_FLOAT_WORD (x, i0); | |
61 | return x; | |
62560ee8 | 62 | #endif /* ! USE_CEILF_BUILTIN */ |
f7eac6eb | 63 | } |
ad0f5cad | 64 | #ifndef __ceilf |
2f49ce7d | 65 | libm_alias_float (__ceil, ceil) |
ad0f5cad | 66 | #endif |