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 /*
16 FUNCTION
17 	<<log2>>, <<log2f>>---base 2 logarithm
18 INDEX
19 	log2
20 INDEX
21 	log2f
22 
23 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_LN2)
38 . #define log2f(x) (logf (x) / (float) _M_LN2)
39 To use the functions instead, just undefine the macros first.
40 
41 RETURNS
42 The <<log2>> functions return
43 @ifnottex
44 <<log base-2(<[x]>)>>
45 @end ifnottex
46 @tex
47 $log_2(x)$
48 @end tex
49 on success.
50 When <[x]> is zero, the
51 returned value is <<-HUGE_VAL>> and <<errno>> is set to <<ERANGE>>.
52 When <[x]> is negative, the returned value is NaN (not a number) and
53 <<errno>> is set to <<EDOM>>.
54 
55 PORTABILITY
56 C99, POSIX, System V Interface Definition (Issue 6).
57 */
58 
59 /*
60  * wrapper log2(x)
61  */
62 
63 #include "fdlibm.h"
64 #if __OBSOLETE_MATH_DOUBLE
65 #include <errno.h>
66 #include <math.h>
67 #undef log2
68 
69 #ifdef _NEED_FLOAT64
70 
71 __float64
log264(__float64 x)72 log264(__float64 x)		/* wrapper log2 */
73 {
74     return (log64(x) / _F_64(_M_LN2));
75 }
76 
77 _MATH_ALIAS_d_d(log2)
78 
79 #endif /* _NEED_FLOAT64 */
80 #else
81 #include "log2.c"
82 #endif /* __OBSOLETE_MATH_DOUBLE */
83