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.
7 * ====================================================
8 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10 * Developed at SunPro, a Sun Microsystems, Inc. business.
11 * Permission to use, copy, modify, and distribute this
12 * software is freely granted, provided that this notice
14 * ====================================================
17 #if defined(LIBM_SCCS) && !defined(lint)
18 static char rcsid[] = "$NetBSD: $";
23 * Return x rounded to integral value according to the prevailing
26 * Using floating addition.
28 * Inexact flag raised if x not equal to rintl(x).
32 #include "math_private.h"
35 static const long double
40 9.223372036854775808000000e+18, /* 0x403E, 0x00000000, 0x00000000 */
41 -9.223372036854775808000000e+18 /* 0xC03E, 0x00000000, 0x00000000 */
45 long double __rintl(long double x)
47 long double __rintl(x)
54 GET_LDOUBLE_WORDS(se,i0,i1,x);
56 j0 = (se&0x7fff)-0x3fff;
59 if(((se&0x7fff)|i0|i1)==0) return x;
62 i0 |= (i1|-i1)&0x80000000;
63 SET_LDOUBLE_MSW(x,i0);
66 GET_LDOUBLE_EXP(i0,t);
67 SET_LDOUBLE_EXP(t,(i0&0x7fff)|(sx<<15));
71 if(((i0&i)|i1)==0) return x; /* x is integral */
74 if(j0==30) i1 = 0x40000000; else
75 i0 = (i0&(~i))|((0x20000000)>>j0);
79 if(j0==0x4000) return x+x; /* inf or NaN */
80 else return x; /* x is integral */
82 i = ((u_int32_t)(0xffffffff))>>(j0-31);
83 if((i1&i)==0) return x; /* x is integral */
85 if((i1&i)!=0) i1 = (i1&(~i))|((0x40000000)>>(j0-31));
87 SET_LDOUBLE_WORDS(x,se,i0,i1);
91 weak_alias (__rintl, rintl)