1 /* Adapted for use as nearbyint by Ulrich Drepper <drepper@cygnus.com>. */
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 * ====================================================
15 * Return x rounded to integral value according to the prevailing
18 * Using floating addition.
20 * Inexact flag raised if x not equal to rint(x).
25 #include <math_private.h>
29 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
30 -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
39 EXTRACT_WORDS64(i0
,x
);
41 j0
= ((i0
>>52)&0x7ff)-0x3ff;
42 if(__builtin_expect(j0
<52, 1)) {
44 libc_feholdexcept (&env
);
45 double w
= TWO52
[sx
]+x
;
46 double t
= w
-TWO52
[sx
];
49 return copysign(t
, x
);
52 if(j0
==0x400) return x
+x
; /* inf or NaN */
53 else return x
; /* x is integral */
55 libc_feholdexcept (&env
);
56 double w
= TWO52
[sx
]+x
;
57 double t
= w
-TWO52
[sx
];
62 weak_alias (__nearbyint
, nearbyint
)
64 strong_alias (__nearbyint
, __nearbyintl
)
65 weak_alias (__nearbyint
, nearbyintl
)