OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libm/] [common/] [s_lround.c] - Blame information for rev 455

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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