High-precision logarithmic function implementation method based on segmentation strategy

By employing a segmentation strategy and path selection, a high-precision logarithmic function method is developed, which solves the problem of balancing computational accuracy and efficiency in traditional methods, and achieves high-precision and low-complexity logarithmic function computation.

CN121723013APending Publication Date: 2026-03-24HUNAN XINHONGDAO INFORMATION TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-23
Publication Date
2026-03-24

AI Technical Summary

Technical Problem

Existing methods for calculating logarithmic functions struggle to balance computational accuracy and efficiency. Traditional methods suffer from high computational complexity, large storage requirements, and insufficient computational accuracy.

Method used

A high-precision logarithmic function implementation method based on a piecewise strategy is adopted. By standardizing the input floating-point number, a threshold signal is generated for path selection. Polynomial approximation and third-order Taylor expansion are used for calculation in different intervals. The format of polynomial coefficients and Taylor expansion component data is unified and shifted to ensure that the result conforms to the IEEE 754 floating-point number format.

Benefits of technology

It achieves high-precision calculations in different input ranges, reduces computational complexity, improves local approximation accuracy and overall computational stability, balances computational accuracy and efficiency, and avoids quantization errors and overflow distortion.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121723013A_ABST
    Figure CN121723013A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of numerical calculation and hardware algorithm implementation, in particular to a segmentation strategy-based high-precision logarithmic function implementation method, which comprises the following steps of: carrying out standardization processing on an input floating-point number, generating a threshold signal for path selection based on a relationship between an index and a mantissa of the floating-point number, and then, carrying out segmentation on the threshold signal; performing sub-interval division on the standardized data, determining corresponding sub-interval numbers, selecting a sub-interval starting point as a polynomial approximation reference point, generating parameter data for polynomial calculation and third-order Taylor expansion calculation, performing numerical format unification and shift alignment processing on the parameter data, and then obtaining a polynomial approximation reference point; the method comprises the following steps: respectively performing polynomial calculation and Taylor expansion calculation to obtain a polynomial fixed-point result and a Taylor expansion temporary result, performing normalization and rounding processing on calculation results to ensure that output meets floating point format requirements, and finally realizing path selection according to a threshold signal and outputting a final logarithmic function result. Therefore, the calculation precision and the operation efficiency are effectively considered.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of numerical computation and hardware algorithm implementation technology, specifically to a method for implementing a high-precision logarithmic function based on a piecewise strategy. Background Technology

[0002] While the traditional Taylor series expansion method can theoretically achieve high computational accuracy, its computational process relies on solving multiple high-order terms, resulting in high computational complexity and making it difficult to meet real-time requirements.

[0003] Traditional table lookup methods achieve fast lookups by pre-calculating and storing logarithmic function values. While this improves computational speed to some extent, it has significant structural limitations: when high precision is required, a large amount of storage space is needed, while reducing the table size significantly reduces computational precision. To strike a balance between the two, interpolation is usually introduced, but this adds additional computational overhead and still fails to meet high precision requirements in certain critical numerical ranges (such as the region close to 1).

[0004] Furthermore, the unified polynomial approximation method uses polynomials of the same order to approximate the entire domain. Although the implementation structure is relatively simple and the computational efficiency is high, it lacks the ability to adaptively adjust to the characteristics of the logarithmic function curve. For example, in the sensitive region of the logarithmic function (especially the interval close to 1), if a low-order polynomial of the same order is still used, the calculation error will increase significantly, making it difficult to guarantee the overall calculation accuracy.

[0005] In summary, existing methods for calculating logarithmic functions generally suffer from the technical problem of balancing computational accuracy and efficiency.

[0006] To address the aforementioned shortcomings, a technical solution is provided. Summary of the Invention

[0007] To address the aforementioned shortcomings of existing technologies, this invention provides a high-precision logarithmic function implementation method based on a piecewise strategy, which can effectively solve the problem of balancing computational accuracy and efficiency in existing technologies.

[0008] To achieve the above objectives, the present invention can be implemented through the following technical solutions:

[0009] This invention provides a method for implementing a high-precision logarithmic function based on a piecewise strategy, comprising the following steps:

