1 /*
2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4 *
5 * Developed at SunPro, a Sun Microsystems, Inc. business.
6 * Permission to use, copy, modify, and distribute this
7 * software is freely granted, provided that this notice
8 * is preserved.
9 * ====================================================
10 */
11
12 #include "fdlibm.h"
13
14 float
truncf(float x)15 truncf(float x)
16 {
17 int32_t ix = _asint32 (x);
18 int32_t mask;
19 int exp;
20
21 exp = _exponent32(ix) - 127;
22
23 if (unlikely(exp == 128))
24 return x + x;
25
26 /* compute portion of value with useful bits */
27 if (exp < 0)
28 /* less than one, save sign bit */
29 mask = 0x80000000;
30 else
31 /* otherwise, save sign, exponent and any useful bits */
32 mask = ~(0x007fffff >> exp);
33
34 return _asfloat(ix & mask);
35 }
36
37 _MATH_ALIAS_f_f(trunc)
38