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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libm/] [mathfp/] [sf_logarithm.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
/* @(#)z_logarithmf.c 1.0 98/08/13 */
3
/******************************************************************
4
 * The following routines are coded directly from the algorithms
5
 * and coefficients given in "Software Manual for the Elementary
6
 * Functions" by William J. Cody, Jr. and William Waite, Prentice
7
 * Hall, 1980.
8
 ******************************************************************/
9
/******************************************************************
10
 * Logarithm
11
 *
12
 * Input:
13
 *   x - floating point value
14
 *   ten - indicates base ten numbers
15
 *
16
 * Output:
17
 *   logarithm of x
18
 *
19
 * Description:
20
 *   This routine calculates logarithms.
21
 *
22
 *****************************************************************/
23
 
24
#include "fdlibm.h"
25
#include "zmath.h"
26
 
27
static const float a[] = { -0.5527074855 };
28
static const float b[] = { -0.6632718214e+1 };
29
static const float C1 = 0.693145752;
30
static const float C2 = 1.428606820e-06;
31
static const float C3 = 0.4342944819;
32
 
33
float
34
_DEFUN (logarithmf, (float, int),
35
        float x _AND
36
        int ten)
37
{
38
  int N;
39
  float f, w, z;
40
 
41
  /* Check for domain/range errors here. */
42
  if (x == 0.0)
43
    {
44
      errno = ERANGE;
45
      return (-z_infinity_f.f);
46
    }
47
  else if (x < 0.0)
48
    {
49
      errno = EDOM;
50
      return (z_notanum_f.f);
51
    }
52
  else if (!isfinitef(x))
53
    {
54
      if (isnanf(x))
55
        return (z_notanum_f.f);
56
      else
57
        return (z_infinity_f.f);
58
    }
59
 
60
  /* Get the exponent and mantissa where x = f * 2^N. */
61
  f = frexpf (x, &N);
62
 
63
  z = f - 0.5;
64
 
65
  if (f > __SQRT_HALF)
66
    z = (z - 0.5) / (f * 0.5 + 0.5);
67
  else
68
    {
69
      N--;
70
      z /= (z * 0.5 + 0.5);
71
    }
72
  w = z * z;
73
 
74
  /* Use Newton's method with 4 terms. */
75
  z += z * w * (a[0]) / ((w + 1.0) * w + b[0]);
76
 
77
  if (N != 0)
78
    z = (N * C2 + z) + N * C1;
79
 
80
  if (ten)
81
    z *= C3;
82
 
83
  return (z);
84
}

powered by: WebSVN 2.1.0

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