mirror of
https://github.com/adtools/clib2.git
synced 2025-12-08 14:59:05 +00:00
- Implemented lrintf(), lrint(), lroundf(), lround(), nearbyintf(),
nearbyint(), remquof(), remquo(), roundf(), round(), tgammaf(), tgamma(), truncf(), trunc(). Sort of implemented fmaf() and fma(), which really ought to be done in "SIMD" fashion. This completes the "real" floating point math library (ignoring for a moment that the floating point environment code is still not implemented). git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@15035 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_lround.c,v 1.1 2005-05-29 11:19:01 obarthel Exp $
|
||||
* $Id: math_lround.c,v 1.2 2005-10-09 10:38:55 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@ -29,6 +29,15 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||
*
|
||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software is freely granted, provided that this notice
|
||||
* is preserved.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@ -44,8 +53,52 @@
|
||||
long int
|
||||
lround(double x)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
LONG sign, exponent_less_1023;
|
||||
/* Most significant word, least significant word. */
|
||||
ULONG msw, lsw;
|
||||
long int result;
|
||||
|
||||
EXTRACT_WORDS(msw, lsw, x);
|
||||
|
||||
/* Extract sign. */
|
||||
sign = ((msw & 0x80000000) ? -1 : 1);
|
||||
/* Extract exponent field. */
|
||||
exponent_less_1023 = ((msw & 0x7ff00000) >> 20) - 1023;
|
||||
msw &= 0x000fffff;
|
||||
msw |= 0x00100000;
|
||||
|
||||
if (exponent_less_1023 < 20)
|
||||
{
|
||||
if (exponent_less_1023 < 0)
|
||||
{
|
||||
if (exponent_less_1023 < -1)
|
||||
return 0;
|
||||
else
|
||||
return sign;
|
||||
}
|
||||
else
|
||||
{
|
||||
msw += 0x80000 >> exponent_less_1023;
|
||||
result = msw >> (20 - exponent_less_1023);
|
||||
}
|
||||
}
|
||||
else if (exponent_less_1023 < (8 * sizeof (long int)) - 1)
|
||||
{
|
||||
if (exponent_less_1023 >= 52)
|
||||
result = ((long int) msw << (exponent_less_1023 - 20)) | (lsw << (exponent_less_1023 - 52));
|
||||
else
|
||||
{
|
||||
unsigned int tmp = lsw + (0x80000000 >> (exponent_less_1023 - 20));
|
||||
if (tmp < lsw)
|
||||
++msw;
|
||||
result = ((long int) msw << (exponent_less_1023 - 20)) | (tmp >> (52 - exponent_less_1023));
|
||||
}
|
||||
}
|
||||
else
|
||||
/* Result is too large to be represented by a long int. */
|
||||
return (long int)x;
|
||||
|
||||
return sign * result;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
Reference in New Issue
Block a user