Background
Division operation is one of the basic operations in a processor (including DSP and embedded chips) and is a very important functional component. In computer graphics, computer vision, visualization, geographic information systems, grid generation techniques and scientific computing, very high precision division operations (beyond that provided by computer hardware) are often required, at which point software is required to simulate floating-point division operations. Compared with floating-point addition, subtraction and multiplication, division operation is more complex and takes longer, so that the design of a calculation scheme of high-performance division is very important. At present, there are five main methods for division: a function iteration algorithm, a numerical loop algorithm, a very large radix algorithm, a table look-up method, and a variable computation period method. Of all these algorithms, the numerical loop algorithm and the function iteration method are the two most commonly used algorithms. The convergence rate of the digital loop algorithm is linear, while the convergence rate of the function iteration algorithm is quadratic.
Function iterative algorithms are widely used in the design of divisions in modern general-purpose processors. Obtaining the division parameter to be divided often requires providing an initial approximate value of a quotient, and then gradually approaches to an accurate quotient through a certain iterative format. A mature function iterative algorithm generally needs to give an initial approximation and an iterative format to perform iterative operation until an iterative result meets the accuracy requirement. However, when processing with a large amount of data is involved, the existing iterative algorithm has a serious problem of wasting computing resources, and the computational efficiency of the iterative algorithm needs to be improved urgently.
Disclosure of Invention
The application provides a division operation method, a division operation device, electronic equipment and a medium.
In a first aspect, a method of division operation is provided, including:
obtaining a division parameter to be subjected to division operation, and obtaining a first iteration value;
performing error analysis processing according to the first iteration value, and determining rounding operation required by the division parameter in the current iteration;
continuing iterative processing according to the division parameter after the rounding operation to obtain a second iterative value;
if the second iteration value does not meet the precision requirement, the second iteration value is used as the first iteration value to repeatedly execute the steps until the second iteration value meets the precision requirement, and the second iteration value is output.
In an optional implementation manner, the performing, according to the first iteration value, an error analysis process to determine a rounding operation that needs to be performed on the division parameter in the current iteration includes:
acquiring a first error of the first iteration value and a second error of the second iteration value;
and determining the rounding operation required to be carried out on the division parameter in the iteration according to the first error and the second error.
In an optional implementation, the determining, according to the first error and the second error, a rounding operation that needs to be performed on the division parameter in the current iteration includes:
determining a precision of a rounding operation of the first iteration value based on the precision of the first error; and determining the precision of the rounding operation of the divisor and/or dividend of the division operation according to the precision of the second error.
In an optional implementation, the determining, according to the first error and the second error, a rounding operation that needs to be performed on the division parameter in the current iteration includes:
and determining the rounding operation required to be carried out on the first iteration value and the divisor according to the index of the first error.
In an alternative embodiment, the first error is:
wherein x
nIs the first iteration value, a is the divisor, N
nIs a positive integer, E
nRepresents a constant;
the determining, according to the exponent of the first error, a rounding operation required for the first iteration value and the divisor, includes:
determining the xnThe rounding operation to be performed is to round NnThe numbers after +1 bit are truncated;
determining that said a requires rounding by Nn+1The numbers after +1 bit are truncated.
In an optional embodiment, the method further comprises:
obtaining intermediate numbersAccording to
The above-mentioned
Is said x
nObtained after the rounding operation is carried out, the
Obtaining the a after the rounding operation is carried out on the a;
e is to be
nIn N
n+1The number after +1 bit is truncated to obtain intermediate data after the rounding operation
The step of continuing iterative processing according to the parameter after the rounding operation to obtain a second iterative value includes:
according to the intermediate data after the rounding operation
And said
Calculating a second iteration value x
n+1。
In an alternative embodiment, the first error is:
wherein x
nIs the first iteration value, a is the divisor, N
nIs a positive integer, E
nRepresents a constant;
the method further comprises the following steps:
determining a rounding operation required for the first error according to the exponent of the first error;
the step of continuing iterative processing according to the parameter after the rounding operation to obtain a second iterative value comprises:
according to the rounding operationCalculating a second iteration value x of the first error after the rounding operation, the first iteration value after the rounding operation, the divisor after the rounding operation, and other intermediate parameters after the rounding operationn+1。
In a second aspect, there is provided a division operation apparatus, including:
the acquisition module is used for acquiring a division parameter to be subjected to division operation and acquiring a first iteration value;
the processing module is used for carrying out error analysis processing according to the first iteration value and determining rounding operation required by the division parameter in the current iteration;
the processing module is further configured to continue iterative processing according to the parameter after the rounding operation to obtain a second iterative value;
the processing module is further configured to, if the second iteration value does not meet the accuracy requirement, repeatedly execute the above steps with the second iteration value as the first iteration value;
and the output module is used for outputting the second iteration value until the second iteration value meets the precision requirement.
In a third aspect, an electronic device is provided, comprising a memory and a processor, the memory storing a computer program that, when executed by the processor, causes the processor to perform the steps as in the first aspect and any one of its possible implementations.
In a fourth aspect, there is provided a computer storage medium storing one or more instructions adapted to be loaded by a processor and to perform the steps of the first aspect and any possible implementation thereof.
The method comprises the steps of obtaining a division parameter to be subjected to division operation, obtaining a first iteration value, carrying out error analysis processing according to the first iteration value, determining rounding operation required by the division parameter in the current iteration, continuing iteration processing according to the parameter after the rounding operation, obtaining a second iteration value, and if the second iteration value does not meet the precision requirement, repeatedly executing the steps by taking the second iteration value as the first iteration value until the second iteration value meets the precision requirement, and outputting the second iteration value. Based on an error analysis theory, under the premise of ensuring the precision, invalid numbers beyond the error are rounded, so that numerical values of short word length and equal precision are substituted into an iteration rule for calculation, the waste of calculation resources can be greatly reduced, and the operation efficiency of a function iteration algorithm is improved.
Detailed Description
In order to make the technical solutions of the present application better understood, 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 only a part of the embodiments of the present application, and not all of the embodiments. 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 terms "first," "second," and the like in the description and claims of the present application and in the above-described drawings are used for distinguishing between different objects and not for describing a particular order. Furthermore, the terms "include" and "have," as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not limited to only those steps or elements listed, but may alternatively include other steps or elements not listed, or inherent to such process, method, article, or apparatus.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the application. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. It is explicitly and implicitly understood by one skilled in the art that the embodiments described herein can be combined with other embodiments.
The embodiments of the present application will be described below with reference to the drawings.
Referring to fig. 1, fig. 1 is a schematic flow chart of a division operation method according to an embodiment of the present application. The method can comprise the following steps:
101. obtaining a division parameter to be subjected to division operation, and obtaining a first iteration value.
The execution subject of the embodiments of the present application may be a division operation apparatus, and may be an electronic device, which in a specific implementation is a terminal, and may also be referred to as a terminal device, including but not limited to other portable devices such as a mobile phone, a laptop computer, or a tablet computer having a touch-sensitive surface (e.g., a touch screen display and/or a touch pad). It should also be understood that in some embodiments, the device is not a portable communication device, but is a desktop computer. In an alternative embodiment, the division operation method may be executed by a corresponding hardware module, such as a chip or a divider, or may alternatively be executed based on a software program.
In the embodiment of the application, the division operation is implemented by using a function iteration algorithm, and the main theoretical basis is an error analysis theory of the function iteration algorithm. In this embodiment of the application, the division parameter to be subjected to division operation may be from any application scenario that needs to be subjected to division operation, and may include one or more of a dividend, a divisor, each iteration value, and an error, and may be determined according to a used algorithm, which is not limited herein. The division operation method in the embodiment of the present application may be performed in the case of obtaining a specific division parameter. In the embodiment of the present application, assuming that the dividend is b and the divisor is a, the quotient is calculated by using a function iteration method, and the iteration format (1) is:
xn+1=f(a,b,xn);
wherein xnThe approximate quotient after the nth iteration is also referred to as the iteration value in each iteration.
The first iteration value may be any iteration value in an iteration process, including an initial iteration value x0。
102. And carrying out error analysis processing according to the first iteration value, and determining the rounding operation required by the division parameter in the current iteration.
Specifically, in each iteration, the error of the iterative approximation value may be calculated based on the error analysis theory of the iteration format (1) used, and then, according to the error analysis theory, on the premise of ensuring the accuracy, the rounding operation may be performed on the invalid number beyond the error. The specific iterative format has a specific error analysis theory, and is not limited herein.
In an alternative embodiment, the step 102 includes:
acquiring a first error of the first iteration value and a second error of the second iteration value;
and determining the rounding operation required to be carried out on the division parameter in the current iteration according to the first error and the second error.
The above rounding operation may be understood as an operation of retaining the bits after the decimal point in any form. In the process of calculating the quotient, the quotient at each step is approximate, and the precision of the quotient can be given according to an error analysis theory. With approximate quotient x
nFor example, 0.123456789012345, the approximate quotient decimal point is followed by a 15 digit number. Iterative algorithm in functionThe error of the approximation quotient can be calculated for each iteration. Suppose that the error of the approximation quotient 0.123456789012345 is
nAnd 0.01, all the numbers after the 3 rd digit after the approximate quotient decimal point are practically useless and belong to invalid numbers, and if all the numbers participate in calculation, the calculation resources are wasted. The invalid numbers are cut off to obtain approximate quotient
Can be combined with
And (4) substituting the approximate quotient into an iterative format (1) of the algorithm for calculation.
The first error is any value that measures the accuracy of the first iteration value, such as an absolute difference, a relative error, and the like between the first iteration value and a true value, and is not limited herein. The second error is any value that measures the accuracy of the second iteration value, such as the absolute difference, relative error, etc. of the second iteration value and the true value, and is not limited herein.
Since the accuracy of 0.12 and the accuracy of 0.123456789012345 are the same, the next iteration value x is not affected
n+1The accuracy of (2). But it is clear that the calculation with 0.12 is much simpler than the calculation with 0.123456789012345. Meanwhile, according to the error analysis theory, the error can be measured at x
n+1Before being calculated, its accuracy is known (for ease of explanation, assume x
n+1Has an error of
n+10.0001). Then according to
n+1It can be seen that, for example, other values (e.g., a and b) required in the iterative format may be used in the actual calculation, and the rounding operation may be performed without loss of accuracy. Due to the fact that
And
is longer than a, b and x
nThe word length of the method is short, and the calculation is simpler and quicker.
The division parameter may include one or more of a dividend b, a divisor a, each iteration value, and an error, and may be determined according to an algorithm used, which is not limited herein. The division operation method in the embodiment of the present application may be performed in the case of obtaining a specific division parameter.
In one embodiment, an initial iteration value x is set0The following steps may be performed:
1) obtaining x according to the error analysis theory of the adopted function iterative algorithmnError of (2)nAnd xn+1Error of (2)n+1,n=0,1,…;
2) According to the error, the iteration parameter (such as x) related to the iteration format is determined on the premise of ensuring the precision
nA and b, etc.) to obtain a short word length value (corresponding to the value of the word length)
And
)。
optionally, the determining, according to the first error and the second error, a rounding operation that needs to be performed on the division parameter in the current iteration includes:
determining a precision of a rounding operation of the first iteration value based on the precision of the first error; and determining the precision of rounding operations of the divisor, the dividend and other iteration parameters related to the iteration format of the division operation according to the precision of the second error.
In particular, the first iteration value x may be setnIs set to be in error with the firstnWith the same precision, a, b, and other iteration parameters involved in the iteration format are set to the second errorn+1With the same precision, to perform the iterative operation.
103. And continuing iterative processing according to the parameters after the rounding operation to obtain a second iterative value.
According to the error analysis theory, under the premise of ensuring the precision, invalid numbers beyond the error are rounded, and the obtained parameters after the rounding operation are substituted into the iteration rule for calculation, so that the calculation complexity is simplified, and the calculation efficiency is improved.
104. If the second iteration value does not meet the precision requirement, the second iteration value is used as the first iteration value to repeatedly execute the steps until the second iteration value meets the precision requirement, and the second iteration value is output.
In the embodiment of the application, for a function iteration algorithm capable of giving error analysis, iteration is sequentially circulated according to an iteration format (1), and a more accurate approximate quotient can be obtained in each iteration. The error and the precision of the iteration result of each step can be judged according to the error analysis result, so that whether the iteration is finished or not is judged. The basic iterative algorithm is not described in detail here.
See fig. 2 for a flow diagram of a division method. The iterative algorithm steps in fig. 2 include: 21. substituting the initial value into an iteration rule; 22. carrying out iterative calculation to obtain an approximate value; 23. calculating an error; ending under the condition that the judgment error is accepted; if the error is judged not to be accepted, executing 24, and according to the error, eliminating invalid numbers in the relevant numerical values; 25. and substituting the rounded numerical value into an iteration rule. Multiple iterations may be performed through the above steps.
In each iteration, the division operation method in the embodiment of the application calculates the error of the iteration approximate value based on the error analysis theory of the adopted iteration format, and then performs rounding operation on invalid numbers beyond the error according to the error analysis theory on the premise of ensuring the precision, so that the numerical values of short word length and equal precision are substituted into the iteration rule for calculation, the calculation complexity can be simplified, and the calculation efficiency is improved.
To further describe the application of the division operation method in the embodiment of the present application, the following description is made in detail in conjunction with different iterative algorithms (formats).
In one embodiment, the rounding operations required for the first iteration value and the divisor may be determined based on the exponent of the first error.
The division operation method can be applied to different iterative algorithms, and because of different iterative rules, the error calculation may also be different, and further, the rounding operation on the related data in the calculation may also be different.
In an alternative embodiment, the first error is:
wherein x
nIs the first iteration value, a is the divisor, N
nIs a positive integer, E
nRepresents a constant;
n is aboven+1The method is an index corresponding to an error in the (n + 1) th iteration, and the rounding operation required for determining the first iteration value and the divisor according to the index of the first error comprises the following steps:
determining the above xnThe rounding operation to be performed is to round NnThe numbers after +1 bit are truncated;
determining the rounding operation required for a is to round Nn+1The numbers after +1 bit are truncated.
Specifically, the application can be further illustrated by taking a Newton-Rapshon algorithm as an example. Let a be the divisor, b be the dividend, and the quotient be Q. The Newton-Rapshon algorithm is used to calculate x 1 ÷ a and then the quotient Q is calculated b × x in one multiplication. The Newton-Rapshon algorithm is a function iteration algorithm, and an initial value x needs to be provided during calculation0Then, the following iterative format is used for calculation:
xn+1=xn×(2-a×xn);
definition of xnHas an error ofn=1-a×xnThen the above formula can be expressed as:
xn+1=xn×(1+n);
xn+1error of (2)n+1Can be expressed as:
as can be seen from the above equation, the Newton-Rapshon algorithm converges secondarily. If the initial iteration value x0Choose good, then initial error0It is small and the number of iterations is small. In the current method for improving the Newton-Rapshon algorithm, the initial iteration value x is mostly aimed at0The selection of (2) is improved. According to the method, the Newton-Rapshon algorithm is improved by using the error analysis result, the calculation amount can be reduced, and the calculation efficiency of the division is improved.
In the process of carrying out division operation by adopting a Newton-Rapshon algorithm, because errors generated by each iteration are different, the iteration precision gradually becomes better along with the increase of the iteration times. While in the initial few iterations, xnIs not good, so xnIt is not necessary to store all the numbers, but only the number corresponding to the precision, and thus the multiplication a × x is calculatednIn time, all numbers do not need to be calculated, and invalid numbers exceeding the error can be discarded, thereby reducing the calculation amount. The details will be described below. Assuming that the reciprocal x of a is 1 ÷ a, a is represented as: a is Ax 2MWherein | A | is more than or equal to 1 and less than or equal to 2, and M is an integer. If | a ≦ 1, a ═ a. Since the reciprocal of a is actually equal to a ═ A-1×2-MThus, without loss of generality, discussion can be made only with respect to 1 ≦ a ≦ 2. An initial approximation of 0 ≦ x may be provided at this time0Less than or equal to 1, and the specific calculation steps are as follows:
1) according to the initial iteration value x0Calculating an initial error0And it is expressed as follows according to a scientific counting method:
wherein-N0Is that0Index of (1), N0Is a positive integer.
2) Iterate by n-0, 1, …. x is the number ofnHas an error ofnAn index of-NnThus x will benIn NnThe numbers after +1 are truncated, representing this step as:
where Roundoff () represents a rounding operation. After rounding off
Is still the error of
Of the order of (d), and therefore does not affect the accuracy of the next iteration, but does so
Word length is greater than x
nThe word length of (2) is much smaller, and the data processing amount is simplified. The rounding method of the rounding operation may be the rounding method provided in IEEE745 standard, and may also use "
quasi-round 1 in" method, "constant one" method, etc., which is not limited in the embodiments of the present application.
Further optionally, the method further comprises:
obtaining intermediate data
Above is x
nObtained after the rounding operation, the
The rounding operation is carried out for the a;
e is to be
nIn N
n+1The numbers after +1 bit are truncated to obtain intermediate data after the rounding operation
The above-mentioned continuing the iterative process according to the parameter after the rounding operation, and obtaining the second iterative value includes:
according to the intermediate data after the rounding operation
And the above
Calculating a second iteration value x
n+1。
In the Newton-Raphson algorithm, a second iteration value x is obtained
n+1Intermediate data may be first calculated from the divisor and the previous iteration value, including the divisor after each rounding operation described above
And the iteration value
A corresponding rounding operation may still be used in the calculation of the intermediate data. Continuing by way of example, the following steps may be seen:
3) according to the error analysis theory of the Newton-Raphson algorithm, the error of each iteration is reduced according to the square, so that x
n+1Must be twice the last error index, so there is N
n+1=2N
n. But in calculating x
n+1When it is needed to use
Wherein
The word length of (a) is very short, while a retains all the exact digits, which are very long. Because of x
n+1It is still not accurate and therefore it is not necessary to use the exact a, and a can be rounded to fit N in a
n+1The numbers after +1 are truncated to give
According to
And e
nCan calculate
But e
nIs obtained by multiplication. In general, subtraction has little effect on the word length of the result during calculation, and multiplication often results in a significant increase in word length. Because of x
n+1With a precision of
So that e can be controlled with guaranteed accuracy
nA rounding operation is performed, so that:
5) finally calculate xn+1
If xn+1And returning to 2) to continue calculating when n is equal to n + 1.
The division operation method in the embodiment of the application is suitable for a Newton-Raphson algorithm, and the rounding operation combined with the characteristics of the algorithm can reduce the data calculation amount without influencing the accuracy and improve the processing efficiency.
In an alternative embodiment, the application is further described by taking the Markstein algorithm as an example.
Optionally, the first error is:
wherein x
nIs the first iteration value, a is the divisor, N
nIs a positive integer, E
nRepresents a constant;
the method further comprises the following steps:
determining a rounding operation required for the first error according to the exponent of the first error;
the above-mentioned continuing iterative processing according to the parameter after the rounding operation to obtain a second iterative value includes:
calculating a second iteration value x based on the first error after the rounding operation and the first iteration value after the rounding operationn+1。
Similar to the application of the Newton-Raphson algorithm, the above steps may correspond to the Markstein algorithm, the iterative format of which is as follows:
xn+1=xn+xn×n,n+1=1-a×xn+1;
the method is used for a Markstein algorithm, and the specific calculation steps are as follows:
1) according to the initial iteration value x0Calculating an initial error0And it is expressed as follows according to a scientific counting method:
wherein-N0Is that0Index of (1), N0Is a positive integer. According to N0X is to be0In N0The numbers after +1 are truncated, representing this step as:
2) according to the formula n ═ n0,1, … iterate. Firstly, to
nA rounding operation is performed. The Markstein algorithm is second order convergent, so x
n+1Has an error of
Magnitude. To ensure to be paired
nAfter rounding operation, the calculation x is not influenced
n+1To a precision of
nRetention of 2N
nA bit significant digit whose rounding operation is expressed as:
3) computing
And to e
nA rounding operation is performed. For the same reason, to ensure x
n+1Has an error of
Magnitude, pair e
nThe rounding operation is performed by reserving 2N
nBit significant digits, rounded by operations represented as
4) Computing
And to x
n+1Performing rounding operations
5) The rounding operation is performed on a next. The purpose of rounding a is to calculate x
n+2According to the quadratic convergence property of the algorithm, x
n+2Has an error of
Magnitude. Therefore, to ensure that the calculation of x is not affected after the rounding operation is performed on a
n+2With a retained 4N
nBit significant digits, rounded by operations represented as
6) Computing
Error of (2)
wherein-N
n+1Is that
n+1Is used as an index of (1). If it is judged that
And returning to 2) to continue calculating when n is equal to n + 1.
The above two embodiments of the iterative algorithm were tested experimentally. The experiment is carried out in a epsilon [1,2 ]]Any 100000 points are taken, the reciprocal of the 100000 points is calculated, 0.5 is taken as an initial value, and each point is iterated for 6 times. Meanwhile, the traditional Newton-Raphson algorithm and Markstein are adopted for calculation. The calculation result shows that the prior Newton-Raphson algorithm calculates 100000 points, and the average error after 6 iterations is 0.45 multiplied by 10-16Standard deviation of 0.66X 10-16. The prior Markstein algorithm calculates 100000 points, and the average error after 6 iterations is 0.45 multiplied by 10-16Standard deviation of 0.65X 10-16. The average error of the Newton-Raphson algorithm adopted in the embodiment of the application is 0.52 multiplied by 10-16Standard deviation of 0.72X 10-16(ii) a The average error of the Markstein algorithm adopted in the embodiment of the application is 0.37 multiplied by 10-16Standard deviation of 0.56X 10-16The error magnitude is not different, the difference of specific errors is small, and even the error of the Markstein algorithm in the embodiment of the application is smaller in the same iteration times.
Again taking a 1.477134351152927 as an example, see a Newton-Raphson algorithm as shown in fig. 3The numerical values after the rounding operation in the process are shown schematically. Wherein, when the Newton-Raphson function iterative algorithm based on the error theory is adopted to calculate 1/1.477134351152927, the rounded correlation value (is
And
)。
and
the expressions of (c) are described with reference to the corresponding formulas in the previous embodiments, respectively. All values are represented in 32-bit binary, the first row giving the name of the value, the second row giving the exponent of the value, and the remaining rows giving the mantissa of the value. Invalid numbers in the mantissa are rounded and labeled 0. Taking column 2 as an example, column 2 gives
32 bit binary representation of a value, where line 2 is-1, representing
And rows 3 to 32 represent
Only 3, 4 rows have numbers, and the remaining 5 to 30 rows are all 0.
Is to x
0The mantissa of the value obtained after the rounding operation only retains two digits.
As can be seen from fig. 3, when the method in the embodiment of the present application is used to calculate 1a, the word length of the value used in each iteration is different. By rounded iteration value
For example, the initial value (x)
0) Has only 2 bits, second step (x)
1) It is 4 bits and is incremented sequentially until the last step, there are 32 bits. Similarly, in operation
And
as well as so. However, in a general iterative algorithm, all iteration steps are calculated by 32 bits, so that compared with the current function iteration calculation method, the division calculation method in the embodiment of the application avoids unnecessary calculation, and greatly improves the calculation efficiency.
The embodiment of the application is based on an error analysis theory, and invalid numbers beyond errors can be rounded off on the premise of keeping the precision in each step of iteration process of an iterative algorithm, so that numerical values of short word length and equal precision are substituted into an iteration format for calculation, the calculation complexity is simplified, particularly the calculation complexity of multiplication in the iteration process is improved, and the calculation efficiency is improved. The method can be applied to any function iteration method with a given error analysis, and the iteration method in the two embodiments is only a part of examples and does not limit the scope of the embodiments of the present application. That is, for any function iteration method capable of providing error analysis, the division operation method in the embodiment of the present application may be used to round the relevant numerical values in the iteration process according to the error and precision requirements, so as to substitute the numerical values with short word length and equal precision into the iteration format for calculation, thereby greatly simplifying the complexity of calculation and improving the calculation efficiency, which is not described in detail in the embodiment of the present application.
The method provided by the embodiment of the application can be used for not only a division calculation part in a microprocessor, but also an algorithm design which needs high precision and adopts software to simulate division operation, can be applied to various application scenes containing iterative algorithms, such as floating point number division operation, greatly simplifies the calculation complexity and the calculation resource waste, and improves the calculation efficiency. The application scenario of the method is not limited in the embodiment of the application.
Based on the description of the division operation method embodiment, the embodiment of the application also discloses a division operation device. Referring to fig. 4, the division operation apparatus 400 includes:
an obtaining module 410, configured to obtain a division parameter to be subjected to division operation, and obtain a first iteration value;
a processing module 420, configured to perform error analysis processing according to the first iteration value, and determine a rounding operation that needs to be performed on the division parameter in the current iteration;
the processing module 420 is further configured to continue iterative processing according to the parameter after the rounding operation to obtain a second iterative value;
the processing module 420 is further configured to, if the second iteration value does not meet the accuracy requirement, repeatedly execute the above steps with the second iteration value as the first iteration value;
an output module 430, configured to output the second iteration value until the second iteration value meets the accuracy requirement.
According to an embodiment of the present application, each step involved in the method of the embodiment shown in fig. 1 may be performed by each module in the division operation apparatus 400 shown in fig. 4, and is not described herein again.
The division operation apparatus 400 in the embodiment of the present application may acquire a division parameter to be divided, acquire a first iteration value, perform error analysis processing according to the first iteration value, determine a rounding operation that needs to be performed on the division parameter in the current iteration, continue iteration processing according to the parameter after the rounding operation, acquire a second iteration value, and if the second iteration value does not satisfy a precision requirement, repeat the above steps with the second iteration value as the first iteration value until the second iteration value satisfies the precision requirement, and output the second iteration value. Based on an error analysis theory, under the premise of ensuring the precision, invalid numbers beyond the error are rounded, so that numerical values of short word length and equal precision are substituted into an iteration rule for calculation, the waste of calculation resources can be greatly reduced, and the operation efficiency of a function iteration algorithm is improved.
Based on the description of the method embodiment and the device embodiment, the embodiment of the application further provides an electronic device. Referring to fig. 5, the electronic device 500 includes at least a processor 501, an input device 502, an output device 503, and a computer storage medium 504. The processor 501, the input device 502, the output device 503, and the computer storage medium 504 in the terminal may be connected by a bus or other means.
A computer storage medium 504 may be stored in the memory of the terminal, the computer storage medium 504 being used for storing a computer program comprising program instructions, and the processor 501 being used for executing the program instructions stored by the computer storage medium 504. The processor 501 (or CPU) is a computing core and a control core of the terminal, and is adapted to implement one or more instructions, and specifically, adapted to load and execute the one or more instructions so as to implement a corresponding method flow or a corresponding function; in one embodiment, the processor 501 described above in the embodiments of the present application may be used to perform a series of processes, including the method in the embodiment shown in fig. 1, and the like.
An embodiment of the present application further provides a computer storage medium (Memory), where the computer storage medium is a Memory device in a terminal and is used to store programs and data. It is understood that the computer storage medium herein may include a built-in storage medium in the terminal, and may also include an extended storage medium supported by the terminal. The computer storage medium provides a storage space that stores an operating system of the terminal. Also stored in this memory space are one or more instructions, which may be one or more computer programs (including program code), suitable for loading and execution by processor 501. The computer storage medium may be a high-speed RAM memory, or may be a non-volatile memory (non-volatile memory), such as at least one disk memory; and optionally at least one computer storage medium located remotely from the processor.
In one embodiment, one or more instructions stored in a computer storage medium may be loaded and executed by processor 501 to perform the corresponding steps in the above embodiments; in particular implementations, one or more instructions in the computer storage medium may be loaded by processor 501 and executed to perform any step of the method in fig. 1, which is not described herein again.
According to the embodiment of the application, the complexity of the function iteration algorithm for processing the division problem, especially the calculation complexity of multiplication in the iteration process, can be simplified, and therefore the calculation efficiency is improved. Compared with a general function iteration algorithm, the method adds a rounding operation step with adaptability and is easy to implement. The division component in the processor 501 and the software modules which need high-precision division operation (exceeding the precision provided by computer hardware) such as computer graphics, computer vision, visualization, geographic information systems, grid generation technology, scientific calculation and the like can have high application value, and are not described herein again.
It can be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described apparatuses and modules may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the several embodiments provided in the present application, it should be understood that the disclosed system, apparatus and method may be implemented in other ways. For example, the division of the module is only one logical division, and other divisions may be possible in actual implementation, for example, a plurality of modules or components may be combined or integrated into another system, or some features may be omitted, or not performed. The shown or discussed mutual coupling, direct coupling or communication connection may be an indirect coupling or communication connection of devices or modules through some interfaces, and may be in an electrical, mechanical or other form.
Modules described as separate parts may or may not be physically separate, and parts displayed as modules may or may not be physical modules, may be located in one place, or may be distributed on a plurality of network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.
In the above embodiments, the implementation may be wholly or partially realized by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. The procedures or functions according to the embodiments of the present application are wholly or partially generated when the computer program instructions are loaded and executed on a computer. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored on or transmitted over a computer-readable storage medium. The computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center by wire (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)), or wirelessly (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device, such as a server, a data center, etc., that includes one or more of the available media. The usable medium may be a read-only memory (ROM), or a Random Access Memory (RAM), or a magnetic medium, such as a floppy disk, a hard disk, a magnetic tape, a magnetic disk, or an optical medium, such as a Digital Versatile Disk (DVD), or a semiconductor medium, such as a Solid State Disk (SSD).