Blame sysdeps/ieee754/flt-32/s_rintf.c

Packit 6c4009
/* s_rintf.c -- float version of s_rint.c.
Packit 6c4009
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
Packit 6c4009
 */
Packit 6c4009
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
#include <math.h>
Packit 6c4009
#include <math_private.h>
Packit 6c4009
#include <libm-alias-float.h>
Packit Bot a0b6f3
#include <math-use-builtins.h>
Packit 6c4009
Packit 6c4009
float
Packit Bot 7c8e80
__rintf (float x)
Packit 6c4009
{
Packit Bot a0b6f3
#if USE_RINTF_BUILTIN
Packit Bot a0b6f3
  return __builtin_rintf (x);
Packit Bot a0b6f3
#else
Packit Bot a0b6f3
  /* Use generic implementation.  */
Packit Bot a0b6f3
  static const float
Packit Bot a0b6f3
    TWO23[2] = {
Packit Bot a0b6f3
		8.3886080000e+06, /* 0x4b000000 */
Packit Bot a0b6f3
		-8.3886080000e+06, /* 0xcb000000 */
Packit Bot a0b6f3
  };
Packit Bot 7c8e80
  int32_t i0, j0, sx;
Packit Bot 7c8e80
  float w, t;
Packit Bot 7c8e80
  GET_FLOAT_WORD (i0, x);
Packit Bot 7c8e80
  sx = (i0 >> 31) & 1;
Packit Bot 7c8e80
  j0 = ((i0 >> 23) & 0xff) - 0x7f;
Packit Bot 7c8e80
  if (j0 < 23)
Packit Bot 7c8e80
    {
Packit Bot 7c8e80
      if(j0 < 0)
Packit Bot 7c8e80
	{
Packit Bot 7c8e80
	  w = TWO23[sx] + x;
Packit Bot 7c8e80
	  t =  w - TWO23[sx];
Packit Bot 7c8e80
	  GET_FLOAT_WORD (i0, t);
Packit Bot 7c8e80
	  SET_FLOAT_WORD (t, (i0 & 0x7fffffff) | (sx << 31));
Packit Bot 7c8e80
	  return t;
Packit 6c4009
	}
Packit Bot 7c8e80
    }
Packit Bot 7c8e80
  else
Packit Bot 7c8e80
    {
Packit Bot 7c8e80
      if (j0 == 0x80)
Packit Bot 7c8e80
	return x + x;		/* inf or NaN  */
Packit Bot 7c8e80
      else
Packit Bot 7c8e80
	return x;		/* x is integral  */
Packit Bot 7c8e80
    }
Packit Bot 7c8e80
  w = TWO23[sx] + x;
Packit Bot 7c8e80
  return w - TWO23[sx];
Packit Bot a0b6f3
#endif /* ! USE_RINTF_BUILTIN  */
Packit 6c4009
}
Packit 6c4009
#ifndef __rintf
Packit 6c4009
libm_alias_float (__rint, rint)
Packit 6c4009
#endif