This Application claims the right of priority based on Taiwan Patent Application No. 093106945 filed on Mar. 16, 2004.
The present invention relates to a logarithm determining method and the apparatus for the same.
When processing digital signals, sometimes, a number needs to be converted into a logarithm form first. There are several ways to convert a logarithm. For example, a floating-point format can be used to represent numbers, and a power series or Newton-Raphson method is used to round off the numbers; alternatively, a reference table can be used, or one can only calculate the integer part of the number and ignore the mantissa part.
However, the method using the floating-point format to represent numbers and then using the power series or Newton-Raphson method to round off the numbers is very complex, wasting both time and hardware resources. Additionally, it is very difficult and expensive for a hardware utilizing a fixed-point format to simulate a floating format by software. As for the reference tables, a logarithm table needs to be established first. It is needed to pre-save a great number of digits of precision, when an exact mantissa part is requested, and thus occupying a lot of memory space. Nevertheless, calculation to the integer part is not precise enough. Therefore, a simple logarithm determining method and the apparatus for the same, having enough precision, is needed.
An object of the present invention is to provide a simple logarithm determining method and an apparatus for the same with a desired precision. Depending on the number of digits of precision required on the mantissa part, the present invention creates a reference table having the same number of digits of precision as required. The m-th reference table can be used for calculating to the m-th decimal place of the mantissa part. Because the present invention utilizes the reference table, it is easier than representing the numbers in the floating format and then rounding off the numbers. The number of reference tables is dependent on the number of digits of precision required, and thus memory space is smaller than in the case of the conventional method using the reference tables. In addition, designating a number of digits of precision as desired is also more precise than calculating only to the integer part.
The present invention provides a logarithm determining method in a digital processor. The logarithm determining method converts an input number x into a logarithm L by a base b. The logarithm L includes an integer part In and a mantissa part Ma. The method represents numbers in a fixed-point format. The method comprises the following steps. The number of digits of precision for the mantissa part Ma, k, is designated. A plurality of reference tables is created based on the base b. The number of the plurality of reference tables is equal to k, the number of digits of precision for the mantissa part Ma. The m-th reference table is for evaluating the m-th digit to the right of the decimal point of the mantissa part Ma. The integer part In is calculated. The plurality of reference tables is searched sequentially to evaluate the 1st to the k-th digit to the right of the decimal point of the mantissa part Ma.
The above-mentioned calculating step can include the following steps: searching for a number y such that the base b to the y-th power is not greater than the input number x, and the base b to the (y+1)-th power is greater than the input number x; and outputting the number y as the integer number In.
Each reference table mentioned above can have 10 entries. The above-mentioned creating step can include the following steps: determining a coefficient SCm for the m-th of the plurality of reference tables; and rooting 10m the base b to the n-th power, and then multiplying it by the coefficient SCm to be the n-th entry of the m-th of the plurality of the reference tables, where n=0, . . . ,9; and the coefficient SCm is for extending intervals among the ten entries. The coefficient SCm is a power series of 2.
The above-mentioned searching step includes the following steps: setting m=1; if m=1, obtaining a temporary value Temp, by eliminating the integer part In in the input number x, and then multiplied by the coefficient SCm; or else, obtaining the temporary value Temp, by eliminating the portion from the first to the (m−1)-th digits to the right of the decimal points of the integer part In and of the mantissa part Ma in the input number, and then multiplied by the coefficient SCm; searching for the n-th entry Tabm[n] of the m-th of the plurality of said reference tables such that Tabm[n] is not greater than the temporary value Temp, and Tabm[n+1] is greater than said temporary value Temp; outputting n as the m-th digit to the right of the decimal points of the mantissa part Ma; adding m by 1; comparing m with the number of digits of precision k; and if m is not greater than the number of digits of precision k, repeat from calculating the temporary value Temp to comparing m and the number of digits of precision k.
The present invention also provides a logarithm determining apparatus for converting an input number x into a logarithm L by a base b. The logarithm L includes an integer part In and a mantissa part Ma. The apparatus can represent any numbers, using a fixed-point format. The apparatus includes a designating device, a creating device, a calculating device, and a searching device. The designating device is for designating k as a number of digits of precision for the mantissa part Ma. The creating device is for creating a plurality of reference tables based on the base b. The number of the plurality of reference tables equals the number of digits of precision k. An m-th reference table is for evaluating an m-th digit to the right of the decimal point of the mantissa part Ma. The calculating device is for calculating the integer part In. The searching device is for searching the plurality of reference tables sequentially to obtain a first to a k-th digit to the right of the decimal point of the mantissa part Ma.
The above-mentioned calculating device can include a first searching unit and a first output unit. The first searching unit is for searching for a number y such that the base b to the y-th power is not greater than the input number x, and the base b to the (y+1)-th power is greater than the input number x. The first output unit for outputting the number y as the integer number In.
Each of the above mentioned reference tables can have 10 entries. The above-mentioned creating device can include a determining unit and a first computing unit. The determining unit is for determining a coefficient SCm for the m-th of the plurality of reference tables. The first computing unit for rooting 10m the base b to the n-th power, and then multiplied by the coefficient SCm to be the n-th entry of the m-th of the plurality of the reference tables, where n=0, . . . ,9, wherein the coefficient SCm is for extending intervals among the ten entries.
The above mentioned searching device can include a setting unit, a second computing unit, a second searching unit, a second output unit, an adding unit, a comparing unit, and a logic unit. The setting unit is for setting m=1. If m=1, the second computing unit is operable to obtain a temporary value Temp, by eliminating the integer part In in the input number x, and then multiplied by the coefficient SCm; or else, obtaining the temporary value Temp, by eliminating the portion from the first to the (m−1)-th digits to the right of the decimal points of the integer part In and of the mantissa part Ma in the input number, and then multiplied by the coefficient SCm. The second searching unit is for searching for the n-th entry Tabm[n] of the m-th of the plurality of the reference tables such that Tabm[n] is not greater than the temporary value Temp, and Tabm[n+1] is greater than the temporary value Temp. The second output unit is for outputting n as the m-th digit to the right of the decimal points of the mantissa part Ma. The adding unit is for adding m by 1. The comparing unit is for comparing m with the number of digits of precision k. If m is not greater than the number of digits of precision k, the logic unit is for asking the second computing unit, the second searching unit, the second output unit, the adding unit and the comparing unit to repeat the steps accordingly.
The method includes the following steps. In step 101, k is designated to the number of digits of precision for the mantissa part Ma. A plurality of reference tables is created based on the base b. The number of the plurality of reference tables is equal to k, the number of digits of precision for the mantissa part Ma. The m-th reference table is for evaluating the m-th digit to the right of the decimal point of the mantissa part Ma. Each reference table can have 10 entries. The above-mentioned creating step can include the following steps. In step 103, a coefficient SCm for the m-th of the plurality of reference tables is determined. The coefficient for each reference table may be different. The coefficient SCm is for extending the intervals among the 10 entries. If the interval is sufficient, SCm−1. The coefficient SCm is a power series of 2 so as to facilitate the computation in binary representation. Then, in step 105, the base b to the n-th power is rooted 10m, and then multiplied by the coefficient SCm so as to be the n-th entry of the m-th of the plurality of the reference tables, where n=0, . . . ,9.
Furthermore, the integer part In is calculated. The calculating step can include the following. In step 107, a number y is searched for such that the base b to the y-th power is not greater than the input number x, and the base b to the (y+1)-th power is greater than the input number x. In step 109, the number y is output as the integer number In.
The plurality of reference tables is searched sequentially to evaluate the 1st to the k-th digit to the right of the decimal point of the mantissa part Ma. The searching step can include the following. In step 111, m=1 is set. In step 113, if m=1, a temporary value Temp is obtained by eliminating the integer part In in the input number x, and then multiplying it by the coefficient SCm; or else, the temporary value Temp is obtained by eliminating the portion from the first to the (m−1)-th digits to the right of the decimal points of the integer part In and of the mantissa part Ma in the input number, and then multiplying it by the coefficient SCm. In step 115, the n-th entry Tabm[n] of the m-th of said plurality of the reference tables is searched such that Tabm[n] is not greater than the temporary value Temp, and Tabm[n+1] is greater than the temporary value Temp. In step 117, n is output as the m-th digit to the right of the decimal points of the mantissa part Ma. In step 119, m is added by 1. In step 121, m is compared with the number of digits of precision k. If m is not greater than the number of digits of precision k, repeat from the step of calculating the temporary value Temp to the step of comparing m and the number of digits of precision k (steps 113-121). In step 123, if m is greater than k, then the number of digits to the right of the decimal point of the mantissa part Ma is output. There are many ways to implement the above mentioned searching Tabm[n] step, namely step 115; for example, size can be compared from the zeroith entry, or from the fourth or the fifth entry.
Although the creating step (steps 103-105) is prior to the calculating step (steps 107-109), the calculating step (step 107-109) can also be implemented prior to the creating step (steps 103-105). Alternatively, the 2 steps can be processed simultaneously.
The designating device 202 is for designating k as a number of digits of precision for the mantissa part Ma. The creating device 204 is for creating a plurality of reference tables based on the base b. The number of the plurality of reference tables equals the number of digits of precision k. An m-th reference table is for evaluating an m-th digit to the right of the decimal point of the mantissa part Ma. Each of the reference tables mentioned above can have 10 entries. The creating device 204 includes a determining unit 206 and a first computing unit 208. The determining unit 206 is for determining a coefficient SCm for the m-th of the plurality of reference tables. The coefficient for each reference table can be different. The coefficient SCm is for extending the intervals among the 10 entries. If the interval is sufficient, SCm can be equal to 1. The coefficient SCm can be a power series of 2 so as to facilitate the computation in a binary representation. The first computing unit 208 is for rooting 10m the base b to the n-th power, and then multiplying it by the coefficient SCm to be the n-th entry of the m-th of the plurality of the reference tables, where n=0, . . . ,9.
The calculating device 210 is for calculating the integer part In. The calculating device 210 can include a searching unit 212 and a first output unit 214. The first searching unit 212 is for searching for a number y such that the base b to the y-th power is not greater than the input number x, and the base b to the (y+1)-th power is greater than the input number x. The first output unit 214 is for outputting the number y as the integer number In.
The searching device 216 is for searching in the plurality of reference tables sequentially to obtain a first to a k-th digit to the right of the decimal point of the mantissa part Ma. The searching device 216 can include a setting unit 218, a second computing unit 220, a second searching unit 222, a second output unit 224, an adding unit 226, a comparing unit 228, and a logic unit 230. The setting unit 218 is for setting m=1. If m=1, the second computing unit 220 is operable to obtain a temporary value Temp by eliminating the integer part In in the input number x, and then multiplying it by the coefficient SCm; or else, obtaining the temporary value Temp, by eliminating the portion from the first to the (m−1)-th digits to the right of the decimal points of the integer part In and the mantissa part Ma in the input number, and then multiplying it by the coefficient SCm. The second searching unit 222 is for searching for the n-th entry Tabm[n] of the m-th of the plurality of the reference tables such that Tabm[n] is not greater than the temporary value Temp, and Tabm[n+1] is greater than the temporary value Temp. The second output unit 224 is for outputting n as the m-th digit to the right of the decimal points of the mantissa part Ma. The adding unit 226 is for adding 1 to m. The comparing unit 228 is for comparing m with the number of digits of precision k. If m is not greater than the number of digits of precision k, the logic unit 230 is for asking the second computing unit 220, the second searching unit 222, the second output unit 224, the adding unit 226 and the comparing unit 228 to repeat the steps accordingly. There are many ways to implement the above mentioned searching Tabm[n] step, namely step 115; for example, size can be compared from the zeroith entry, or from the fourth or the fifth entry.
The following is an exemplary logarithm determining method and apparatus in accordance with the present invention. Assume an input number is equal to 135, and a base b is equal to 10. First, the number of digits of precision for the mantissa part Ma, k, is designated as 3. Then, creating a reference table and calculating an integer part In can be processed simultaneously. Alternatively, a reference table can be created prior to when an integer part In is calculated, and vice versa. Assume that the reference table is created first. Refer to
Then, the integer part In is calculated. A number y=2 can first be found such that the base b (=10) to the y-th power is not greater than the input number x (=135), and that the base b to the (y+1) power is greater than the input number x, namely 102≦135<10(2+1), then the integer part In is equal to 2.
The reference tables are then searched to obtain the mantissa part Ma.
Finally, the integer part In is equal to 2, the mantissa part is equal to 0.130, and the logarithm L is equal to 2.130, namely log10x=log10135˜2.130.
By means of the detailed descriptions of what is presently considered to be the most practical and preferred embodiments of the subject invention, it is expected that the features and the gist thereof be clearly described. Nevertheless, these embodiments are not intended to be construed in a limiting sense. Instead, it will be well understood that any analogous variations and equivalent arrangements will fall within the spirit and scope of the invention.
Number | Date | Country | Kind |
---|---|---|---|
93106945 | Mar 2004 | TW | national |