OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc1/] [newlib/] [libm/] [common/] [s_llround.c] - Diff between revs 207 and 345

Only display areas with differences | Details | Blame | View Log

Rev 207 Rev 345
/* lround adapted to be llround for Newlib, 2009 by Craig Howland.  */
/* lround adapted to be llround for Newlib, 2009 by Craig Howland.  */
/*
/*
 * ====================================================
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * software is freely granted, provided that this notice
 * is preserved.
 * is preserved.
 * ====================================================
 * ====================================================
 */
 */
 
 
#include "fdlibm.h"
#include "fdlibm.h"
 
 
#ifndef _DOUBLE_IS_32BITS
#ifndef _DOUBLE_IS_32BITS
 
 
long long int
long long int
llround(double x)
llround(double x)
{
{
  __int32_t sign, exponent_less_1023;
  __int32_t sign, exponent_less_1023;
  /* Most significant word, least significant word. */
  /* Most significant word, least significant word. */
  __uint32_t msw, lsw;
  __uint32_t msw, lsw;
  long long int result;
  long long int result;
 
 
  EXTRACT_WORDS(msw, lsw, x);
  EXTRACT_WORDS(msw, lsw, x);
 
 
  /* Extract sign. */
  /* Extract sign. */
  sign = ((msw & 0x80000000) ? -1 : 1);
  sign = ((msw & 0x80000000) ? -1 : 1);
  /* Extract exponent field. */
  /* Extract exponent field. */
  exponent_less_1023 = ((msw & 0x7ff00000) >> 20) - 1023;
  exponent_less_1023 = ((msw & 0x7ff00000) >> 20) - 1023;
  msw &= 0x000fffff;
  msw &= 0x000fffff;
  msw |= 0x00100000;
  msw |= 0x00100000;
 
 
  if (exponent_less_1023 < 20)
  if (exponent_less_1023 < 20)
    {
    {
      if (exponent_less_1023 < 0)
      if (exponent_less_1023 < 0)
        {
        {
          if (exponent_less_1023 < -1)
          if (exponent_less_1023 < -1)
            return 0;
            return 0;
          else
          else
            return sign;
            return sign;
        }
        }
      else
      else
        {
        {
          msw += 0x80000 >> exponent_less_1023;
          msw += 0x80000 >> exponent_less_1023;
          result = msw >> (20 - exponent_less_1023);
          result = msw >> (20 - exponent_less_1023);
        }
        }
    }
    }
  else if (exponent_less_1023 < (8 * sizeof (long long int)) - 1)
  else if (exponent_less_1023 < (8 * sizeof (long long int)) - 1)
    {
    {
      if (exponent_less_1023 >= 52)
      if (exponent_less_1023 >= 52)
        result = ((long long int) msw << (exponent_less_1023 - 20)) | (lsw << (exponent_less_1023 - 52));
        result = ((long long int) msw << (exponent_less_1023 - 20)) | (lsw << (exponent_less_1023 - 52));
      else
      else
        {
        {
          unsigned int tmp = lsw + (0x80000000 >> (exponent_less_1023 - 20));
          unsigned int tmp = lsw + (0x80000000 >> (exponent_less_1023 - 20));
          if (tmp < lsw)
          if (tmp < lsw)
            ++msw;
            ++msw;
          result = ((long long int) msw << (exponent_less_1023 - 20)) | (tmp >> (52 - exponent_less_1023));
          result = ((long long int) msw << (exponent_less_1023 - 20)) | (tmp >> (52 - exponent_less_1023));
        }
        }
    }
    }
  else
  else
    /* Result is too large to be represented by a long long int. */
    /* Result is too large to be represented by a long long int. */
    return (long long int)x;
    return (long long int)x;
 
 
  return sign * result;
  return sign * result;
}
}
 
 
#endif /* _DOUBLE_IS_32BITS */
#endif /* _DOUBLE_IS_32BITS */
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.