source: trunk/libs/newlib/src/newlib/libm/common/sf_lround.c @ 620

Last change on this file since 620 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 1.3 KB
Line 
1/*
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        long int lroundf(float x)
16#else
17        long int lroundf(x)
18        float x;
19#endif
20{
21  __int32_t exponent_less_127;
22  __uint32_t w;
23  long int result;
24  __int32_t sign;
25
26  GET_FLOAT_WORD (w, x);
27  exponent_less_127 = ((w & 0x7f800000) >> 23) - 127;
28  sign = (w & 0x80000000) != 0 ? -1 : 1;
29  w &= 0x7fffff;
30  w |= 0x800000;
31
32  if (exponent_less_127 < (int)((8 * sizeof (long int)) - 1))
33    {
34      if (exponent_less_127 < 0)
35        return exponent_less_127 < -1 ? 0 : sign;
36      else if (exponent_less_127 >= 23)
37        result = (long int) w << (exponent_less_127 - 23);
38      else
39        {
40          w += 0x400000 >> exponent_less_127;
41          result = w >> (23 - exponent_less_127);
42        }
43    }
44  else
45      return (long int) x;
46
47  return sign * result;
48}
49
50#ifdef _DOUBLE_IS_32BITS
51
52#ifdef __STDC__
53        long int lround(double x)
54#else
55        long int lround(x)
56        double x;
57#endif
58{
59        return lroundf((float) x);
60}
61
62#endif /* defined(_DOUBLE_IS_32BITS) */
Note: See TracBrowser for help on using the repository browser.