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 * ====================================================
20 * Return x rounded to integral value according to the prevailing
23 * Using floating addition.
25 * Inexact flag raised if x not equal to rintl(x).
30 #include "math_private.h"
33 static const long double
38 9.223372036854775808000000e+18, /* 0x403E, 0x00000000, 0x00000000 */
39 -9.223372036854775808000000e+18 /* 0xC03E, 0x00000000, 0x00000000 */
43 long double __nearbyintl(long double x)
45 long double __nearbyintl(x)
53 GET_LDOUBLE_WORDS(se,i0,i1,x);
55 j0 = (se&0x7fff)-0x3fff;
58 if(((se&0x7fff)|i0|i1)==0) return x;
61 i0 |= (i1|-i1)&0x80000000;
62 SET_LDOUBLE_MSW(x,i0);
67 GET_LDOUBLE_EXP(i0,t);
68 SET_LDOUBLE_EXP(t,(i0&0x7fff)|(sx<<15));
72 if(((i0&i)|i1)==0) return x; /* x is integral */
75 if (j0==30) i1 = 0x40000000; else
76 i0 = (i0&(~i))|((0x20000000)>>j0);
80 if(j0==0x4000) return x+x; /* inf or NaN */
81 else return x; /* x is integral */
83 i = ((u_int32_t)(0xffffffff))>>(j0-31);
84 if((i1&i)==0) return x; /* x is integral */
86 if((i1&i)!=0) i1 = (i1&(~i))|((0x40000000)>>(j0-31));
88 SET_LDOUBLE_WORDS(x,se,i0,i1);
95 weak_alias (__nearbyintl, nearbyintl)