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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib-1.10.0/] [newlib/] [libm/] [math/] [w_log.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1010 ivang
 
2
/* @(#)w_log.c 5.1 93/09/24 */
3
/*
4
 * ====================================================
5
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6
 *
7
 * Developed at SunPro, a Sun Microsystems, Inc. business.
8
 * Permission to use, copy, modify, and distribute this
9
 * software is freely granted, provided that this notice
10
 * is preserved.
11
 * ====================================================
12
 */
13
 
14
/*
15
FUNCTION
16
       <<log>>, <<logf>>---natural logarithms
17
 
18
INDEX
19
    log
20
INDEX
21
    logf
22
 
23
ANSI_SYNOPSIS
24
       #include <math.h>
25
       double log(double <[x]>);
26
       float logf(float <[x]>);
27
 
28
TRAD_SYNOPSIS
29
       #include <math.h>
30
       double log(<[x]>);
31
       double <[x]>;
32
 
33
       float logf(<[x]>);
34
       float <[x]>;
35
 
36
DESCRIPTION
37
Return the natural logarithm of <[x]>, that is, its logarithm base e
38
(where e is the base of the natural system of logarithms, 2.71828@dots{}).
39
<<log>> and <<logf>> are identical save for the return and argument types.
40
 
41
You can use the (non-ANSI) function <<matherr>> to specify error
42
handling for these functions.
43
 
44
RETURNS
45
Normally, returns the calculated value.  When <[x]> is zero, the
46
returned value is <<-HUGE_VAL>> and <<errno>> is set to <<ERANGE>>.
47
When <[x]> is negative, the returned value is <<-HUGE_VAL>> and
48
<<errno>> is set to <<EDOM>>.  You can control the error behavior via
49
<<matherr>>.
50
 
51
PORTABILITY
52
<<log>> is ANSI, <<logf>> is an extension.
53
*/
54
 
55
/*
56
 * wrapper log(x)
57
 */
58
 
59
#include "fdlibm.h"
60
#include <errno.h>
61
 
62
#ifndef _DOUBLE_IS_32BITS
63
 
64
#ifdef __STDC__
65
        double log(double x)            /* wrapper log */
66
#else
67
        double log(x)                   /* wrapper log */
68
        double x;
69
#endif
70
{
71
#ifdef _IEEE_LIBM
72
        return __ieee754_log(x);
73
#else
74
        double z;
75
        struct exception exc;
76
        z = __ieee754_log(x);
77
        if(_LIB_VERSION == _IEEE_ || isnan(x) || x > 0.0) return z;
78
#ifndef HUGE_VAL 
79
#define HUGE_VAL inf
80
        double inf = 0.0;
81
 
82
        SET_HIGH_WORD(inf,0x7ff00000);  /* set inf to infinite */
83
#endif
84
        exc.name = "log";
85
        exc.err = 0;
86
        exc.arg1 = x;
87
        exc.arg2 = x;
88
        if (_LIB_VERSION == _SVID_)
89
           exc.retval = -HUGE;
90
        else
91
           exc.retval = -HUGE_VAL;
92
        if(x==0.0) {
93
            /* log(0) */
94
            exc.type = SING;
95
            if (_LIB_VERSION == _POSIX_)
96
               errno = ERANGE;
97
            else if (!matherr(&exc)) {
98
               errno = EDOM;
99
            }
100
        } else {
101
            /* log(x<0) */
102
            exc.type = DOMAIN;
103
            if (_LIB_VERSION == _POSIX_)
104
               errno = EDOM;
105
            else if (!matherr(&exc)) {
106
               errno = EDOM;
107
            }
108
        }
109
        if (exc.err != 0)
110
           errno = exc.err;
111
        return exc.retval;
112
#endif
113
}
114
 
115
#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.