2 /* @(#)s_rint.c 1.3 95/01/18 */
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7 * Developed at SunSoft, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
11 * ====================================================
16 * Return x rounded to integral value according to the prevailing
19 * Using floating addition.
21 * Inexact flag raised if x not equal to rint(x).
26 #ifndef _DOUBLE_IS_32BITS
34 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
35 -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
49 EXTRACT_WORDS(i0
,i1
,x
);
51 j0
= ((i0
>>20)&0x7ff)-0x3ff;
54 if(((i0
&0x7fffffff)|i1
)==0) return x
;
57 i0
|= ((i1
|-i1
)>>12)&0x80000;
62 SET_HIGH_WORD(t
,(i0
&0x7fffffff)|(sx
<<31));
66 if(((i0
&i
)|i1
)==0) return x
; /* x is integral */
69 if(j0
==19) i1
= 0x40000000; else
70 i0
= (i0
&(~i
))|((0x20000)>>j0
);
74 if(j0
==0x400) return x
+x
; /* inf or NaN */
75 else return x
; /* x is integral */
77 i
= ((uint32_t)(0xffffffff))>>(j0
-20);
78 if((i1
&i
)==0) return x
; /* x is integral */
80 if((i1
&i
)!=0) i1
= (i1
&(~i
))|((0x40000000)>>(j0
-20));
82 INSERT_WORDS(x
,i0
,i1
);
86 #endif /* _DOUBLE_IS_32BITS */