[0010] The input floating-point number is standardized to map it to the interval [1, 2), and a threshold signal for path selection is generated based on the relationship between the exponent and mantissa of the input floating-point number.

[0011] The data mapped to the interval [1, 2) is divided into sub-intervals, the corresponding sub-interval numbers are determined, and the starting point of the sub-interval is selected as the reference point for polynomial approximation. At the same time, parameter data for polynomial calculation and third-order Taylor expansion calculation are generated.

[0012] Numerical format unification and shift alignment are performed on the polynomial coefficients and third-order Taylor expansion components to ensure that the data involved in the calculation are processed with the same bit width and precision.

[0013] Polynomial operations are performed using polynomial coefficients and reference points to obtain the fixed-point result of the polynomial. At the same time, addition and subtraction operations are performed on the component data of the third-order Taylor expansion to obtain the temporary result of the Taylor expansion.

[0014] Normalize and round the fixed-point results of the polynomial and the temporary results of the Taylor expansion to make the calculation results conform to the floating-point format requirements;

[0015] Path selection is performed based on the value of the threshold signal to obtain the final logarithmic function result.

[0016] Furthermore, the specific process of standardizing the input floating-point number is as follows:

[0017] The input floating-point number is preprocessed in accordance with the IEEE 754 standard. The input floating-point number consists of three parts: sign bit, exponent bit, and mantissa bit. By parsing and separating these three parts, the sign information, exponent value, and mantissa value of the input data are obtained respectively.

[0018] Based on the relationship between the exponent and mantissa of floating-point numbers, logarithmic decomposition is performed using the following transformation formula: ;

[0019] Where In is the input floating-point number, E is the exponent part of the input floating-point number minus the offset, and M is the normalized mantissa obtained by combining the mantissa part with the hidden bit 1, and its value range is limited to the interval [1, 2).

[0020] Furthermore, the specific process for generating the threshold signal for path selection is as follows:

[0021] Perform a linearization transformation on M, let: ;

[0022] The logarithmic function is then converted to: This transformation converts the logarithmic function into the natural logarithmic form with X as the variable;

[0023] Based on the distance relationship between the input data and the floating-point number 1, a threshold determination mechanism is established. By comparing the magnitude relationship between the exponent and offset code of the input data, and combining the feature information of whether the high-order bits of the mantissa are zero, it is determined whether the input data is in the high-precision sensitive range close to 1. If the determination result shows that the input data is in this range, a threshold signal is output. This indicates that a third-order Taylor expansion path is subsequently used; otherwise, a threshold signal is output. This indicates that a second-order polynomial is used to approximate the path.

[0024] Furthermore, the specific process for generating parameter data for polynomial calculations and third-order Taylor expansion calculations is as follows:

[0025] Based on the sub-interval number, extract the corresponding polynomial coefficients (A0, A1, A2) from the preset polynomial coefficient lookup table as parameter data for polynomial calculation.

[0026] Based on the third-order Taylor expansion of the logarithmic function ln(1+X) near 0: , for variables Performing term-by-term multiplication, we obtain the third-order Taylor expansion of the terms: , which serves as parameter data for calculating the third-order Taylor expansion.

[0027] Furthermore, the specific process of unifying the numerical format and performing shift alignment on the polynomial coefficients and the partial data of the third-order Taylor expansion is as follows:

[0028] Based on the preset numerical bit width and calculation precision requirements, the decimal part of the parameter data is shifted and aligned. At the same time, all data involved in the calculation are fixed-point converted and truncation controlled. Combined with bit width compensation and rounding mechanisms, cumulative errors caused by floating-point and fixed-point format conversion are avoided.

[0029] Furthermore, the fixed-point result R1 of the polynomial is expressed as:

[0030] , where xi is the starting value of the corresponding sub-interval.

[0031] Furthermore, the temporary result R² of the Taylor expansion is expressed as:

[0032] .

[0033] Furthermore, the specific process of normalizing and rounding the fixed-point result of the polynomial and the temporary result of the Taylor expansion is as follows:

