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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libm/] [mathfp/] [s_logarithm.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_logarithm.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
/*
11
FUNCTION
12
       <<log>>, <<logf>>, <<log10>>, <<log10f>>, <<logarithm>>, <<logarithmf>>---natural or base 10 logarithms
13
 
14
INDEX
15
    log
16
INDEX
17
    logf
18
INDEX
19
    log10
20
INDEX
21
    log10f
22
 
23
ANSI_SYNOPSIS
24
       #include <math.h>
25
       double log(double <[x]>);
26
       float logf(float <[x]>);
27
       double log10(double <[x]>);
28
       float log10f(float <[x]>);
29
 
30
TRAD_SYNOPSIS
31
       #include <math.h>
32
       double log(<[x]>);
33
       double <[x]>;
34
 
35
       float logf(<[x]>);
36
       float <[x]>;
37
 
38
       double log10(<[x]>);
39
       double <[x]>;
40
 
41
       float log10f(<[x]>);
42
       float <[x]>;
43
 
44
DESCRIPTION
45
Return the natural or base 10 logarithm of <[x]>, that is, its logarithm base e
46
(where e is the base of the natural system of logarithms, 2.71828@dots{}) or
47
base 10.
48
<<log>> and <<logf>> are identical save for the return and argument types.
49
<<log10>> and <<log10f>> are identical save for the return and argument types.
50
 
51
RETURNS
52
Normally, returns the calculated value.  When <[x]> is zero, the
53
returned value is <<-HUGE_VAL>> and <<errno>> is set to <<ERANGE>>.
54
When <[x]> is negative, the returned value is <<-HUGE_VAL>> and
55
<<errno>> is set to <<EDOM>>.  You can control the error behavior via
56
<<matherr>>.
57
 
58
PORTABILITY
59
<<log>> is ANSI, <<logf>> is an extension.
60
<<log10>> is ANSI, <<log10f>> is an extension.
61
*/
62
 
63
 
64
/******************************************************************
65
 * Logarithm
66
 *
67
 * Input:
68
 *   x - floating point value
69
 *   ten - indicates base ten numbers
70
 *
71
 * Output:
72
 *   logarithm of x
73
 *
74
 * Description:
75
 *   This routine calculates logarithms.
76
 *
77
 *****************************************************************/
78
 
79
#include "fdlibm.h"
80
#include "zmath.h"
81
 
82
#ifndef _DOUBLE_IS_32BITS
83
 
84
static const double a[] = { -0.64124943423745581147e+02,
85
                             0.16383943563021534222e+02,
86
                            -0.78956112887481257267 };
87
static const double b[] = { -0.76949932108494879777e+03,
88
                             0.31203222091924532844e+03,
89
                            -0.35667977739034646171e+02 };
90
static const double C1 =  22713.0 / 32768.0;
91
static const double C2 =  1.428606820309417232e-06;
92
static const double C3 =  0.43429448190325182765;
93
 
94
double
95
_DEFUN (logarithm, (double, int),
96
        double x _AND
97
        int ten)
98
{
99
  int N;
100
  double f, w, z;
101
 
102
  /* Check for domain error here. */
103
  if (x <= 0.0)
104
    {
105
      errno = ERANGE;
106
      return (z_notanum.d);
107
    }
108
 
109
  /* Get the exponent and mantissa where x = f * 2^N. */
110
  f = frexp (x, &N);
111
 
112
  z = f - 0.5;
113
 
114
  if (f > __SQRT_HALF)
115
    z = (z - 0.5) / (f * 0.5 + 0.5);
116
  else
117
    {
118
      N--;
119
      z /= (z * 0.5 + 0.5);
120
    }
121
  w = z * z;
122
 
123
  /* Use Newton's method with 4 terms. */
124
  z += z * w * ((a[2] * w + a[1]) * w + a[0]) / (((w + b[2]) * w + b[1]) * w + b[0]);
125
 
126
  if (N != 0)
127
    z = (N * C2 + z) + N * C1;
128
 
129
  if (ten)
130
    z *= C3;
131
 
132
  return (z);
133
}
134
 
135
#endif /* _DOUBLE_IS_32BITS */

powered by: WebSVN 2.1.0

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