]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/libm-ieee754/s_nearbyintl.c
b6a865443ac8abc9da81064c7f95cb7546e43d66
1 /* s_rintl.c -- long double version of s_rint.c.
2 * Conversion to long double by Ulrich Drepper,
3 * Cygnus Support, drepper@cygnus.com.
5 /* Adapted for use as nearbyint by Ulrich Drepper <drepper@cygnus.com>. */
8 * ====================================================
9 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
11 * Developed at SunPro, a Sun Microsystems, Inc. business.
12 * Permission to use, copy, modify, and distribute this
13 * software is freely granted, provided that this notice
15 * ====================================================
18 #if defined(LIBM_SCCS) && !defined(lint)
19 static char rcsid
[] = "$NetBSD: $";
24 * Return x rounded to integral value according to the prevailing
27 * Using floating addition.
29 * Inexact flag raised if x not equal to rintl(x).
34 #include "math_private.h"
37 static const long double
42 9.223372036854775808000000e+18, /* 0x403E, 0x00000000, 0x00000000 */
43 -9.223372036854775808000000e+18 /* 0xC03E, 0x00000000, 0x00000000 */
47 long double __rintl(long double x
)
49 long double __rintl(x
)
57 GET_LDOUBLE_WORDS(se
,i0
,i1
,x
);
59 j0
= (se
&0x7fff)-0x3fff;
62 if(((se
&0x7fff)|i0
|i1
)==0) return x
;
65 i0
|= (i1
|-i1
)&0x80000000;
66 SET_LDOUBLE_MSW(x
,i0
);
71 GET_LDOUBLE_EXP(i0
,t
);
72 SET_LDOUBLE_EXP(t
,(i0
&0x7fff)|(sx
<<15));
76 if(((i0
&i
)|i1
)==0) return x
; /* x is integral */
79 if(j0
==31) i1
= 0x40000000; else
80 i0
= (i0
&(~i
))|((0x20000000)>>j0
);
82 if (j0 >= 30) i1 = 0x80000000 >> (j0 - 30);
83 i0 = (i0&(~i))|((0x20000000)>>j0);
84 If yes, this should be correct in s_rint and
85 s_rintf, too. -- drepper@cygnus.com */
89 if(j0
==0x4000) return x
+x
; /* inf or NaN */
90 else return x
; /* x is integral */
92 i
= ((u_int32_t
)(0xffffffff))>>(j0
-31);
93 if((i1
&i
)==0) return x
; /* x is integral */
95 if((i1
&i
)!=0) i1
= (i1
&(~i
))|((0x40000000)>>(j0
-31));
97 SET_LDOUBLE_WORDS(x
,se
,i0
,i1
);
104 weak_alias (__rintl
, rintl
)