[0034] Normalization transformation is performed on the fixed-point result R1 of the polynomial and the temporary result R2 of the Taylor expansion. The result is made to conform to the IEEE 754 floating-point number format specification by left or right shifting the mantissa, and rounding is performed to eliminate bit width truncation error.

[0035] During the normalization process, overflow detection and underflow correction are also performed. If the result exceeds the numerical representation range, the exponent is automatically adjusted to maintain the numerical validity of the output result.

[0036] Furthermore, the specific process of path selection based on the threshold signal value is as follows:

[0037] When the threshold signal In this case, the polynomial floating-point result is chosen as the final logarithmic function result;

[0038] When the threshold signal In this case, the Taylor expansion floating-point result is chosen as the final logarithmic function result.

[0039] The technical solution provided by this invention has the following advantages compared with the known prior art:

[0040] 1. After standardizing the input floating-point number, this invention maps it to the interval [1, 2) and performs sub-interval partitioning within this interval. The logarithmic function curve in each sub-interval has a relatively gentle change characteristic, so a low-order polynomial can be used for high-precision approximation, thereby effectively reducing the polynomial order required for global approximation. This piecewise strategy not only reduces computational complexity, but also avoids the large error generated in the steep region of the curve in the traditional unified polynomial approximation, so that the approximation error is uniformly controlled in each sub-interval, thereby significantly improving the local approximation accuracy and overall computational stability.

[0041] 2. This invention analyzes the exponent difference and mantissa high-order characteristics of the input floating-point number to generate a threshold signal for path selection, thereby achieving adaptive switching of the calculation path. When the input data is in the high-precision sensitive range close to 1, a third-order Taylor expansion path with ln(1+X) as the core is activated, which can converge quickly within a small input range and obtain high-precision calculation results. When the input data is far from the sensitive range, a preset low-order polynomial approximation path is adopted to achieve fast calculation and low hardware resource consumption. This adaptive path selection method breaks through the limitation of the traditional method of "using a fixed approximation model throughout the domain", enabling the system to dynamically adjust the calculation strategy according to the input characteristics, thereby achieving a balance between calculation accuracy and computational efficiency without significantly increasing the computational complexity.

[0042] 3. Before the polynomial and Taylor expansion calculation stages, this invention performs fixed-point normalization, bit width compensation, and shift alignment on the parameter data involved in the calculation to ensure that all data are calculated with the same precision. After the calculation is completed, the final result conforms to the IEEE 754 floating-point format requirements through mantissa normalization, rounding control, and overflow / underflow correction mechanisms, effectively preventing quantization errors and overflow distortion caused by conversion between different numerical formats. Attached Figure Description

[0043] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0044] Figure 1 This is a flowchart illustrating the overall process of the present invention. Detailed Implementation

[0045] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative effort are within the scope of protection of the present invention.

[0046] like Figure 1 As shown, a method for implementing a high-precision logarithmic function based on a piecewise strategy includes the following steps:

[0047] Step 1: Standardize the input floating-point number to map it to the interval [1, 2), and generate a threshold signal for path selection, providing a data foundation for subsequent polynomial approximation and third-order Taylor expansion calculations. The specific implementation process is as follows:

[0048] The input floating-point number is preprocessed in accordance with the IEEE 754 standard. The input floating-point number consists of three parts: sign bit, exponent bit, and mantissa bit. By parsing and separating these three parts, the sign information, exponent value, and mantissa value of the input data are obtained respectively, which prepares for subsequent numerical transformation and calculation.

[0049] Based on the relationship between the exponent and mantissa of floating-point numbers, logarithmic decomposition is performed using the following transformation formula: ;

[0050] Where In is the input floating-point number, E is the exponent part of the input floating-point number minus the offset (i.e. the integer part of the result), and M is the normalized mantissa obtained by combining the mantissa part with the hidden bit "1", and its value range is limited to the interval [1, 2). Through this decomposition formula, the calculation of the logarithmic function can be decomposed into two parts: exponential addition and mantissa logarithm, thereby realizing the parallel processing of the calculation path and improving the overall computational efficiency.

