a-new-floating-point-implementation-of-base-2-logarithm
a-new-floating-point-implementation-of-base-2-logarithm
Abstract — Logarithms reduce products to sums and powers CORDIC method and how it is used for calculating log2 ,
to products; they play an important role in signal processing, Section V presents our proposed method for calculating log2 ,
communication and information theory. They are primarily Section VI presents our proposed method in calculating log 2
used for hardware calculations, handling multiplications, divi- using Taylor series. We compare the algorithms in Section VII,
Open Science Index, Information and Communication Engineering Vol:8, No:10, 2014 publications.waset.org/9999600.pdf
sions, powers, and roots effectively. There are three commonly and finally Section VIII presents our conclusions and future work.
used bases for logarithms; the logarithm with base-10 is called
the common logarithm, the natural logarithm with base-e and II. L OOK -U P TABLE M ETHOD
the binary logarithm with base-2. This paper demonstrates dif-
ferent methods of calculation for log2 showing the complexity This algorithm depends on selecting a certain range of
of each and finds out the most accurate and efficient besides interest and storing a LUT in ROM. It is the traditional method
giving insights to their hardware design. We present a new for calculating the logarithm for any base but we must consider
method called Floor Shift for fast calculation of log2 , and memory resources needed for look-up tables and available
then we combine this algorithm with Taylor series to improve space. Implementation is direct forward since there are not
the accuracy of the output, we illustrate that by using two any decisions taken [1][2].
examples. We finally compare the algorithms and conclude
with our remarks. III. I TERATIVE METHOD
Keywords — Logarithms, log2 , floor, iterative, CORDIC, The input value X is first divided into mantissa m and
Taylor series. exponent e representation as:
data are divided into two main types; one is the look-up
table based algorithms and the other is Iterative methods. This
paper presents different algorithms that are used to calculate
log2 showing the accuracy and complexity in hardware design.
The remaining of this paper is organized as follows; Section
II covers calculating log 2 using a look-up table, Section III
shows an Iterative method for calculating log2 where accuracy
International Scholarly and Scientific Research & Innovation 8(10) 2014 1352 ISNI:0000000091950263
World Academy of Science, Engineering and Technology
International Journal of Information and Communication Engineering
Vol:8, No:10, 2014
Error analysis shows that our CORDIC design is more
accurate than the design presented in [4] for the same example
points that we mentioned in Table I showing our minimized
error.
TABLE I
E RROR A NALYSIS
0.8
Log2 calculated value at (N = 5)
Log2 calculated value at (N = 9)
Since the logarithmic value of X can be expressed in terms
0.7
of m and e as in (1), so our method tries to calculate log2 (X)
directly by getting the integer part then add the fraction part.
Log2( Input Value)
0.6
0.5
Our proposed method based on that presented in [5] which
creates a dependence between accuracy and number of itera-
0.4
tions, but here we calculate log2 (X) directly independent of
the number of iterations; getting the floor of log2 of the input
0.3
0.1
that presents the fraction part. This operation is described as
0
1 1.1 1.2 1.3 1.4 1.5
Input value
1.6 1.7 1.8 1.9 follows:
1) We calculate log2 (X) by searching for the leading one
Fig. 3. Exact value and calculated value of Log2 (m) (i.e., position of Xk ) to get the integer part of log2 (X).
2) We can get the approximated value for log2 (mantissa)
IV. CORDIC M ETHOD using (7), this operation is described in Fig. 5, noting
The CORDIC algorithm uses only adders and shifters. It that we must have the same length N for data after
provides a relatively high precision output, which is suit- shifting the decimal point [6].
able for hardware implementation. Calculating log2 using the
CORDIC algorithm depends on linear and inverse hyperbolic x − 2(log2 (x)
log2 (m) = (7)
tangent modes of CORDIC, then using (4) for conversion 2log2 (x)
between logarithm base-2 and natural logarithm [4][3].
m−1
ln(m) = 2 ∗ tanh−1 ( ) (3)
m+1
log2 (m) = loge (m) ∗ log2 (e) (4)
The design of CORDIC algorithm for calculating loge (X)
using CORDIC method is presented in Fig. 4.
" !
International Scholarly and Scientific Research & Innovation 8(10) 2014 1353 ISNI:0000000091950263
World Academy of Science, Engineering and Technology
International Journal of Information and Communication Engineering
Vol:8, No:10, 2014
4000
combine a simple LUT for certain values range and adding
0.04 as bias to center the error around zero for other values, 3500
this modification will minimize the error to half. The next 3000
Number of Repetition
2500
calculating mantissa with more accuracy depending on Taylor
series. 2000
Ex: log2 (0.1): integer part = log2 (0.1) = −4 and fraction part 1500
calculation using (7) = 0.6, so log2 (0.1) using this method = 1000
(equals) -3.4.
500
0
VI. TAYLOR S ERIES BASED I MPROVED M ETHOD −0.01 −0.008 −0.006 −0.004 −0.002 0
Error
0.002 0.004 0.006 0.008 0.01
This method used Taylor series expansion to calculate log2 Fig. 7. Difference between exact and calculated values for Taylor series
of the mantissa and then add its value to the floor of log2 algorithm with average Taylor terms with modification
Open Science Index, Information and Communication Engineering Vol:8, No:10, 2014 publications.waset.org/9999600.pdf
4000
3rd, 4th terms and taking the average of both will produce
approximated value for exact log2 (m), noting that the accuracy 3000
1.2 0
−2 −1.5 −1 −0.5 0 0.5 1
Exact log2 value −3
Error x 10
taylor 3rd terms
1 taylor 4th terms
taylor average 3rd & 4th terms
taylor 5th terms Fig. 8. Difference between exact and calculated values for Taylor series
0.8
algorithm with 4 terms Taylor series centered at x = 1.5
0.6
Log2(m)
International Scholarly and Scientific Research & Innovation 8(10) 2014 1354 ISNI:0000000091950263
World Academy of Science, Engineering and Technology
International Journal of Information and Communication Engineering
Vol:8, No:10, 2014
4
x 10
method. Table II presents the maximum value of SQNR that 3.5
LUT
we can obtain to get minimum error for each algorithm. 3
Taylor (4 Terms)
Cordic
Iterative (N = 9 )
2.5
LUT
Number of Occurrence
Taylor (4 terms)
−1
10 CORDIC 2
Iterative (N = 9)
Floor Shift
1.5
Error (log scale)
0.5
−2
10
0
−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1
Error −3
x 10
25 30 35 40 45 50 55 60 65 70
SQNR
R EFERENCES
1800
[1] H. Hassler and N. Takagi, Function evaluation by table look-up and
LUT addition, in Proc.12th Symp.on Computer Arithmetic, pp. 10-16, Jul.1995.
Taylor (4 Terms)
1600
Cordic [2] D. DasSarma, D.W. Matula, Measuring the Accumcy of ROM Reciprocal
Iterative ( N = 9 )
Floor Shift
Tables, IEEE 11th Symp.on Computer Arithmetic, pp.932-940, Aug.1994.
1400
[3] Pramod K. Meher, Javier Valls, Tso-Bing Juang, K. Sridharan and
1200 Koushik Maharatna, 50 Years of CORDIC: Algorithms, Architectures and
Number of Occurrence
International Scholarly and Scientific Research & Innovation 8(10) 2014 1355 ISNI:0000000091950263