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/] [sf_trunc.c] - Blame information for rev 158

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 truncf(float x)
16
#else
17
        float truncf(x)
18
        float x;
19
#endif
20
{
21
  __int32_t signbit, w, exponent_less_127;
22
 
23
  GET_FLOAT_WORD(w,x);
24
 
25
  /* Extract sign bit. */
26
  signbit = w & 0x80000000;
27
 
28
  /* Extract exponent field. */
29
  exponent_less_127 = ((w & 0x7f800000) >> 23) - 127;
30
 
31
  if (exponent_less_127 < 23)
32
    {
33
      if (exponent_less_127 < 0)
34
        {
35
          /* -1 < x < 1, so result is +0 or -0. */
36
          SET_FLOAT_WORD(x, signbit);
37
        }
38
      else
39
        {
40
          SET_FLOAT_WORD(x, signbit | (w & ~(0x007fffff >> exponent_less_127)));
41
        }
42
    }
43
  else
44
    {
45
      if (exponent_less_127 == 255)
46
        /* x is NaN or infinite. */
47
        return x + x;
48
 
49
      /* All bits in the fraction field are relevant. */
50
    }
51
  return x;
52
}
53
 
54
#ifdef _DOUBLE_IS_32BITS
55
 
56
#ifdef __STDC__
57
        double trunc(double x)
58
#else
59
        double trunc(x)
60
        double x;
61
#endif
62
{
63
        return (double) truncf((float) x);
64
}
65
 
66
#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.