[0051] Building upon this, and addressing the issue of precision loss when using second-order polynomial form to calculate M as its value approaches 1, this step further linearizes M, letting: ;

[0052] The logarithmic function is then converted to: ;

[0053] This transformation can convert the logarithmic function into the natural logarithm form with X as the variable, so that the third-order Taylor expansion expression of ln(1+X) can be directly used for high-precision approximation calculation, which significantly improves the calculation accuracy of M in the region close to 1;

[0054] Based on the distance relationship between the input data and the floating-point number "1", a threshold determination mechanism is established. By comparing the magnitude relationship between the exponent and offset code of the input data, and combining feature information such as whether the high-order bit of the mantissa is zero, it is determined whether the input data is in a high-precision sensitive range close to 1. If the determination result shows that the input data is in this range, a threshold signal is output. This indicates that a third-order Taylor expansion path is subsequently used; otherwise, a threshold signal is output. This indicates that a second-order polynomial is used to approximate the path;

[0055] Through the above process, this step realizes the standardization and interval mapping of the input floating-point number, completes the separation of sign, exponent and mantissa, obtains the standardized mantissa M mapped to the interval [1, 2), and generates a threshold signal for multipath switching, laying a unified and accurate data foundation for subsequent piecewise polynomial calculation and third-order Taylor expansion.

[0056] Step 2: Divide the data mapped to the interval [1, 2) into sub-intervals, determine the corresponding sub-interval numbers, and select the starting point of the sub-interval as the reference point for polynomial approximation. At the same time, generate parameter data for polynomial calculation and third-order Taylor expansion calculation. The specific implementation process is as follows:

[0057] Perform sub-interval decoding on the data mapped to the interval [1, 2) to obtain the corresponding sub-interval. By taking the starting point of the sub-interval as the reference point for polynomial approximation and using the reference point as the expansion basis, the constant terms that are repeatedly calculated in the operation can be significantly reduced, thereby reducing the amount of arithmetic operations and optimizing the timing performance.

[0058] After determining the reference point, the corresponding polynomial coefficients (A0, A1, A2) are extracted from the pre-set Coefficient Lookup Table according to the sub-interval number i, and used as parameter data for polynomial calculation. The Coefficient Lookup Table can be generated offline by pre-fitting the curve features of the logarithmic function in different intervals and stored in fixed-point or floating-point form so as to be quickly indexed and calculated in the hardware implementation.

[0059] Meanwhile, to achieve high-precision approximation calculations, this step is based on the third-order Taylor expansion of the logarithmic function ln(1+X) near 0: , for variables Performing term-by-term multiplication, we obtain the third-order Taylor expansion of the terms: , as parameter data used for third-order Taylor expansion calculation;

[0060] Through the above process, this step completes the subdivision of the interval [1, 2), the determination of the reference point, the extraction of polynomial coefficients, and the generation of the third-order Taylor expansion sub-items. This process not only realizes multi-level precision control of the input data, but also provides a structured data input foundation for subsequent parallel computing.

[0061] Step 3: Standardize the format and perform shifting and alignment of the polynomial coefficients and third-order Taylor expansion components. The specific implementation process is as follows:

[0062] Based on the preset numerical bit width and computational precision requirements, the polynomial coefficients (A0, A1, A2) and the third-order Taylor expansion of the component data are... The decimal part is shifted and aligned to ensure that it participates in calculations under the same fixed decimal place format, thus ensuring that multiplication and addition operations are performed with the same numerical precision.

[0063] Secondly, all data involved in the calculation are subjected to fixed-point conversion and truncation control, and combined with bit width compensation and rounding mechanism to avoid cumulative errors caused by the conversion between floating-point and fixed-point formats. In addition, a data validity flag is generated during this process to indicate whether the current numerical format meets the requirements of subsequent pipeline calculations.

[0064] Through the above process, this step unifies the polynomial coefficients and third-order Taylor expansion components in terms of accuracy, ensuring that different calculation paths (polynomial approximation path and Taylor expansion path) have the same benchmark format in subsequent fusion calculations, thus ensuring the numerical stability of the results and the consistency of hardware implementation.

