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] - Blame information for rev 345

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
/* lround adapted to be llround for Newlib, 2009 by Craig Howland.  */
2
/*
3
 * ====================================================
4
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * Developed at SunPro, a Sun Microsystems, Inc. business.
7
 * Permission to use, copy, modify, and distribute this
8
 * software is freely granted, provided that this notice
9
 * is preserved.
10
 * ====================================================
11
 */
12
 
13
#include "fdlibm.h"
14
 
15
#ifndef _DOUBLE_IS_32BITS
16
 
17
long long int
18
llround(double x)
19
{
20
  __int32_t sign, exponent_less_1023;
21
  /* Most significant word, least significant word. */
22
  __uint32_t msw, lsw;
23
  long long int result;
24
 
25
  EXTRACT_WORDS(msw, lsw, x);
26
 
27
  /* Extract sign. */
28
  sign = ((msw & 0x80000000) ? -1 : 1);
29
  /* Extract exponent field. */
30
  exponent_less_1023 = ((msw & 0x7ff00000) >> 20) - 1023;
31
  msw &= 0x000fffff;
32
  msw |= 0x00100000;
33
 
34
  if (exponent_less_1023 < 20)
35
    {
36
      if (exponent_less_1023 < 0)
37
        {
38
          if (exponent_less_1023 < -1)
39
            return 0;
40
          else
41
            return sign;
42
        }
43
      else
44
        {
45
          msw += 0x80000 >> exponent_less_1023;
46
          result = msw >> (20 - exponent_less_1023);
47
        }
48
    }
49
  else if (exponent_less_1023 < (8 * sizeof (long long int)) - 1)
50
    {
51
      if (exponent_less_1023 >= 52)
52
        result = ((long long int) msw << (exponent_less_1023 - 20)) | (lsw << (exponent_less_1023 - 52));
53
      else
54
        {
55
          unsigned int tmp = lsw + (0x80000000 >> (exponent_less_1023 - 20));
56
          if (tmp < lsw)
57
            ++msw;
58
          result = ((long long int) msw << (exponent_less_1023 - 20)) | (tmp >> (52 - exponent_less_1023));
59
        }
60
    }
61
  else
62
    /* Result is too large to be represented by a long long int. */
63
    return (long long int)x;
64
 
65
  return sign * result;
66
}
67
 
68
#endif /* _DOUBLE_IS_32BITS */

powered by: WebSVN 2.1.0

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