1 /* origin: FreeBSD /usr/src/lib/msun/src/s_trunc.c */
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 * Developed at SunPro, a Sun Microsystems, Inc. business.
7 * Permission to use, copy, modify, and distribute this
8 * software is freely granted, provided that this notice
10 * ====================================================
14 * Return x rounded toward 0 to integral value
18 * Inexact flag raised if x not equal to trunc(x).
23 static const double huge = 1.0e300;
25 double trunc(double x)
30 EXTRACT_WORDS(i0, i1, x);
31 j0 = ((i0>>20)&0x7ff) - 0x3ff;
33 if (j0 < 0) { /* |x|<1, return 0*sign(x) */
34 /* raise inexact if x != 0 */
42 return x; /* x is integral */
51 return x + x; /* inf or NaN */
52 return x; /* x is integral */
54 i = (uint32_t)0xffffffff>>(j0-20);
56 return x; /* x is integral */
61 INSERT_WORDS(x, i0, i1);