[0065] Step 4: Perform polynomial operations using the polynomial coefficients and reference points to obtain the fixed-point result of the polynomial. Simultaneously, perform addition and subtraction operations on the terms of the third-order Taylor expansion to obtain a temporary result of the Taylor expansion. The specific implementation process is as follows:

[0066] For the second-order polynomial path, based on the polynomial coefficients (A0, A1, A2) extracted in step two and the reference point xi, calculate the fixed-point result R1 of the polynomial of the current input data within this interval. The calculation formula is as follows: , where xi is the starting point value of the corresponding sub-interval. This operation is implemented by a multi-level multiply-accumulate unit (MAC), which can be completed in parallel over multiple clock cycles through a pipelined structure to reduce overall latency;

[0067] For the third-order Taylor expansion path, based on the aligned data from step three, perform addition and subtraction operations sequentially to obtain the temporary Taylor expansion result R2: In the hardware implementation, this path also adopts a pipelined parallel architecture, and the three computations can be executed in an overlapping manner, thereby effectively improving the throughput.

[0068] This scheme, through its dual-path synchronous computation structure design, allows the system to simultaneously obtain polynomial approximation results and third-order Taylor expansion results, providing parallel output for subsequent normalization and result selection, and significantly improving computational latency and resource utilization.

[0069] Step 5: Normalize and round the fixed-point result of the polynomial and the temporary result of the Taylor expansion to ensure that the output meets the floating-point format requirements. The specific implementation process is as follows:

[0070] Normalization transformation is performed on the fixed-point result R1 of the polynomial and the temporary result R2 of the Taylor expansion. The result is made to conform to the IEEE 754 floating-point number format specification by left or right shifting the mantissa, and rounding is performed to eliminate bit width truncation error.

[0071] During the normalization process, overflow detection and underflow correction are also performed. If the result exceeds the numerical representation range, the exponent is automatically adjusted to maintain the numerical validity of the output result.

[0072] Through the above process, this step ensures the consistency of accuracy and format compatibility of the calculation results of the polynomial path and the Taylor path, providing a reliable data foundation for the adaptive selection of the final result.

[0073] Step Six: Select the polynomial floating-point result and the Taylor expansion floating-point result based on the threshold signal to obtain the final logarithmic function result. The specific implementation process is as follows:

[0074] When the threshold signal In this case, the polynomial floating-point result is chosen as the final logarithmic function result;

[0075] When the threshold signal In this case, the Taylor expansion floating-point result is chosen as the final logarithmic function result.

[0076] The preferred embodiments of the present invention disclosed above are merely illustrative of the invention. These preferred embodiments do not exhaustively describe all details, nor do they limit the invention to any specific implementation. Clearly, many modifications and variations can be made based on the content of this specification. This specification selects and specifically describes these embodiments to better explain the principles and practical applications of the invention, thereby enabling those skilled in the art to better understand and utilize the invention. The invention is limited only by the claims and their full scope and equivalents.

Claims

1. A method for implementing a high-precision logarithmic function based on a piecewise strategy, characterized in that, Includes the following steps: The input floating-point number is standardized to map it to the interval [1, 2), and a threshold signal for path selection is generated based on the relationship between the exponent and mantissa of the input floating-point number. The data mapped to the interval [1, 2) is divided into sub-intervals, the corresponding sub-interval numbers are determined, and the starting point of the sub-interval is selected as the reference point for polynomial approximation. At the same time, parameter data for polynomial calculation and third-order Taylor expansion calculation are generated. Numerical format unification and shift alignment are performed on the polynomial coefficients and third-order Taylor expansion components to ensure that the data involved in the calculation are processed with the same bit width and precision. Polynomial operations are performed using polynomial coefficients and reference points to obtain the fixed-point result of the polynomial. At the same time, addition and subtraction operations are performed on the component data of the third-order Taylor expansion to obtain the temporary result of the Taylor expansion. Normalize and round the fixed-point results of the polynomial and the temporary results of the Taylor expansion to make the calculation results conform to the floating-point format requirements; Path selection is performed based on the value of the threshold signal to obtain the final logarithmic function result.

