/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include "libm.h"
#include "fma.h"
#include "fenv_inlines.h"
#if defined(__sparc)
static union {
unsigned i;
float f;
long double
__nearbyintl(long double x) {
union {
unsigned i[4];
long double q;
} xx;
unsigned int fsr;
int rm, j;
volatile float dummy;
xx.q = x;
/* handle trivial cases */
/* check for signaling nan */
}
return (xx.q);
return (x);
/* get the rounding mode */
/* flip the sense of directed roundings if x is negative */
if (sx)
/* handle |x| < 1 */
if (hx < 0x3fff0000) {
else
return (xx.q);
}
/* round x at the integer bit */
if (j >= 96) {
i = 1 << (j - 96);
frac |= 1;
if (!frac)
return (x);
xx.i[0] &= ~(i - 1);
xx.i[0] += i;
} else if (j >= 64) {
i = 1 << (j - 64);
frac |= 1;
if (!frac)
return (x);
xx.i[1] += i;
if (xx.i[1] == 0)
xx.i[0]++;
}
} else if (j >= 32) {
i = 1 << (j - 32);
frac |= 1;
if (!frac)
return (x);
xx.i[3] = 0;
xx.i[2] += i;
if (xx.i[2] == 0)
if (++xx.i[1] == 0)
xx.i[0]++;
}
} else {
i = 1 << j;
if (!frac)
return (x);
xx.i[3] += i;
if (xx.i[3] == 0)
if (++xx.i[2] == 0)
if (++xx.i[1] == 0)
xx.i[0]++;
}
}
return (xx.q);
}
/* inline template */
extern long double frndint(long double);
long double
__nearbyintl(long double x) {
long double z;
/* save the control and status words, mask the inexact exception */
z = frndint(x);
/*
* restore the control and status words, preserving all but the
* inexact flag
*/
return (z);
}
#else
#endif