source: trunk/libs/newlib/src/newlib/libm/common/s_log2.c @ 471

Last change on this file since 471 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 2.1 KB
Line 
1/* @(#)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/*
16FUNCTION
17        <<log2>>, <<log2f>>---base 2 logarithm
18INDEX
19        log2
20INDEX
21        log2f
22
23SYNOPSIS
24        #include <math.h>
25        double log2(double <[x]>);
26        float log2f(float <[x]>);
27
28DESCRIPTION
29The <<log2>> functions compute the base-2 logarithm of <[x]>.  A domain error
30occurs if the argument is less than zero.  A range error occurs if the
31argument is zero.
32
33The Newlib implementations are not full, intrinisic calculations, but
34rather are derivatives based on <<log>>.  (Accuracy might be slightly off from
35a direct calculation.)  In addition to functions, they are also implemented as
36macros defined in math.h:
37. #define log2(x) (log (x) / _M_LN2)
38. #define log2f(x) (logf (x) / (float) _M_LN2)
39To use the functions instead, just undefine the macros first.
40
41You can use the (non-ANSI) function <<matherr>> to specify error
42handling for these functions, indirectly through the respective <<log>>
43function.
44
45RETURNS
46The <<log2>> functions return
47@ifnottex
48<<log base-2(<[x]>)>>
49@end ifnottex
50@tex
51$log_2(x)$
52@end tex
53on success.
54When <[x]> is zero, the
55returned value is <<-HUGE_VAL>> and <<errno>> is set to <<ERANGE>>.
56When <[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
60PORTABILITY
61C99, 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_LN2);
83}
84
85#endif /* defined(_DOUBLE_IS_32BITS) */
Note: See TracBrowser for help on using the repository browser.