OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.18.0/] [newlib/] [libm/] [common/] [s_log2.c] - Blame information for rev 252

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

Line No. Rev Author Line
1 207 jeremybenn
/* @(#)s_log2.c 5.1 93/09/24 */
2
/* Modification from s_exp10.c Yaakov Selkowitz 2009.  */
3
 
4
/*
5
 * ====================================================
6
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7
 *
8
 * Developed at SunPro, a Sun Microsystems, Inc. business.
9
 * Permission to use, copy, modify, and distribute this
10
 * software is freely granted, provided that this notice
11
 * is preserved.
12
 * ====================================================
13
 */
14
 
15
/*
16
FUNCTION
17
        <<log2>>, <<log2f>>--base 2 logarithm
18
INDEX
19
        log2
20
INDEX
21
        log2f
22
 
23
ANSI_SYNOPSIS
24
        #include <math.h>
25
        double log2(double <[x]>);
26
        float log2f(float <[x]>);
27
 
28
DESCRIPTION
29
The <<log2>> functions compute the base-2 logarithm of <[x]>.  A domain error
30
occurs if the argument is less than zero.  A range error occurs if the
31
argument is zero.
32
 
33
The Newlib implementations are not full, intrinisic calculations, but
34
rather are derivatives based on <<log>>.  (Accuracy might be slightly off from
35
a direct calculation.)  In addition to functions, they are also implemented as
36
macros defined in math.h:
37
. #define log2(x) (log (x) / _M_LOG2_E)
38
. #define log2f(x) (logf (x) / (float) _M_LOG2_E)
39
To use the functions instead, just undefine the macros first.
40
 
41
You can use the (non-ANSI) function <<matherr>> to specify error
42
handling for these functions, indirectly through the respective <<log>>
43
function.
44
 
45
RETURNS
46
The <<log2>> functions return
47
@ifnottex
48
<<log base-2(<[x]>)>>
49
@end ifnottex
50
@tex
51
$log_2(x)$
52
@end tex
53
on success.
54
When <[x]> is zero, the
55
returned value is <<-HUGE_VAL>> and <<errno>> is set to <<ERANGE>>.
56
When <[x]> is negative, the returned value is NaN (not a number) and
57
<<errno>> is set to <<EDOM>>.  You can control the error behavior via
58
<<matherr>>.
59
 
60
PORTABILITY
61
C99, POSIX, System V Interface Definition (Issue 6).
62
*/
63
 
64
/*
65
 * wrapper log2(x)
66
 */
67
 
68
#include "fdlibm.h"
69
#include <errno.h>
70
#include <math.h>
71
#undef log2
72
 
73
#ifndef _DOUBLE_IS_32BITS
74
 
75
#ifdef __STDC__
76
        double log2(double x)           /* wrapper log2 */
77
#else
78
        double log2(x)                  /* wrapper log2 */
79
        double x;
80
#endif
81
{
82
  return (log(x) / M_LOG2_E);
83
}
84
 
85
#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.