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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib-1.10.0/] [newlib/] [libm/] [mathfp/] [sf_logarithm.c] - Blame information for rev 1773

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

Line No. Rev Author Line
1 1010 ivang
 
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 error here. */
42
  if (x <= 0.0)
43
    {
44
      errno = ERANGE;
45
      return (z_notanum_f.f);
46
    }
47
 
48
  /* Get the exponent and mantissa where x = f * 2^N. */
49
  f = frexpf (x, &N);
50
 
51
  z = f - 0.5;
52
 
53
  if (f > __SQRT_HALF)
54
    z = (z - 0.5) / (f * 0.5 + 0.5);
55
  else
56
    {
57
      N--;
58
      z /= (z * 0.5 + 0.5);
59
    }
60
  w = z * z;
61
 
62
  /* Use Newton's method with 4 terms. */
63
  z += z * w * (a[0]) / ((w + 1.0) * w + b[0]);
64
 
65
  if (N != 0)
66
    z = (N * C2 + z) + N * C1;
67
 
68
  if (ten)
69
    z *= C3;
70
 
71
  return (z);
72
}

powered by: WebSVN 2.1.0

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