1*f504f610SAugustin Cavalier #include "libm.h" 2*f504f610SAugustin Cavalier ceilf(float x)3*f504f610SAugustin Cavalierfloat ceilf(float x) 4*f504f610SAugustin Cavalier { 5*f504f610SAugustin Cavalier union {float f; uint32_t i;} u = {x}; 6*f504f610SAugustin Cavalier int e = (int)(u.i >> 23 & 0xff) - 0x7f; 7*f504f610SAugustin Cavalier uint32_t m; 8*f504f610SAugustin Cavalier 9*f504f610SAugustin Cavalier if (e >= 23) 10*f504f610SAugustin Cavalier return x; 11*f504f610SAugustin Cavalier if (e >= 0) { 12*f504f610SAugustin Cavalier m = 0x007fffff >> e; 13*f504f610SAugustin Cavalier if ((u.i & m) == 0) 14*f504f610SAugustin Cavalier return x; 15*f504f610SAugustin Cavalier FORCE_EVAL(x + 0x1p120f); 16*f504f610SAugustin Cavalier if (u.i >> 31 == 0) 17*f504f610SAugustin Cavalier u.i += m; 18*f504f610SAugustin Cavalier u.i &= ~m; 19*f504f610SAugustin Cavalier } else { 20*f504f610SAugustin Cavalier FORCE_EVAL(x + 0x1p120f); 21*f504f610SAugustin Cavalier if (u.i >> 31) 22*f504f610SAugustin Cavalier u.f = -0.0; 23*f504f610SAugustin Cavalier else if (u.i << 1) 24*f504f610SAugustin Cavalier u.f = 1.0; 25*f504f610SAugustin Cavalier } 26*f504f610SAugustin Cavalier return u.f; 27*f504f610SAugustin Cavalier } 28