2. The method for implementing a high-precision logarithmic function based on a piecewise strategy according to claim 1, characterized in that, The specific process of standardizing the input floating-point number is as follows: The input floating-point number is preprocessed in accordance with the IEEE 754 standard. The input floating-point number consists of three parts: sign bit, exponent bit, and mantissa bit. By parsing and separating these three parts, the sign information, exponent value, and mantissa value of the input data are obtained respectively. Based on the relationship between the exponent and mantissa of floating-point numbers, logarithmic decomposition is performed using the following transformation formula: ; Where In is the input floating-point number, E is the exponent part of the input floating-point number minus the offset, and M is the normalized mantissa obtained by combining the mantissa part with the hidden bit 1, and its value range is limited to the interval [1, 2).

3. The method for implementing a high-precision logarithmic function based on a piecewise strategy according to claim 1, characterized in that, The specific process for generating the threshold signal for path selection is as follows: Perform a linearization transformation on M, let: ; The logarithmic function is then converted to: This transformation converts the logarithmic function into the natural logarithmic form with X as the variable; Based on the distance relationship between the input data and the floating-point number 1, a threshold determination mechanism is established. By comparing the magnitude relationship between the exponent and offset code of the input data, and combining the feature information of whether the high-order bits of the mantissa are zero, it is determined whether the input data is in the high-precision sensitive range close to 1. If the determination result shows that the input data is in this range, a threshold signal is output. This indicates that a third-order Taylor expansion path is subsequently used; otherwise, a threshold signal is output. This indicates that a second-order polynomial is used to approximate the path.

4. The method for implementing a high-precision logarithmic function based on a piecewise strategy according to claim 1, characterized in that, The specific process for generating parameter data for polynomial calculations and third-order Taylor expansion calculations is as follows: Based on the sub-interval number, extract the corresponding polynomial coefficients (A0, A1, A2) from the preset polynomial coefficient lookup table as parameter data for polynomial calculation. Based on the third-order Taylor expansion of the logarithmic function ln(1+X) near 0: , for variables Performing term-by-term multiplication, we obtain the third-order Taylor expansion of the terms: , which serves as parameter data for calculating the third-order Taylor expansion.

5. The method for implementing a high-precision logarithmic function based on a piecewise strategy according to claim 1, characterized in that, The specific process of unifying the numerical format and performing shift alignment on the polynomial coefficients and third-order Taylor expansion components is as follows: Based on the preset numerical bit width and calculation precision requirements, the decimal part of the parameter data is shifted and aligned. At the same time, all data involved in the calculation are fixed-point converted and truncation controlled. Combined with bit width compensation and rounding mechanisms, cumulative errors caused by floating-point and fixed-point format conversion are avoided.

6. The method for implementing a high-precision logarithmic function based on a piecewise strategy according to claim 1, characterized in that, The fixed-point result R1 of the polynomial is expressed as: , where xi is the starting value of the corresponding sub-interval.

7. The method for implementing a high-precision logarithmic function based on a piecewise strategy according to claim 1, characterized in that, The temporary result R2 expression of the Taylor expansion is: 。 8. The method for implementing a high-precision logarithmic function based on a piecewise strategy according to claim 1, characterized in that, The specific process of normalizing and rounding the fixed-point result and the temporary result of the Taylor expansion of the polynomial is as follows: Normalization transformation is performed on the fixed-point result R1 of the polynomial and the temporary result R2 of the Taylor expansion. The result is made to conform to the IEEE 754 floating-point number format specification by left or right shifting the mantissa, and rounding is performed to eliminate bit width truncation error. During the normalization process, overflow detection and underflow correction are also performed. If the result exceeds the numerical representation range, the exponent is automatically adjusted to maintain the numerical validity of the output result.

9. The method for implementing a high-precision logarithmic function based on a piecewise strategy according to claim 1, characterized in that, The specific process of path selection based on the threshold signal value is as follows: When the threshold signal In this case, the polynomial floating-point result is chosen as the final logarithmic function result; When the threshold signal In this case, the Taylor expansion floating-point result is chosen as the final logarithmic function result.