Re: Division routine help sought!
Posted: Sun Apr 26, 2020 4:32 pm
RichTW:
I have implemented the Goldschmidt Square Root Algorithm for fixed-point numbers, and it works just fine. In addition, a side benefit of the Goldschmidt Square Root Algorithm is that it simultaneously calculates the reciprocal of the square root: 1/sqrt(x). That is really the value that I was wanting because I needed that term in order to solve the Law of Cosines. Squaring the reciprocal of the square root enables division by multiplication of the reciprocal of the divisor.
I have a paper describing the algorithms and how to estimate the initial value of the reciprocal of the square root. It is based on an estimate derived for how the initial value for the floating point algorithm can be derived from the exponent of the floating point value. My initial estimate is based on the most significant bit of the fixed-point value for which I want to calculate the reciprocal of the square root. In my application, I only have to calculate the Law of Cosines twice in each control loop cycle. Therefore, I only looked for an initial value that would limit the number of iterations equally for the ranges in which I binned the input data. I also wanted the accuracy to be about the same for each of these bins, so I biased my estimate to accomplish this.
I'll have to sanitized the paper somewhat to remove some stuff that is not suitable for public disclosure. If the preceding is insufficient to get you started, send me a PM and I'll undertake to sanitize the paper over the next few days.
Added link to article on fixed-point Goldschmidt Square Root Algorithm.
RichTW wrote:
Thanks for links Ed! Will try digesting that with a coffee! A skim read suggests that Goldschmidt division works with reals rather than integers, but I haven't really taken it in properly.
I have a paper describing the algorithms and how to estimate the initial value of the reciprocal of the square root. It is based on an estimate derived for how the initial value for the floating point algorithm can be derived from the exponent of the floating point value. My initial estimate is based on the most significant bit of the fixed-point value for which I want to calculate the reciprocal of the square root. In my application, I only have to calculate the Law of Cosines twice in each control loop cycle. Therefore, I only looked for an initial value that would limit the number of iterations equally for the ranges in which I binned the input data. I also wanted the accuracy to be about the same for each of these bins, so I biased my estimate to accomplish this.
I'll have to sanitized the paper somewhat to remove some stuff that is not suitable for public disclosure. If the preceding is insufficient to get you started, send me a PM and I'll undertake to sanitize the paper over the next few days.
Added link to article on fixed-point Goldschmidt Square Root Algorithm.