1
0
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:
Olaf Barthel
2005-10-09 10:38:56 +00:00
parent 159e55f1e6
commit bb2376a6ed
22 changed files with 616 additions and 71 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: math_truncf.c,v 1.1 2005-05-29 11:19:01 obarthel Exp $
* $Id: math_truncf.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,37 @@
float
truncf(float x)
{
/* ZZZ unimplemented */
return(0);
LONG signbit, w, exponent_less_127;
GET_FLOAT_WORD(w,x);
/* Extract sign bit. */
signbit = w & 0x80000000;
/* Extract exponent field. */
exponent_less_127 = ((w & 0x7f800000) >> 23) - 127;
if (exponent_less_127 < 23)
{
if (exponent_less_127 < 0)
{
/* -1 < x < 1, so result is +0 or -0. */
SET_FLOAT_WORD(x, signbit);
}
else
{
SET_FLOAT_WORD(x, signbit | (w & ~(0x007fffff >> exponent_less_127)));
}
}
else
{
if (exponent_less_127 == 255)
/* x is NaN or infinite. */
return x + x;
/* All bits in the fraction field are relevant. */
}
return x;
}
/****************************************************************************/