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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libm/] [mathfp/] [sf_pow.c] - Blame information for rev 1774

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

Line No. Rev Author Line
1 56 joel
 
2
/* @(#)z_powf.c 1.0 98/08/13 */
3
#include <float.h>
4
#include "fdlibm.h"
5
#include "zmath.h"
6
 
7
float powf (float x, float y)
8
{
9
  float d, t, r = 1.0;
10
  int n, k, sign = 0;
11
  __int32_t px;
12
 
13
  GET_FLOAT_WORD (px, x);
14
 
15
  k = modff (y, &d);
16
  if (k == 0.0)
17
    {
18
      if (modff (ldexpf (y, -1), &t))
19
        sign = 0;
20
      else
21
        sign = 1;
22
    }
23
 
24
  if (x == 0.0 && y <= 0.0)
25
    errno = EDOM;
26
 
27
  else if ((t = y * log (fabsf (x))) >= BIGX)
28
    {
29
      errno = ERANGE;
30
      if (px & 0x80000000)
31
        {
32
          if (!k)
33
            {
34
              errno = EDOM;
35
              x = 0.0;
36
            }
37
          else if (sign)
38
            x = -z_infinity_f.f;
39
          else
40
            x =  z_infinity_f.f;
41
        }
42
 
43
    else
44
      x = z_infinity_f.f;
45
  }
46
 
47
  else if (t < SMALLX)
48
    {
49
      errno = ERANGE;
50
      x = 0.0;
51
    }
52
 
53
  else
54
    {
55
      if ( k && fabsf (d) <= 32767 )
56
        {
57
          n = (int) d;
58
 
59
          if (sign = (n < 0))
60
            n = -n;
61
 
62
          while ( n > 0 )
63
            {
64
              if ((unsigned int) n % 2)
65
                r *= x;
66
              x *= x;
67
              n = (unsigned int) n / 2;
68
            }
69
 
70
          if (sign)
71
            r = 1.0 / r;
72
 
73
          return r;
74
        }
75
 
76
      else
77
        {
78
          if ( px & 0x80000000 )
79
            {
80
              if ( !k )
81
                {
82
                  errno = EDOM;
83
                  return 0.0;
84
                }
85
            }
86
 
87
          x = exp (t);
88
 
89
          if ( sign )
90
            {
91
              px ^= 0x80000000;
92
              SET_FLOAT_WORD (x, px);
93
            }
94
        }
95
      }
96
 
97
  return x;
98
}
99
 
100
#ifdef _DOUBLE_IS_32BITS
101
 
102
double pow (double x, double y)
103
{
104
  return (double) powf ((float) x, (float) y);
105
}
106
 
107
#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.