Blame sysdeps/ieee754/dbl-64/s_rint.c
|
Packit Service |
3e830d |
/* @(#)s_rint.c 5.1 93/09/24 */
|
|
Packit |
6c4009 |
/*
|
|
Packit |
6c4009 |
* ====================================================
|
|
Packit |
6c4009 |
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
Packit |
6c4009 |
*
|
|
Packit |
6c4009 |
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
Packit |
6c4009 |
* Permission to use, copy, modify, and distribute this
|
|
Packit |
6c4009 |
* software is freely granted, provided that this notice
|
|
Packit |
6c4009 |
* is preserved.
|
|
Packit |
6c4009 |
* ====================================================
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/*
|
|
Packit |
6c4009 |
* rint(x)
|
|
Packit |
6c4009 |
* Return x rounded to integral value according to the prevailing
|
|
Packit |
6c4009 |
* rounding mode.
|
|
Packit |
6c4009 |
* Method:
|
|
Packit |
6c4009 |
* Using floating addition.
|
|
Packit |
6c4009 |
* Exception:
|
|
Packit |
6c4009 |
* Inexact flag raised if x not equal to rint(x).
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <math.h>
|
|
Packit |
6c4009 |
#include <math_private.h>
|
|
Packit |
6c4009 |
#include <libm-alias-double.h>
|
|
Packit Service |
3e830d |
|
|
Packit Service |
3e830d |
static const double
|
|
Packit Service |
3e830d |
TWO52[2] = {
|
|
Packit Service |
3e830d |
4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
|
|
Packit Service |
3e830d |
-4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
|
|
Packit Service |
3e830d |
};
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
double
|
|
Packit |
6c4009 |
__rint (double x)
|
|
Packit |
6c4009 |
{
|
|
Packit Service |
3e830d |
int32_t i0, j0, sx;
|
|
Packit Service |
3e830d |
double w, t;
|
|
Packit Service |
3e830d |
GET_HIGH_WORD (i0, x);
|
|
Packit Service |
3e830d |
sx = (i0 >> 31) & 1;
|
|
Packit Service |
3e830d |
j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
|
|
Packit |
6c4009 |
if (j0 < 52)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (j0 < 0)
|
|
Packit |
6c4009 |
{
|
|
Packit Service |
3e830d |
w = TWO52[sx] + x;
|
|
Packit Service |
3e830d |
t = w - TWO52[sx];
|
|
Packit Service |
3e830d |
GET_HIGH_WORD (i0, t);
|
|
Packit Service |
3e830d |
SET_HIGH_WORD (t, (i0 & 0x7fffffff) | (sx << 31));
|
|
Packit |
6c4009 |
return t;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (j0 == 0x400)
|
|
Packit Service |
3e830d |
return x + x; /* inf or NaN */
|
|
Packit |
6c4009 |
else
|
|
Packit Service |
3e830d |
return x; /* x is integral */
|
|
Packit |
6c4009 |
}
|
|
Packit Service |
3e830d |
w = TWO52[sx] + x;
|
|
Packit |
6c4009 |
return w - TWO52[sx];
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
#ifndef __rint
|
|
Packit |
6c4009 |
libm_alias_double (__rint, rint)
|
|
Packit |
6c4009 |
#endif
|