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_trunc.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
        double trunc(double x)
18
#else
19
        double trunc(x)
20
        double x;
21
#endif
22
{
23
  int signbit;
24
  /* Most significant word, least significant word. */
25
  int msw;
26
  unsigned int lsw;
27
  int exponent_less_1023;
28
 
29
  EXTRACT_WORDS(msw, lsw, x);
30
 
31
  /* Extract sign bit. */
32
  signbit = msw & 0x80000000;
33
 
34
  /* Extract exponent field. */
35
  exponent_less_1023 = ((msw & 0x7ff00000) >> 20) - 1023;
36
 
37
  if (exponent_less_1023 < 20)
38
    {
39
      /* All significant digits are in msw. */
40
      if (exponent_less_1023 < 0)
41
        {
42
          /* -1 < x < 1, so result is +0 or -0. */
43
          INSERT_WORDS(x, signbit, 0);
44
        }
45
      else
46
        {
47
          /* All relevant fraction bits are in msw, so lsw of the result is 0. */
48
          INSERT_WORDS(x, signbit | (msw & ~(0x000fffff >> exponent_less_1023)), 0);
49
        }
50
    }
51
  else if (exponent_less_1023 > 51)
52
    {
53
      if (exponent_less_1023 == 1024)
54
        {
55
          /* x is infinite, or not a number, so trigger an exception. */
56
          return x + x;
57
        }
58
      /* All bits in the fraction fields of the msw and lsw are needed in the result. */
59
    }
60
  else
61
    {
62
      /* All fraction bits in msw are relevant.  Truncate irrelevant
63
         bits from lsw. */
64
      INSERT_WORDS(x, msw, lsw & ~(0xffffffffu >> (exponent_less_1023 - 20)));
65
    }
66
  return x;
67
}
68
 
69
#endif /* _DOUBLE_IS_32BITS */

powered by: WebSVN 2.1.0

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