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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libm/] [common/] [sf_round.c] - Blame information for rev 158

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
#ifdef __STDC__
15
        float roundf(float x)
16
#else
17
        float roundf(x)
18
        float x;
19
#endif
20
{
21
  int signbit;
22
  __uint32_t w;
23
  /* Most significant word, least significant word. */
24
  int exponent_less_127;
25
 
26
  GET_FLOAT_WORD(w, x);
27
 
28
  /* Extract sign bit. */
29
  signbit = w & 0x80000000;
30
 
31
  /* Extract exponent field. */
32
  exponent_less_127 = (int)((w & 0x7f800000) >> 23) - 127;
33
 
34
  if (exponent_less_127 < 23)
35
    {
36
      if (exponent_less_127 < 0)
37
        {
38
          w &= 0x80000000;
39
          if (exponent_less_127 == -1)
40
            /* Result is +1.0 or -1.0. */
41
            w |= (127 << 23);
42
        }
43
      else
44
        {
45
          unsigned int exponent_mask = 0x007fffff >> exponent_less_127;
46
          if ((w & exponent_mask) == 0)
47
            /* x has an integral value. */
48
            return x;
49
 
50
          w += 0x00400000 >> exponent_less_127;
51
          w &= ~exponent_mask;
52
        }
53
    }
54
  else
55
    {
56
      if (exponent_less_127 == 128)
57
        /* x is NaN or infinite. */
58
        return x + x;
59
      else
60
        return x;
61
    }
62
  SET_FLOAT_WORD(x, w);
63
  return x;
64
}
65
 
66
#ifdef _DOUBLE_IS_32BITS
67
 
68
#ifdef __STDC__
69
        double round(double x)
70
#else
71
        double round(x)
72
        double x;
73
#endif
74
{
75
        return (double) roundf((float) x);
76
}
77
 
78
#endif /* defined(_DOUBLE_IS_32BITS) */

powered by: WebSVN 2.1.0

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