CN115659110A - Trigonometric function calculation method, device, equipment and storage medium - Google Patents
Trigonometric function calculation method, device, equipment and storage medium Download PDFInfo
- Publication number
- CN115659110A CN115659110A CN202211329702.5A CN202211329702A CN115659110A CN 115659110 A CN115659110 A CN 115659110A CN 202211329702 A CN202211329702 A CN 202211329702A CN 115659110 A CN115659110 A CN 115659110A
- Authority
- CN
- China
- Prior art keywords
- function
- lookup table
- trigonometric
- trigonometric function
- period
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Landscapes
- Image Processing (AREA)
Abstract
The application relates to the technical field of graphic processing units, and discloses a trigonometric function calculation method, a device, equipment and a storage medium, wherein the trigonometric function calculation method comprises the steps of converting a function to be discretized into a discrete function lookup table based on a preset lookup table; reconstructing the discrete function lookup table into a target function based on a nonlinear interpolation method of a trigonometric sum-difference formula; the function calculation is simplified by decomposing the function lookup table into an odd lookup table and an even lookup table, and mapping the objective function within the [ - π, π ] period into [0, π/2] periods based on the periodicity of the objective function. According to the method, the period of the trigonometric function is reduced to [0, pi/2 ] through continuous and discrete mutual transformation of the trigonometric function, the function lookup table is decomposed, so that two adjacent trigonometric function values can be obtained in one period, the trigonometric function synchronously uses circuit design, the throughput rate of a logic circuit is improved, and the calculation precision of the trigonometric function is improved.
Description
Technical Field
The present application relates to the field of graphics processing unit technologies, and in particular, to a method, an apparatus, a device, and a storage medium for trigonometric function calculation.
Background
The SIN, COS function is typically implemented by a Floating Point processor FPU (Floating Point Unit) in a general purpose processor design using a polynomial expansion method. However, since FPUs are lacking in most FPGAs (Field Programmable Gate arrays), ASICs (Application Specific Integrated circuits) and MCUs (Micro Controller units), approximate calculation methods are usually used to calculate SIN and COS functions. The general approximate calculation method includes a CORDIC (Coordinate Rotation Digital Computer) algorithm or a look-up table approximate method, but the CORDIC method and the look-up table approximate method have upper limit of calculation precision, and cannot meet the use requirement in some fields with higher requirement on error precision of numerical calculation.
The common calculation method of the COS function used in the CPU is an expansion approximation based on a polynomial, and requires an FPU to be called to process floating point number calculation. In embedded systems and common FPGA/ASIC hardware systems, implementation methods based on CORDIC algorithms or table lookup based methods are commonly used. The general CORDIC algorithm-based method or the lookup table-based method has low calculation accuracy, and is difficult to meet the requirements under the scene with high numerical calculation accuracy requirements, so that the throughput rate of a logic circuit is low and the accuracy is low in the image processing process. Therefore, how to improve the trigonometric function calculation accuracy in the graphics processing unit technology field becomes a technical problem to be solved urgently.
Disclosure of Invention
The application provides a trigonometric function calculation method, a trigonometric function calculation device, equipment and a storage medium, which are used for calculating the trigonometric function calculation precision in the technical field of graphic processing units.
In a first aspect, the present application provides a trigonometric function calculation method, including: converting a function to be discrete into a discrete function lookup table based on a preset lookup table; reconstructing the discrete function lookup table into a target function based on a nonlinear interpolation method of a trigonometric sum difference formula; the function calculation is simplified by decomposing the function lookup table into an odd lookup table and an even lookup table, and mapping the objective function within the [ - π, π ] period into [0, π/2] periods based on the periodicity of the objective function, the odd lookup table and the even lookup table.
Further, the converting the function to be discretized into a discrete function lookup table based on the preset lookup table includes:
uniformly mapping values in one radian period of the trigonometric function to a radian lookup table;
uniformly mapping values in an angle period of the trigonometric function to an angle lookup table;
uniformly mapping values within one scalar cycle of the trigonometric function to a scalar look-up table.
Further, the target function is a trigonometric function, and the reconstructing of the discrete function lookup table into the target function is based on a nonlinear interpolation method of a trigonometric sum and difference formula, and includes:
and when the angle of the trigonometric function does not belong to the index value of the angle lookup table, correspondingly looking up the value in the angle lookup table through the positions of the Ceil and the Floor, and weighting and calculating the angle approximate value through the nonlinear interpolation method based on the trigonometric sum and difference formula.
Further, after simplifying the function calculation by decomposing the function lookup table into an odd lookup table and an even lookup table, and mapping the objective function in the [ -pi, pi ] period into [0, pi/2 ] periods based on the periodicity of the objective function, the odd lookup table and the even lookup table, comprising:
mutually converting the Sin function and the Cos function in a [0, pi/2 ] period based on the periodic characteristics of the Sin function and the Cos function in the trigonometric function;
and calculating the converted trigonometric function by using a floating point number calculation method in a fixed point number system.
Further, in the fixed point number system, the floating point number calculation method is used to calculate the transformed trigonometric function, and includes:
decomposing the converted trigonometric function into an exponential part and a remainder part by the floating point number calculation method;
and carrying out normalization operation on the index part, and carrying out addition, subtraction, multiplication and division operation on the normalized index part according to a fixed point number mode.
Further, after mutually converting the Sin function and the Cos function within [0, pi/2 ] cycle based on the periodic characteristics of the Sin function and the Cos function in the trigonometric function, the method comprises:
transforming the trigonometric function within [ - π, π ] periods into [0, π/2] periods based on the periodic characteristics of the trigonometric function;
and increasing the input angle of the Sin function by pi/2 or reducing the input angle of the Cos function by pi/2 so as to enable the trigonometric function [0, pi/2 ] to share a design circuit in a period.
Further, the trigonometric function calculation method further comprises:
and storing the value of the floating point data type in the function lookup table so as to avoid error propagation caused by the quantization error of fixed point of the floating point number.
In a second aspect, the present application further provides an apparatus for improving computation accuracy of a trigonometric function, including:
the function lookup table acquisition module is used for converting the function to be discretized into a discrete function lookup table based on a preset lookup table;
the target function reconstruction module is used for reconstructing the discrete function lookup table into a target function based on a nonlinear interpolation method of a trigonometric sum-difference formula;
and the function mapping module is used for mapping the target function in the [ -pi, pi ] period to the [0, pi/2 ] period to simplify function calculation by decomposing the function lookup table into an odd lookup table and an even lookup table and based on the periodicity of the target function, the odd lookup table and the even lookup table.
In a third aspect, the present application further provides an apparatus comprising a memory and a processor; the memory is used for storing a computer program; the processor is configured to execute the computer program and implement the trigonometric function calculation method when executing the computer program.
In a fourth aspect, the present application also provides a computer-readable storage medium storing a computer program, which when executed by a processor causes the processor to implement the trigonometric function calculation method as described above.
The application discloses a trigonometric function calculation method, a device, equipment and a storage medium, wherein the trigonometric function calculation method comprises the steps of converting a function to be discrete into a discrete function lookup table based on a preset lookup table; reconstructing the discrete function lookup table into a target function based on a nonlinear interpolation method of a trigonometric sum difference formula; the function calculation is simplified by decomposing the function lookup table into an odd lookup table and an even lookup table, and mapping the target function within the [ - π, π ] period into [0, π/2] periods based on the periodicity of the target function, the odd lookup table and the even lookup table. According to the method, the period of the trigonometric function is reduced to [0, pi/2 ] through continuous and discrete mutual transformation of the trigonometric function, the function lookup table is decomposed, so that two adjacent trigonometric function values can be obtained in one period, the trigonometric function synchronously uses circuit design, the throughput rate of a logic circuit is improved, and the calculation precision of the trigonometric function is improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a schematic flowchart of a trigonometric function calculation method according to a first embodiment of the present application;
FIG. 2 is a schematic flow chart diagram of a trigonometric function calculation method provided by a second embodiment of the present application;
fig. 3 is a schematic block diagram of a trigonometric function calculation accuracy improving apparatus according to an embodiment of the present application;
fig. 4 is a block diagram schematically illustrating a structure of an apparatus according to an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some, but not all, embodiments of the present application. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The flow diagrams depicted in the figures are merely illustrative and do not necessarily include all of the elements and operations/steps, nor do they necessarily have to be performed in the order depicted. For example, some operations/steps may be decomposed, combined or partially combined, so that the actual execution order may be changed according to the actual situation.
It is to be understood that the terminology used in the description of the present application herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. As used in this specification and the appended claims, the singular forms "a", "an", and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
It should also be understood that the term "and/or" as used in this specification and the appended claims refers to any and all possible combinations of one or more of the associated listed items and includes such combinations.
The embodiment of the application provides a trigonometric function calculation method, a trigonometric function calculation device, equipment and a storage medium. The trigonometric function calculation method can be applied to a server, two adjacent trigonometric function values can be obtained in one period through the mutual conversion of the continuous trigonometric function and the discrete trigonometric function, the circuit design is synchronously used by the trigonometric function, the throughput rate of a logic circuit is improved, and the calculation precision of the trigonometric function is further improved. The server may be an independent server or a server cluster.
Some embodiments of the present application will be described in detail below with reference to the accompanying drawings. The embodiments and features of the embodiments described below can be combined with each other without conflict.
Referring to fig. 1, fig. 1 is a schematic flowchart of a trigonometric function calculation method according to a first embodiment of the present application. The trigonometric function calculation method can be applied to a server and is used for obtaining two adjacent trigonometric function values in a period through the continuous and discrete mutual transformation of the trigonometric function, and the trigonometric function synchronously uses the circuit design, so that the throughput rate of a logic circuit is improved, and the calculation precision of the trigonometric function is further improved.
As shown in fig. 1, the trigonometric function calculation method specifically includes steps S10 to S30.
S10, converting a function to be discretized into a discrete function lookup table based on a preset lookup table;
s20, reconstructing the discrete function lookup table into a target function by a nonlinear interpolation method based on a trigonometric sum-difference formula;
step S30, decomposing the function lookup table into an odd lookup table and an even lookup table, and mapping the target function in the [ - π, π ] period into a [0, π/2] period based on the periodicity of the target function, the odd lookup table and the even lookup table, so as to simplify the function calculation.
In a specific embodiment, taking a 360 ° panorama application as an example, the 360 ° panorama is projected on a 2D plane according to a mapping format of an equidistant spherical graph, and on a display device of an end user, because of a visual angle limitation of human eyes, only image content in an area in the panorama corresponding to a visual angle corresponding to a specific observation position needs to be projected on a user visual plane. Since the coordinates of the equi-distant spherical projection image are actually angles, the horizontal direction represents the latitude, the vertical direction represents the longitude, and the projection plane is cartesian coordinates at the user's angle. In order to obtain the accurate position of a pixel point on the equidistant spherical projection drawing on the user visual angle projection plane, accurate cosine and atan trigonometric functions are required, and if the computational accuracy of the trigonometric functions is insufficient, pixel coordinates close to the north/south pole position can generate intolerable offset, which can cause obvious image quality problems.
The following trigonometric function formula is used in this embodiment to obtain a more accurate fitting result of the sin/cos function:
cos(a+b)=cos(a)*cos(b)-sin(a)*sin(b),
the input arc radians of the cos function can be expressed as:
arc=k*table_step+frac,frac∈[0,table_size),
table_step=(π/2)/table_size,table_size=2^n。
[ kCosTable ] and [ kSinTable ] are used for storing table _ step integral multiple angles, and the fixed-point realization algorithm of [ kCosTable ] and [ kSinTable ] is as follows:
kCosTable[k]=std::cosf((int32_t)std::round(k*table_step);
kSinTable[k]=std::sinf((int32_t)std::round(k*table_step)。
the design purpose of [ kCosFracTable ] and [ kSinTracTable ] is to assist [ kCosTable ] and [ kSinTable ] in calculating the value of the non-table _ step integral multiple angle, and the sin/cos value of table _ step with table _ step/frac _ table _ size as the frac _ ts quantization step size is stored inside. The implementation algorithm is as follows:
kCosFracTable[k]=std::cosf((int32_t)std::round(k*frac_ts));
kSinFracTable[k]=std::sinf((int32_t)std::round(k*frac_ts)。
in the present embodiment, the input angle arc is decomposed as:
arc=k*table_step+f*frac_ts+factor*frac_ts;
arc=k*table_step-(f*frac_ts+factor*frac_ts)。
to improve hardware throughput, in the present invention kCosFracTable and ksinuflacttable are decomposed into odd and even lookup tables [ kCosFracTable e ], [ kCosFracTable table ] and
[kSinFracTableE],[kSinFracTableO]。
the embodiment discloses a trigonometric function calculation method, a device, equipment and a storage medium, wherein the trigonometric function calculation method comprises the steps of converting a function to be discrete into a discrete function lookup table based on a preset lookup table; reconstructing the discrete function lookup table into a target function based on a nonlinear interpolation method of a trigonometric sum difference formula; the function calculation is simplified by decomposing the function lookup table into an odd lookup table and an even lookup table, and mapping the target function within the [ - π, π ] period into [0, π/2] periods based on the periodicity of the target function, the odd lookup table and the even lookup table. The period of the trigonometric function is reduced to [0, pi/2 ] through the continuous and discrete mutual transformation of the trigonometric function, and the function lookup table is decomposed, so that two adjacent trigonometric function values can be obtained in one period, the trigonometric function synchronously uses the circuit design, the throughput rate of a logic circuit is improved, and the calculation precision of the trigonometric function is further improved.
Referring to fig. 2, fig. 2 is a schematic flowchart of a trigonometric function calculation method according to a second embodiment of the present application. The trigonometric function calculation method can be applied to a server and is used for obtaining two adjacent trigonometric functions in a period through continuous and discrete mutual transformation of the trigonometric functions, and the trigonometric functions synchronously use circuit design, so that the throughput rate of a logic circuit is improved, and further the calculation accuracy of the trigonometric functions is improved.
As shown in fig. 1, the step S10 specifically includes steps S11 to S13.
S11, uniformly mapping values in a radian period of the trigonometric function to a radian lookup table;
step S12, uniformly mapping values in an angle period of the trigonometric function to an angle lookup table;
and step S13, uniformly mapping the values in one scalar period of the trigonometric function to a scalar lookup table.
Based on the embodiment shown in fig. 2, in this embodiment, the step S12 includes:
and when the angle of the trigonometric function does not belong to the index value of the angle lookup table, correspondingly looking up the value in the angle lookup table through the positions of the Ceil and the Floor, and weighting and calculating the angle approximate value through the nonlinear interpolation method based on the trigonometric sum and difference formula.
In a specific embodiment, the index of the lookup table is an integer multiple of a floating point number radian step, and radians in a radian period are uniformly mapped into the lookup table with limited depth by taking the radian step as a unit. The numeric values stored within the table may be fixed point numbers or floating point numbers scaled to a range of numeric values.
The index of the lookup table is integral multiple of angle step of a floating point number, and the angles in an angle period are uniformly mapped to the lookup table with limited depth by taking the angle step as a unit. The numeric values stored within the table may be fixed point numbers or floating point numbers scaled to a range of numeric values.
The index of the lookup table is an integral multiple of a scalar step, and the angle or radian in a period is uniformly mapped into a fixed-point scalar range, and the scalar range is divided equally by the fixed-point scalar step. The numeric values stored within the table may be fixed point numbers or floating point numbers scaled to a range of numeric values.
The embodiment discloses a trigonometric function calculation method, a trigonometric function calculation device, equipment and a storage medium, wherein the trigonometric function calculation method comprises the steps of uniformly mapping values in a radian period of the trigonometric function to a radian lookup table; uniformly mapping values in an angle period of the trigonometric function to an angle lookup table; uniformly mapping values within one scalar period of the trigonometric function to a scalar look-up table; reconstructing the discrete function lookup table into a target function based on a nonlinear interpolation method of a trigonometric sum difference formula; the function calculation is simplified by decomposing the function lookup table into an odd lookup table and an even lookup table, and mapping the objective function within the [ - π, π ] period into [0, π/2] periods based on the periodicity of the objective function, the odd lookup table and the even lookup table. The period of the trigonometric function is reduced to [0, pi/2 ] through the continuous and discrete mutual transformation of the trigonometric function, and the function lookup table is decomposed, so that two adjacent trigonometric function values can be obtained in one period, the trigonometric function synchronously uses the circuit design, the throughput rate of a logic circuit is improved, and the calculation precision of the trigonometric function is further improved.
In this embodiment, after the step S30, the method further includes:
mutually converting the Sin function and the Cos function in a [0, pi/2 ] period based on the periodic characteristics of the Sin function and the Cos function in the trigonometric function;
and calculating the converted trigonometric function by using a floating point number calculation method in the fixed point number system.
After the above embodiment, the method further includes:
decomposing the converted trigonometric function into an exponential part and a remainder part by the floating point number calculation method;
and carrying out normalization operation on the index part, and carrying out addition, subtraction, multiplication and division operation on the normalized index part according to a fixed point number mode.
Further, still include:
transforming the trigonometric function within the [ -pi, pi ] period into a [0, pi/2 ] period based on the periodic characteristic of the trigonometric function;
and increasing the input angle of the Sin function by pi/2 or reducing the input angle of the Cos function by pi/2 so as to enable the trigonometric function [0, pi/2 ] to share a design circuit in a period.
Based on all the above embodiments, in this embodiment, the method for calculating a trigonometric function further includes:
and storing the value of the floating point data type in the function lookup table so as to avoid error propagation caused by the quantization error of fixed point of the floating point number.
Referring to fig. 3, fig. 3 is a schematic block diagram of an apparatus for improving computation accuracy of a trigonometric function according to an embodiment of the present application, wherein the apparatus for improving computation accuracy of a trigonometric function is used for executing the above method for computing a trigonometric function. The trigonometric function calculation accuracy improving device can be configured in a server.
As shown in fig. 3, the trigonometric function calculation accuracy improving apparatus 400 includes:
a function lookup table obtaining module 10, configured to convert a function to be discretized into a discrete function lookup table based on a preset lookup table;
an objective function reconstructing module 20, configured to reconstruct the discrete function lookup table into an objective function based on a nonlinear interpolation method of a sum-of-triangles formula;
a function mapping module 30, configured to map the objective function in [ -pi, pi ] periods into [0, pi/2 ] periods by decomposing the function lookup table into an odd lookup table and an even lookup table, and based on the periodicity of the objective function, the odd lookup table and the even lookup table, so as to simplify function calculation.
Further, the function lookup table obtaining module 10 further includes:
the radian lookup table generating unit is used for uniformly mapping values in a radian period of the trigonometric function to a radian lookup table;
an angle lookup table generating unit for mapping values in one angle period of the trigonometric function to an angle lookup table uniformly;
a scalar lookup table generating unit for mapping values within one scalar period of the trigonometric function to a scalar lookup table uniformly.
Further, the objective function reconstruction module 20 specifically includes:
and the angle approximate value calculating unit is used for correspondingly searching the value in the angle lookup table through the positions of Ceil and Floor when the angle of the trigonometric function does not belong to the index value of the angle lookup table, and weighting and calculating the angle approximate value through the nonlinear interpolation method based on the trigonometric sum and difference formula.
Further, the apparatus for improving the accuracy of trigonometric function calculation further comprises a conversion module, wherein the conversion module specifically comprises:
the conversion unit is used for converting the Sin function and the Cos function into each other in a [0, pi/2 ] period based on the periodic characteristics of the Sin function and the Cos function in the trigonometric function;
and the floating point number calculation unit is used for calculating the converted trigonometric function by using a floating point number calculation method in the fixed point number system.
Further, the floating point number calculation unit includes:
the decomposition subunit is used for decomposing the converted trigonometric function into an exponent part and a remainder part by the floating point number calculation method;
and the normalization calculation subunit is used for performing normalization operation on the index part and performing addition, subtraction, multiplication and division operation on the normalized index part in a fixed point number mode.
Further, the conversion module further comprises:
a trigonometric function period transforming unit for transforming the trigonometric function within [ - π, π ] periods into [0, π/2] periods based on the periodic characteristics of the trigonometric function;
and the angle transformation unit is used for increasing the input angle of the Sin function by pi/2 or reducing the input angle of the Cos function by pi/2 so as to enable the trigonometric function [0, pi/2 ] to share a design circuit in a period.
Further, the device for improving the computational accuracy of the trigonometric function further comprises a floating point data storage module, wherein the floating point data storage module specifically comprises:
and the floating point data storage unit is used for storing the value of the floating point data type in the function lookup table so as to avoid error propagation caused by quantization error of fixed-point floating point number.
It should be noted that, as will be clear to those skilled in the art, for convenience and brevity of description, the specific working processes of the apparatus and the modules described above may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
The apparatus described above may be implemented in the form of a computer program which may be run on a device as shown in figure 4.
Referring to fig. 4, fig. 4 is a schematic block diagram of a structure of an apparatus according to an embodiment of the present application. The device may be a server.
Referring to fig. 4, the apparatus includes a processor, a memory, and a network interface connected by a system bus, wherein the memory may include a nonvolatile storage medium and an internal memory.
The non-volatile storage medium may store an operating system and a computer program. The computer program includes program instructions that, when executed, cause a processor to perform any of the trigonometric function calculation methods.
The processor is used to provide computing and control capabilities to support the operation of the overall device.
The internal memory provides an environment for execution of a computer program on a non-volatile storage medium, which when executed by the processor causes the processor to perform any of the trigonometric function calculation methods.
The network interface is used for network communication, such as sending assigned tasks. It will be appreciated by those skilled in the art that the configuration shown in fig. 4 is a block diagram of only a portion of the configuration associated with the present application, and does not constitute a limitation on the devices to which the present application may be applied, and that a particular device may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
It should be understood that the Processor may be a Central Processing Unit (CPU), and the Processor may be other general purpose processors, digital Signal Processors (DSPs), application Specific Integrated Circuits (ASICs), field Programmable Gate Arrays (FPGAs) or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components, etc. Wherein a general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
Wherein, in one embodiment, the processor is configured to execute a computer program stored in the memory to implement the steps of:
converting a function to be discretized into a discrete function lookup table based on a preset lookup table;
reconstructing the discrete function lookup table into a target function based on a nonlinear interpolation method of a trigonometric sum difference formula;
the function calculation is simplified by decomposing the function lookup table into an odd lookup table and an even lookup table, and mapping the objective function within the [ - π, π ] period into [0, π/2] periods based on the periodicity of the objective function, the odd lookup table and the even lookup table.
In an embodiment, the function to be discretized is a trigonometric function, and the function to be discretized is converted into a discrete function lookup table based on a preset lookup table, so as to implement:
uniformly mapping values in one radian period of the trigonometric function to a radian lookup table;
uniformly mapping values in one angle period of the trigonometric function to an angle lookup table;
uniformly mapping values within one scalar cycle of the trigonometric function to a scalar look-up table.
In one embodiment, the objective function is a trigonometric function, and the non-linear interpolation based on the sum and difference of triangles reconstructs the discrete function lookup table as the objective function, so as to implement:
and when the angle of the trigonometric function does not belong to the index value of the angle lookup table, correspondingly searching the value in the angle lookup table through the positions of Ceil and Floor, and weighting and calculating the angle approximate value through the nonlinear interpolation method based on the trigonometric sum and difference formula.
In one embodiment, the method is implemented by decomposing the function lookup table into an odd lookup table and an even lookup table, and mapping the objective function in [ - π, π ] cycles into [0, π/2] cycles based on the periodicity of the objective function, the odd lookup table and the even lookup table to simplify function computations:
mutually converting the Sin function and the Cos function in a [0, pi/2 ] period based on the periodic characteristics of the Sin function and the Cos function in the trigonometric function;
and calculating the converted trigonometric function by using a floating point number calculation method in a fixed point number system.
In one embodiment, the transformed trigonometric function is calculated in a fixed-point number system by using a floating-point number calculation method, and is used for realizing:
decomposing the converted trigonometric function into an exponential part and a remainder part by the floating point number calculation method;
and carrying out normalization operation on the index part, and carrying out addition, subtraction, multiplication and division operation on the normalized index part according to a fixed point number mode.
In one embodiment, based on the periodic characteristics of the Sin function and the Cos function in the trigonometric function, after mutually converting the Sin function and the Cos function within [0, pi/2 ] period, the method is used for realizing:
transforming the trigonometric function within the [ -pi, pi ] period into a [0, pi/2 ] period based on the periodic characteristic of the trigonometric function;
and increasing the input angle of the Sin function by pi/2 or reducing the input angle of the Cos function by pi/2 so as to enable the trigonometric function [0, pi/2 ] to share a design circuit in a period.
In one embodiment, the trigonometric function calculation method is further used for implementing:
and storing the value of the floating point data type in the function lookup table so as to avoid error propagation caused by the quantization error of fixed point of the floating point number.
In an embodiment of the present application, a computer-readable storage medium is further provided, where a computer program is stored in the computer-readable storage medium, where the computer program includes program instructions, and the processor executes the program instructions to implement any one of the trigonometric function calculation methods provided in the embodiments of the present application.
The computer-readable storage medium may be an internal storage unit of the device according to the foregoing embodiment, for example, a hard disk or a memory of the device. The computer readable storage medium may also be an external storage device of the device, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), etc. provided on the device.
While the invention has been described with reference to specific embodiments, the scope of the invention is not limited thereto, and those skilled in the art can easily conceive various equivalent modifications or substitutions within the technical scope of the invention. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.
Claims (10)
1. A trigonometric function calculation method, characterized by comprising:
converting a function to be discrete into a discrete function lookup table based on a preset lookup table;
reconstructing the discrete function lookup table into a target function based on a nonlinear interpolation method of a trigonometric sum difference formula;
the function calculation is simplified by decomposing the function lookup table into an odd lookup table and an even lookup table, and mapping the objective function within the [ - π, π ] period into [0, π/2] periods based on the periodicity of the objective function, the odd lookup table and the even lookup table.
2. The method according to claim 1, wherein the function to be discretized is a trigonometric function, and the converting the function to be discretized into a discrete function lookup table based on a preset lookup table comprises:
uniformly mapping values in a radian period of the trigonometric function to a radian lookup table;
uniformly mapping values in one angle period of the trigonometric function to an angle lookup table;
uniformly mapping values within one scalar cycle of the trigonometric function to a scalar look-up table.
3. The method of claim 2, wherein the objective function is a trigonometric function, and the reconstructing the discrete function lookup table as the objective function based on a nonlinear interpolation of a sum and difference of triangles comprises:
and when the angle of the trigonometric function does not belong to the index value of the angle lookup table, correspondingly looking up the value in the angle lookup table through the positions of the Ceil and the Floor, and weighting and calculating the angle approximate value through the nonlinear interpolation method based on the trigonometric sum and difference formula.
4. The trigonometric function calculation method of claim 1, wherein the simplifying the function calculation by decomposing the function lookup table into an odd lookup table and an even lookup table and mapping the objective function within the [ -pi, pi ] period into the [0, pi/2 ] period based on the periodicity of the objective function, the odd lookup table and the even lookup table comprises:
converting the Sin function and the Cos function into each other in a [0, pi/2 ] period based on the periodic characteristics of the Sin function and the Cos function in the trigonometric function;
and calculating the converted trigonometric function by using a floating point number calculation method in the fixed point number system.
5. The method of claim 4, wherein the computing the transformed trigonometric function using a floating point number computation method in a fixed point number system comprises:
decomposing the converted trigonometric function into an exponential part and a remainder part by the floating point number calculation method;
and carrying out normalization operation on the index part, and carrying out addition, subtraction, multiplication and division operation on the normalized index part according to a fixed point number mode.
6. The method according to claim 4, wherein said transforming the Sin function and the Cos function to each other within [0, pi/2 ] cycles based on periodic characteristics of the Sin function and the Cos function in the trigonometric function comprises:
transforming the trigonometric function within the [ -pi, pi ] period into a [0, pi/2 ] period based on the periodic characteristic of the trigonometric function;
and increasing the input angle of the Sin function by pi/2 or reducing the input angle of the Cos function by pi/2 so as to enable the trigonometric function [0, pi/2 ] to share a design circuit in a period.
7. The method of trigonometric function calculation according to any one of claims 1 to 6, further comprising:
and storing the value of the floating point data type in the function lookup table so as to avoid error propagation caused by the quantization error of fixed point of the floating point number.
8. A trigonometric function calculation accuracy improving apparatus, comprising:
the function lookup table acquisition module is used for converting the function to be discretized into a discrete function lookup table based on a preset lookup table;
the target function reconstruction module is used for reconstructing the discrete function lookup table into a target function based on a nonlinear interpolation method of a trigonometric sum-difference formula;
and the function mapping module is used for mapping the target function in the [ -pi, pi ] period to the [0, pi/2 ] period to simplify function calculation by decomposing the function lookup table into an odd lookup table and an even lookup table and based on the periodicity of the target function, the odd lookup table and the even lookup table.
9. An apparatus, characterized in that the apparatus comprises a memory and a processor;
the memory is used for storing a computer program;
the processor for executing the computer program and implementing the trigonometric function calculation method of any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that a computer program is stored which, when executed by a processor, causes the processor to carry out the trigonometric function calculation method of any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211329702.5A CN115659110A (en) | 2022-10-27 | 2022-10-27 | Trigonometric function calculation method, device, equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211329702.5A CN115659110A (en) | 2022-10-27 | 2022-10-27 | Trigonometric function calculation method, device, equipment and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN115659110A true CN115659110A (en) | 2023-01-31 |
Family
ID=84993299
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202211329702.5A Pending CN115659110A (en) | 2022-10-27 | 2022-10-27 | Trigonometric function calculation method, device, equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN115659110A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116796114A (en) * | 2023-06-25 | 2023-09-22 | 广州呗呗科技有限公司 | FOC algorithm optimization method |
-
2022
- 2022-10-27 CN CN202211329702.5A patent/CN115659110A/en active Pending
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116796114A (en) * | 2023-06-25 | 2023-09-22 | 广州呗呗科技有限公司 | FOC algorithm optimization method |
CN116796114B (en) * | 2023-06-25 | 2024-03-29 | 广州呗呗科技有限公司 | FOC algorithm optimization method |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US11842438B2 (en) | Method and terminal device for determining occluded area of virtual object | |
CN112785674B (en) | Texture map generation method, rendering device, equipment and storage medium | |
CN108537721B (en) | Panoramic image processing method and device and electronic equipment | |
CN109712234B (en) | Three-dimensional human body model generation method, device, equipment and storage medium | |
US8090756B2 (en) | Method and apparatus for generating trigonometric results | |
Ngo et al. | A pipelined architecture for real-time correction of barrel distortion in wide-angle camera images | |
TW200529041A (en) | System and method for accelerating a special purpose processor | |
CN115659110A (en) | Trigonometric function calculation method, device, equipment and storage medium | |
CN114998406B (en) | Self-supervision multi-view depth estimation method and device | |
CN116700663B (en) | Floating point number processing method and device | |
CN102663666B (en) | Two-dimensional image resampling algorithm accelerator based on field-programmable gate array (FPGA) | |
JP4757328B2 (en) | Inverse tangent calculation device and inverse tangent calculation program | |
CN113096231B (en) | Image processing method and device, electronic equipment and storage medium | |
JP5733379B2 (en) | Processor and calculation method | |
CN116245731A (en) | Method, device, equipment and medium for splicing scanning data | |
CN115661493A (en) | Object pose determination method and device, equipment and storage medium | |
CN116700664B (en) | Method and device for determining square root of floating point number | |
CN116700666B (en) | Floating point number processing method and device | |
CN116700665B (en) | Method and device for determining floating point number square root reciprocal | |
US20200348268A1 (en) | Ultrasound image display method and apparatus, storage medium, and electronic device | |
CN114202465A (en) | Image rotation method, image rotation system, and storage medium | |
US9875084B2 (en) | Calculating trigonometric functions using a four input dot product circuit | |
CN113470154B (en) | Image processing method, device, electronic equipment and storage medium | |
CN117991307B (en) | Method and device for solving displacement of navigation receiver | |
Perez et al. | Real-time voxel-based visual hull reconstruction |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |