Skip to main content
Entropy logoLink to Entropy
. 2021 Jan 9;23(1):86. doi: 10.3390/e23010086

Improving the Accuracy of the Fast Inverse Square Root by Modifying Newton–Raphson Corrections

Cezary J Walczyk 1, Leonid V Moroz 2, Jan L Cieśliński 1,*
PMCID: PMC7827340  PMID: 33435352

Abstract

Direct computation of functions using low-complexity algorithms can be applied both for hardware constraints and in systems where storage capacity is a challenge for processing a large volume of data. We present improved algorithms for fast calculation of the inverse square root function for single-precision and double-precision floating-point numbers. Higher precision is also discussed. Our approach consists in minimizing maximal errors by finding optimal magic constants and modifying the Newton–Raphson coefficients. The obtained algorithms are much more accurate than the original fast inverse square root algorithm and have similar very low computational costs.

Keywords: approximation of functions, floating-point arithmetic, Newton–Raphson method, inverse square root, magic constant

1. Introduction

Efficient performance of algebraic operations in the framework of floating-point arithmetic is a subject of considerable importance [1,2,3,4,5,6]. Approximations of elementary functions are crucial in scientific computing, computer graphics, signal processing, and other fields of engineering and science [7,8,9,10]. Our aim is to compute elementary functions at a very low computational cost without using memory resources. Direct evaluation of functions could be of interest in any systems where storage capabilities challenge the processing of a large volume of data. This problem is crucial, for instance, in high-energy physics experiments [11,12,13].

In this paper, we consider approximation and fast computation of the inverse square root function, which has numerous applications (see [8,10,14,15,16,17]), especially in 3D computer graphics, where it is needed for normalization of vectors [4,18,19]. The proposed algorithms are aimed primarily at floating-point platforms with limited hardware resources, such as microcontrollers, some field-programmable gate arrays (FPGAs), and graphics processing units (GPUs) that cannot use fast look-up table (LUT)-based hardware instructions, such as SSE (i.e., Streaming SIMD (single instruction, multiple data) Extensions) or Advanced Vector Extensions (AVX). We mean here devices and chips containing floating-point multipliers, adders–subtractors, and fused-multiply adders. Therefore, our algorithms can easily be implemented on such a platform. We also offer them as an alternative to library functions that provide full precision, but are very time consuming. This was the motivation for considering the cases of higher precision in Section 3.2. By selecting the precision and number of iterations, the desired accuracy can be obtained. We propose the use of our codes as direct insertions into more general algorithms without referring to the corresponding library of mathematical functions. In the double-precision mode, most modern processors do not have SSE instructions like rsqrt (such instructions appeared only in AVX-512, which is supported only by the latest processor models). In such cases, one can use our algorithms (with the appropriate number of iterations) as a fast alternative to the library function 1/sqrt(x).

In most cases, the initial seed needed to start the approximation is taken from a memory-consuming look-up table (LUT), although the so-called “bipartite table methods” (actually used on many current processors) make it possible to considerably lower the table sizes [20,21]. The “fast inverse square root” code works in a different way. It produces the initial seed in a cheap and effective way using the so-called magic constant [4,19,22,23,24,25]. We point out that this algorithm is still useful in numerous software applications and hardware implementations (see, e.g., [17,26,27,28,29,30]). Recently, we presented a new approach to the fast inverse square root code InvSqrt, presenting a rigorous derivation of the well-known code [31]. Then, this approach was used to construct a more accurate modification (called InvSqrt1) of the fast inverse square root (see [32]). It will be developed and generalized in the next sections, where we will show how to increase the accuracy of the InvSqrt code without losing its advantages, including the low computational cost. We will construct and test two new algorithms, InvSqrt2 and InvSqrt3.

The main idea of the algorithm InvSqrt consists in interpreting bits of the input floating-point number as an integer [31]. In this paper, we consider positive floating-point normal numbers

x=(1+mx)2ex,mx[0,1),exZ, (1)

and, in Section 3.1, we also consider subnormal numbers. We use the standard IEEE-754, where single-precision floating-point numbers are encoded with 32 bits. For positive numbers, the first bit is zero. The next eight bits encode ex, and the remaining 23 bits represent the mantissa mx. The same 32 bits can be treated as an integer Ix:

Ix=Nm(B+ex+mx), (2)

where Nm=223 and B=127. In this case B+ex is a natural number not exceeding 254. The case of higher precision is analogous (see Section 3.2).

The crucial step of the algorithm InvSqrt consists in shifting all bits to the right by one bit and subtracting the result of this operation from a “magic constant” R (and the optimum value of R has to be guessed or determined). In other words,

Iy0=RIx/2. (3)

Originally, R was proposed as 0x5F3759DF (see [19,23]). Interpreted in terms of floating-point numbers, Iy0 approximates the inverse square root function surprisingly well (y0y=1/x). This trick works because (3) is close to dividing the floating-point exponent by 2. The number R is needed because the floating-point exponents are biased (see (2)).

The magic constant R is usually given as a hexadecimal integer. The same bits encode the floating-point number Rf with an exponent eR and mantissa mR. According to (1), Rf=(1+mR)2eR. In [31], we have shown that if eR=12B1 (e.g., eR=63 in the 32-bit case), then the function (3) (defined on integers) is equivalent to the following piece-wise linear function (when interpreted in terms of corresponding floating-point numbers):

y˜0(x˜,t)=1862x˜+tforx˜[1,2)184+tx˜forx˜[2,t)1168+tx˜forx˜[t,4) (4)

where

t=2+4mR+2μx˜Nm1, (5)

mR is the mantissa of R (i.e., mR:=Nm1RNm1R), and, finally, μx˜=0 or μx˜=1 depending on the parity of the last digit of the mantissa of x˜.

The function μx˜ is two-valued, so a given parameter t may correspond to either two values of R or one value of R (when the term containing μx˜ has no influence on the bits of the mantissa mR). The function y=1/x, the function (3), and all Newton–Raphson corrections considered below are invariant under the scaling x˜=22nx and y˜=2ny for any integer n. Therefore, we can confine ourselves to numbers from the interval [1,4). Here and in the following, the tilde always denotes quantities defined on the interval [1,4).

In this paper, we focus on the Newton–Raphson corrections, which form the second part of the InvSqrt code. Following and developing ideas presented in our recent papers [31,32], we propose modifications of the Newton–Raphson formulas, which result in algorithms that have the same or similar computational cost as/to InvSqrt, but improve the accuracy of the original code, even by several times. The modifications consist in changing both the Newton–Raphson coefficients and the magic constant. Moreover, we extend our approach to subnormal numbers and to higher-precision cases.

2. Modified Newton–Raphson Formulas

The standard Newton–Raphson corrections y˜1 and y˜2 for the zeroth approximation y˜0 given by (4) are given by the following formulas:

y˜1(x˜,t)=32y˜0(x˜,t)12x˜y˜03(x˜,t),y˜2(x˜,t)=32y˜1(x˜,t)12x˜y˜13(x˜,t), (6)

(analogous formulas hold for the next corrections as well; see [31]). The relative error functions δ˜j(x˜,t) (where j=0,1,2,) can be expressed as:

δ˜j(x˜,t)=x˜y˜j(x˜,t)1. (7)

The function δ˜0(x˜,t), which is very important for the further analysis, is thoroughly described and discussed in [31]. Using (7), we substitute y˜j=(1+δ˜j)/x˜ (for j=0,1,2,) into (6), x˜ cancels out, and the formulas (6) assume the following form:

δ˜j=12δ˜j12(3+δ˜j1),(j=1,2,), (8)

where δ˜j=δ˜j(x˜,t). We immediately see that every correction increases the accuracy, even by several orders of magnitude (due to the factor δ˜j12). Thus, a very small number of corrections is sufficient to reach the machine precision (see the end of Section 4).

The above approximations depend on the parameter t (which can be expressed by the magic constant R, see (5)). The best approximation is obtained for t=tk minimizing ||δ˜k(t)||, i.e.,

||δ˜k(tk)||=inft(2,4)||δ˜k(t)||inft(2,4)supx˜[1,4)|δ˜k(x˜,t)|. (9)

In this paper we confine ourselves to the case t=t1 (i.e., we assume t2=t1) because the more general case (where the magic constant is also optimized with respect to the assumed number of iterations) is much more cumbersome, and the related increase in accuracy is negligible. Then, we get

t1(0)3.7298003,R(0)=0x5F375A86, (10)

for details, see [31]. The theoretical relative errors are given by

Δ1max(0)||δ˜1(t1)|1.75118·103,Δ2max(0)||δ˜2(t1)|4.60·106. (11)

The superscript (0) indicates values corresponding to the algorithm InvSqrt (other superscripts will denote modifications of this algorithm).

The idea of increasing the accuracy by a modification of the Newton–Raphson formulas is motivated by the fact that δ˜k(x˜,t)0 for any x˜ (see [31,32]). Therefore, we can try to shift the graph of δ˜1 upwards (making it more symmetric with respect to the horizontal axis). Then, the errors of the first correction are expected to decrease twice and the errors of the second correction are expected to decrease by about eight times (for more details, see [32]). Indeed, according to (8), reducing the first correction by a factor of 2 will reduce the second correction by a factor of 4. The second correction is also non-positive, so we may shift the graph of δ˜2, once more improving the accuracy by the factor of 2. This procedure can be formalized by postulating the following modification of the Newton–Raphson formulas (6):

y˜1=12y˜0(3y˜02x˜)+12d1a1y˜0+b1y˜1,y˜2=12y˜1(3y˜12x˜)+12d2a2y˜1+b2y˜2, (12)

where ak+bk=1 for k=1,2. Thus, we have four independent parameters (d1, d2, a1, and a2) to be determined. In other words,

y˜1=c11y˜0c21x˜y˜03,y˜2=c12y˜1c22x˜y˜13, (13)

where four coefficients cjk can be expressed by the four coefficients ak and dk:

c1k=3+akdk2(1ak)dk,c2k=12(1ak)dk(k=1,2). (14)

We point out that the Newton–Raphson corrections and any of their modifications of the form (13) are obviously invariant with respect to the scaling mentioned at the end of Section 1. Therefore, we can continue to confine our analysis to the interval [1,4).

Below, we present three different algorithms (InvSqrt1, InvSqrt2, InvSqrt3) constructed along the above principles (the last two of them are first introduced in this paper). They will be denoted by superscripts in parentheses, e.g., y˜k(N) means the kth modified Newton–Raphson correction to the algorithm InvSqrt N. We always assume that the zeroth approximation is given by (4), i.e.,

y˜0(N)=y˜0(N=1,2,3), (15)

and relative error functions, Δj(N), are expressed as

Δj(N)(x˜,t)=x˜y˜j(N)(x˜,t)1. (16)

We point out that the coefficients of our algorithms are obtained without taking rounding errors into account. This issue will be shortly discussed at the end of Section 4.

2.1. Algorithm InvSqrt1

Assuming a1=a2=0 and b1=b2=1, we transform (12) into

y˜1(1)=12y˜0(1)3(y˜0(1))2x˜+12d1y˜1(1),y˜2(1)=12y˜1(1)3(y˜1(1))2x˜+12d2y˜2(1). (17)

Therefore, y˜1(1) and y˜2(1) depend on x˜, t, d1, and d2. Parameters t=t1(1) and d1=d1(1) are determined by minimization of ||Δ1(1)(x˜,t)||. Then, the parameter d2=d2(1) is determined by minimization of ||Δ2(1)(x˜,t1(1))|| (for details, see [32]). As a result, we get:

d1(1)1.75118·103,d2(1)1.15234·106, (18)

and t1(1)=t1(0) (see (10)). Therefore, R(1)=R(0), i.e., InvSqrt1 has the same magic constant as InvSqrt. The theoretical relative errors are given by

Δ1max(1)||Δ1(1)(x˜,t1(1))||0.87636·103,Δ2max(1)||Δ2(1)(x˜,t1(1))||5.76·107. (19)

The algorithm (17) can be written in the form (13), where:

c1k(1)=32dk(1),c2k(1)=12dk(1)(k=1,2). (20)

Taking into account numerical values for d1(1) and d2(1), we obtain the following values of the parameters cjk(1):

c11(1)1.5013145387528147176730252470373223,c21(1)0.50043817958427157255767508234577407,c12(1)1.5000008642589575005473878767725752,c22(1)c21(1)·0.99912498383253616899527502360939620. (21)

This large number of digits, which is much higher than that needed for the single-precision computations, will be useful later in the case of higher precision.

Thus, finally, we obtained a new algorithm InvSqrt1 that has the same structure as InvSqrt, but with different values of numerical coefficients (see [32]). In the case of two iterations, the code InvSqrt1 has more algebraic operations (one additional multiplication) in comparison to InvSqrt.

2.2. InvSqrt2 Algorithm

Assuming a1=a2=1 and b1=b2=0, we transform (12) into

y˜1(2)=12y˜0(2)3(y˜0(2))2x˜+12d1y˜0(2),y˜2(2)=12y˜1(2)3(y˜1(2))2x˜+12d2y˜1(2), (22)

where y˜1(2) and y˜2(2) depend on x˜, t, d1, and d2.

Parameters t=t1(2) and d1=d1(2) are determined by the minimization of ||Δ1(2)(x˜,t)||. Then, the parameter d2=d2(2) is determined by the minimization of ||Δ2(2)(x˜,t1(2))|| (see Appendix A.1 for details). As a result, we get:

d1(2)=1.75791023259·103,d2(2)1.159352515·106, (23)

and

t1(2)t(2)3.73157124016,R(2)=1597466888=0x5F376908. (24)

The theoretical relative errors are given by

Δ1max(2)||Δ1(2)(x˜,t1(2))||0.87908·103,Δ2max(2)||Δ2(2)(x˜,t1(2))||5.80·107. (25)

The coefficients in (13) are given by

c1k(2)=3+dk(2)2,c2k(2)=12. (26)

Taking into account the numerical values for d1(2) and d2(2) (see (23)), we obtain the following values of the parameters cjk(2):

c11(2)1.5008789551163345746409291568502392,c12(2)1.5000005796762576644996810350809289,c21(2)=c22(2)=0.5, (27)

where the large number of digits will be useful later in the case of higher precision. Thus, we completed the derivation of the code InvSqrt2:

1.floatInvSqrt2(float x){

2.   float halfx = 0.5f*x;

3.   int i = *(int*) &x;

4.   i = 0x5F376908 - (i>>1);

5.   float y = *(float*) &i;

6.   y* = 1.50087896f - halfx*y*y;

7.   y* = 1.50000057f - halfx*y*y;

8.   return y;

9. }

The code InvSqrt2 contains a new magic constant (R(2)) and has two lines (6 and 7) that were modified in comparison with the code InvSqrt. We point out that InvSqrt2 has the same number of algebraic operations as InvSqrt.

2.3. InvSqrt3 Algorithm

Now, we consider the algorithm (13) in its most general form:

y˜1(3)=k1y˜0(3)k2x˜(y˜0(3))2,y˜2(3)=k3y˜1(3)k4x˜(y˜1(3))2, (28)

where kj, k2, k3, and k4 are constant. In Appendix A.2, we determine parameters t=t1(3), k1, and k2 by minimization of ||Δ1(3)(x˜,t)||. Then, the parameters k3 and k4 are determined by minimization of ||Δ2(3)(x˜,t1(3))||. As a result, we get:

k10.70395201,k22.3892451,k30.50000005,k43.0000004, (29)

and

t1(3)t(3)=3,R(3)=1595932672=0x5F200000. (30)

The theoretical relative errors are given by

Δ1max(3)||Δ1(3)(x˜,t1(3))||0.65007·103,Δ2max(3)||Δ2(3)(x˜,t1(3))||3.17·107. (31)

They are significantly smaller (by 26% and 45%, respectively) than the analogous errors for InvSqrt1 and InvSqrt2 (see (19) and (25)). The comparison of error functions for InvSqrt2 and InvSqrt3 (in the case of one correction) is presented in Figure 1.

Figure 1.

Figure 1

Theoretical relative errors of the first correction for the codes InvSqrt2 and InvSqrt3. The solid line represents the function Δ1(2)(x˜,t(2)), while the dashed line represents Δ1(3)(x˜,t(3)).

The numerical values of coefficients cij(3) (compare with (13)) are given by:

c11(3)=k1k21.68191390868723079,c21(3)=k10.703952009104829370,c12(3)=k3k41.50000036976749938,c22(3)=k30.500000052823927419. (32)

Thus, we obtained the following code, called InvSqrt3:

1.floatInvSqrt3(float x){

2.   int i = *(int*) &x;

3.   i = 0x5F200000 - (i>>1);

4.   float y = *(float*) &i;

5.   y* = 1.68191391f - 0.703952009f*x*y*y;

6.   y* = 1.50000036f - 0.500000053f*x*y*y;

7.   return y;

8. }

The code InvSqrt3 has the same number of multiplications as InvSqrt1, which means that it is slightly more expensive than InvSqrt and InvSqrt2.

3. Generalizations

The codes presented in Section 2 can only be applied to normal numbers (1) of the type float. In this section, we show how to extend these results to subnormal numbers and to higher-precision formats.

3.1. Subnormal Numbers

Subnormal numbers are smaller than any normal number of the form of (1). In the single-precision case, positive subnormals can be represented as mx·2126, where mx(0,1). They can also be characterized by nine first bits equal to zero (which also includes the case where x=0). In order to identify subnormals, we will make a bitwise conjunction (AND) of a given number with the integer 0x7f800000, which has all eight exponent bits equal to 1 and all 23 mantissa bits equal to 0. This bitwise conjunction is zero if and only if the given number is subnormal (including 0).

In the case of the single precision, the multiplication by 224 transforms any subnormal number into a normal number. Therefore, we make this transformation; then, we apply one of our algorithms and, finally, make the inverse transformation (i.e., multiplying the result by 212). Thus, we get an approximated value of the inverse square root of the subnormal number. Note that 224 is the smallest power of 2 with an even exponent that transforms all subnormals into normal numbers.

In the case of InvSqrt3, the procedure described above can be written in the form of the following code.

1.floatInvSqrt3s(float x){

2.   int i = *(int*) &x;

3.   int k = i & 0x7f800000;

4.   if (k==0) {

5.    x = 16777216.f*x; //16777216.f=pow(2.0f, 24)

6.    i = *(int*) &x;

7.   }

8.   i = 0x5F200000 - (i>>1);

9.   float y = *(float*) &i;

10.   y* = 1.68191391f - 0.703952009f*x*y*y;

11.   y* = 1.50000036f - 0.500000053f*x*y*y;

12.   if (k==0) return 4096.f*y; //4096.f=pow(2.0f, 12)

13.   return y;

14. }

The maximum relative errors for this code are presented in Section 4 (see Table 1).

Table 1.

Relative numerical errors for the first and second corrections in the case of the type float (compiler 32-bit) for subnormal numbers.

Algorithm Δ1,Nmin(i) Δ1,Nmax(i) Δ2,Nmin(i) Δ2,Nmax(i)
InvSqrt1 0.87642×103 0.87644×103 0.66221×106 0.63442×106
InvSqrt2 0.87916×103 0.87911×103 0.62060×106 0.65285×106
InvSqrt3 0.65016×103 0.65006×103 0.38701×106 0.35196×106

3.2. Higher Precision

The above analysis was confined to the single-precision floating-point format. This is sufficient for many applications (especially microcontrollers), although the double-precision format is more popular. A trade-off between accuracy, computational cost, and memory usage is welcome [33]. In this subsection, we extend our analysis to double- and higher-precision formats. The calculations are almost the same. We just have to compute all involved constants with an appropriate accuracy. Low-bit arithmetic cases could be treated in exactly the same way. In this paper, however, we are focused on increasing the accuracy and on possible applications in distributed systems, so only the cases of higher precision are explicitly presented.

We present detailed results for double precision and some results (magic constants) for quadruple precision. Performing computations in C, we use the GCC Quad-Precision Math Library (working with numbers of type _float128). The crucial point is to express the magic constant R through the corresponding parameter t, which can be done with the formula:

R=Nm(3B1)/2+Nm(t2)/4μx˜/2 (33)

where μx˜{0,1}, t depends on the considered algorithm and Nm and B depend on the precision format used. Namely,

Singleprecision(32-bit):Nm=223,B=271,Doubleprecision(64-bit):Nm=252,B=2101,Quadrupleprecision(128-bit):Nm=2112,B=2141. (34)

In the case of the zeroth approximation (without Newton–Raphson corrections), the parameter t is given by:

t0=3.7309795598377727818740863479840422, (35)

which can be compared with [31]. The corresponding magic constants computed from the formula (33) read:

32-bit:R(0)=0x5F37642F64-bit:R(0D)=0x5FE6EC85E7DE30DA128-bit:R(0Q)=0x5FFE6EC85E7DE30DAABC602711840B0F. (36)

In this paper, we focus on the case of Newton–Raphson corrections, where the value of the parameter t may depend on the algorithm. For InvSqrt and InvSqrt1, we have:

t1(0)=t1(1)=3.7298003391605705687151317499871860, (37)

(see (Section 2.1); compare with [31,32]). Then, (33) yields the following magic constants:

32-bit:R(1)=0x5F375A8664-bit:R(1D)=0x5FE6EB50C7B537A9128-bit:R(1Q)=0x5FFE6EB50C7B537A9CD9F02E504FCFC0. (38)

Actually, the above value of R in the 64-bit case (i.e., R(1D)) corresponds to μx˜=1 (the same value of R was obtained by Robertson for InvSqrt[24] with a different method). For μx˜=0, we got an R greater by 1 (other results reported in this section do not depend on μx˜). In the 128-bit case, Robertson obtained an R that was 1 less than our value (i.e., R(1Q)).

In the case of InvSqrt2, we have

t(2)=3.7315712401613957182292407381942955 (39)

(compare with (A11)), which yields:

32-bit:R(2)=0x5F37690864-bit:R(2D)=0x5FE6ED2102DCBFDA128-bit:R(2Q)=0x5FFE6ED2102DCBFDA59415059AC483B5. (40)

Finally, for InvSqrt3, we obtained:

t(3)=3 (41)

(see (A29)). The corresponding magic constants are given by:

32-bit:R(3)=0x5F20000064-bit:R(3D)=0x5FE400000000000C128-bit:R(3Q)=0x5FFE4000000000000000000000000000. (42)

The parameters of the modified Newton–Raphson corrections for the higher-precision codes can be computed from the theoretical formulas used in the single-precision cases, taking into account an appropriate number of significant digits. In numerical experiments, we tested the algorithms InvSqrt1D, InvSqrt2D, and InvSqrt3D with the magic constants R(1D), R(2D), and R(3D), respectively, and the following coefficients in the modified Newton–Raphson iterations (compare with (21), (27), and (32), respectively):

c11(1D)=1.50131453875281472,c21(1D)=0.500438179584271573,c12(1D)=1.50000086425895750,c22(1D)=c21(1D)·0.999124983832536169. (43)
c11(2D)=1.50087895511633457,c12(2D)=1.50000057967625766,c21(2D)=c22(2D)=0.5, (44)
c11(3D)=1.68191390868723079,c21(3D)=0.703952009104829370,c12(3D)=1.50000036976749938,c22(3D)=0.500000052823927419. (45)

The algorithm InvSqrt and its improved versions are usually implemented in the single-precision case with no more than two Newton–Raphson corrections. However, in the case of higher precision, higher accuracy of the result is welcome. Then, a higher number of modified Newton–Raphson iterations could be considered. As an example, we present the algorithm InvSqrt2D with four iterations:

1.doubleInvSqrt2D(double x){

2.   double halfx=0.5*x;

3.   long long i=*(long long*) &x;

4.   i=0x5FE6ED2102DCBFDA - (i>>1);

5.   double y =*(double*) &i;

6.   y* = 1.50087895511633457 - halfx*y*y;

7.   y* = 1.50000057967625766 - halfx*y*y;

8.   y* = 1.5000000000002520 - halfx*y*y;

9.   y* = 1.5000000000000000 - halfx*y*y;

10.   return y;

11. }

By removing Line 9, we obtain the code InvSqrt2D with three iterations, and by also removing Line 8, we get the code defined by (44). The maximum relative errors for this code are presented in Section 4 (see (52)).

4. Numerical Experiments

The numerical tests for the codes derived and presented in this paper were performed on an Intel Core i5-3470 processor using the TDM-GCC 4.9.2 32-bit compiler (when repeating these tests on the Intel i7-5700 processor, we obtained the same results, and comparisons with some other processors and compilers are given in Appendix B). In this section, we discuss round-off errors for the algorithms InvSqrt2 and InvSqrt3 (the case of single precision and two Newton–Raphson iterations) and then present the final results of analogous analysis for other codes described in this paper.

Applying algorithms InvSqrt2 and InvSqrt3, we obtain relative errors that differ slightly, due to round-off errors, from their analytical values (see Figure 2 and Figure 3; compare with [32] for an analogous discussion concerning InvSqrt1). Although we present only randomly chosen values in the figures, calculations were done for all float numbers x such that ex[126,128).

Figure 2.

Figure 2

Theoretical and rounding errors of the code InvSqrt2 (with two Newton–Raphson corrections). Left: The solid line represents Δ2(2)(x˜,t(2)), dashed lines correspond to Δ2(2)(x˜,t(2))±22Nm1x˜+ε(2), and dots represent errors for 4000 floating-point numbers x randomly chosen from the interval (2126,2128). Right: relative error ε(2) (see (47)). Dashed lines correspond to the minimum and maximum values of these errors, and dots denote errors for 2000 values x˜ randomly chosen from the interval [1,4).

Figure 3.

Figure 3

Theoretical and rounding errors of the code InvSqrt3 (with two Newton–Raphson corrections). Left: The solid line represents Δ2(3)(x˜,t(3)), dashed lines correspond to Δ2(3)(x˜,t(3))±22Nm1x˜+ε(3), and dots represent errors for 4000 floating-point numbers x randomly chosen from the interval (2126,2128). Right: relative error ε(3). Dashed lines correspond to minimum and maximum values of these errors, and dots denote errors for 2000 values x˜ randomly chosen from the interval [1,4).

The errors of numerical values returned by InvSqrt2

Δ2;N(2)(x)=sqrt(x)InvSqrt2(x)1 (46)

belong (for ex126) to the interval (6.21·107,6.53·107). For ex=126, we get a wider interval: [6.46·107,6.84·107]. These errors differ from the errors of y˜2(3)(x˜,t(2)), which were determined analytically (compare (25)). We define:

ε(2)(x˜)=InvSqrt2(x)y˜2(2)(x˜,t(2))y˜2(2)(x˜,t(2)). (47)

This function, representing the observed blur of the float approximation of the InvSqrt2 output, is symmetric with respect to its mean value

ε(2)=21Nm1x[1,4)ε(2)(x˜)=1.636·108 (48)

(see the right part of Figure 2), and covers the following range of values:

ε(2)(x˜)[4.333·108,7.596·108]. (49)

Analogous results for the code InvSqrt3 read:

ε(3)=21Nm1x[1,4)ε(3)(x˜)=1.890·108 (50)
ε(3)(x˜)[7.850·108,4.067·108]. (51)

The results produced by the same hardware with a 64-bit compiler have a greater amplitude of the error oscillations as compared with the 32-bit case (also compare Appendix B).

The maximum errors for the code InvSqrt and all codes presented in the previous sections are given in Table 2 (for codes with just one Newton–Raphson iteration) and Table 3 (the same codes but with two iterations).

Table 2.

Relative numerical errors for the first correction in the case of type float (compiler 32-bit). In the case of type double, the errors are equal to theoretical errors ±Δ1max(i) up to the accuracy given in the table.

Algorithm i Δ1max(i) Δ1,Nmin(i) Δ1,Nmax(i) Δ1,N(i)
InvSqrt 0 1.75118×103 1.75124×103 0.00008×103 1.75124×103
InvSqrt1 1 0.87636×103 0.87642×103 0.87645×103 0.87645×103
InvSqrt2 2 0.87908×103 0.87916×103 0.87914×103 0.87916×103
InvSqrt3 3 0.65007×103 0.65017×103 0.65006·103 0.65017×103

Table 3.

Relative numerical errors for the second correction in the case of type float (compiler 32-bit). In the case of type double, the errors are equal to theoretical errors ±Δ2max(i) up to the accuracy given in the table.

Algorithm i Δ2max(i) Δ2,Nmin(i) Δ2,Nmax(i) Δ2,N(i)
InvSqrt 0 4.59728×106 4.65441×106 0.08336×106 4.65441×106
InvSqrt1 1 0.57617×106 0.67207×106 0.64871×106 0.67207×106
InvSqrt2 2 0.57968×106 0.64591×106 0.68363×106 0.68363×106
InvSqrt3 3 0.31694×106 0.38701×106 0.35198×106 0.38701×106

Looking at the last column of Table 2 (this is the case of one iteration), we see that the code InvSqrt1 is slightly more accurate than InvSqrt2, and both are roughly almost two times more accurate than InvSqrt. However, it is the code InvSqrt3 that has the best accuracy. The computational costs of all these codes are practically the same (four multiplications in every case).

In the case of two iterations (Table 3), the code InvSqrt3 is the most accurate as well. Compared with InvSqrt, its accuracy is 12 times higher for single precision and 14.5 times higher for double precision. However, the computational costs of InvSqrt1 and InvSqrt3 (eight multiplications) are higher than the cost of InvSqrt (seven multiplications). Therefore, the code InvSqrt2 has some advantage, as it is less accurate than InvSqrt3 but cheaper. In the single-precision case the code InvSqrt2 is 6.8 times more accurate than InvSqrt.

We point out that the round-off errors in the single-precision case significantly decrease the gain of the accuracy of the new algorithms as compared with the theoretical values, especially in the case of two Newton–Raphson corrections (compare the third and the last column of Table 3).

The range of errors in the case of subnormal numbers (using the codes described in Section 3.1) is shown in Table 1. One can easily see that the relative errors are similar—in fact, even slightly lower—than in the case of normal numbers.

Although the original InvSqrt code used only one Newton–Raphson iteration, and in this paper, we focus mostly on two iterations, it is worthwhile to also briefly consider the case of more iterations. Then, the increased computational cost is accompanied by increased accuracy. We confine ourselves to the code InvSqrt2 (see the end of Section 3.2), which is less expensive than InvSqrt3 (and the advantage of InvSqrt2 increases with the number of iterations). In the double-precision case, the maximum error for three Newton–Raphson corrections is much lower, and the fourth correction yields the best possible accuracy.

Δ1D,N(2)=0.87908×103,Δ2D,N(2)=0.57968×106,Δ3D,N(2)=2.5213×1013,Δ4D,N(2)=1.1103×1016. (52)

In the case of single precision, we already get the best possible accuracy for the third correction, given by adding the line y* = 1.5f - halfx*y*y as Line 8 in the code InvSqrt2 (see Section 2.2).

Δ1,N(2)=0.87916×103,Δ2,N(2)=0.68363×106,Δ3,N(2)=0.89367×107 (53)

The derivation of all numerical codes presented in this paper did not take rounding errors into account. Therefore, the best floating-point parameters can be slightly different from the rounding of the best real parameters, all the more so since the distribution of the errors is still not exactly symmetric (compare fourth and fifth columns in Table 2 and Table 3). The full analysis of this problem is much more difficult than the analogous analysis for the original InvSqrt code because we now have several parameters to be optimized instead of a single magic constant. At the same time, the increase in accuracy is negligible. Actually, much greater differences in the accuracy appear in numerical experiments as a result of using different devices (see Appendix B).

As an example, we present the results of an experimental search in the case of the code InvSqrt3 with one Newton–Raphson correction (three parameters to be optimized). The modified Newton–Raphson coefficients are found to be

c11num(3)=1.681911588f,c21num(3)=k1=0.7039490938f. (54)

Figure 4 summarizes the last step of this analysis. The dependence of maximum errors on R shows clearly that the optimum value for the magic constant is slightly shifted as compared to the theoretical (real) value:

Rnum(3)=17+0x5f200000=0x5f200011. (55)

Figure 4.

Figure 4

Maximum relative errors for the first Newton–Raphson correction in the code InvSqrt3 as a function of R in the case of k1=0.7039490938f and k1k2=1.681911588f. Circles denote maximum errors (Δ1,Nmax(3)), while squares denote minimum errors (|Δ1,Nmin(3)|). The maximum error (shown by the dashed line) was determined by minimizing the maximum error for all floating-point numbers from [1,4).

The corresponding errors given by

Δ1,Nmax(3)=6.50112284·104,Δ1,Nmin(3)=6.501092575·104 (56)

are nearly symmetric. They are smaller than the maximum error Δ1,N(3) corresponding to our theoretical values, but only by about 0.001% (see Table 2).

5. Conclusions

We presented two new modifications (InvSqrt2 and InvSqrt3) of the fast inverse square root code in single-, double-, and higher-precision versions. Each code has its own magic constant. All new algorithms are much more accurate than the original code InvSqrt. One of the new algorithms, InvSqrt2, has the same computational cost as InvSqrt in the case of any precision. Another code, InvSqrt3, has the best accuracy, but is more expensive if the number of Newton–Raphson corrections is greater than 1. However, its gain in accuracy is very high, even by more than 12 times for two iterations (see Table 3 in Section 4).

Our approach was to modify the Newton–Raphson method by introducing arbitrary parameters, which are then determined by minimizing the maximum relative error. It is expected that such modifications will provide a significant increase in accuracy, especially in the case of asymmetric error distribution for Newton–Raphson corrections (and this is the case with the inverse square root function when these corrections are non-positive). One has to remember that due to rounding errors, our theoretical results may differ from the best floating-point parameters, but the difference is negligible (see the end of Section 4). In fact, parameters (magic constants and modified Newton–Raphson coefficients) from a certain range near the values obtained in this article seem equally good for all practical purposes.

Concerning potential applications, we have to acknowledge that for general-purpose computing, the SSE and AVX reciprocal square root instructions are faster and more accurate. We hope, however, that the proposed algorithms can be applied in embedded systems and microcontrollers without a hardware floating-point divider, and potentially in FPGAs. Moreover, in contrast to the SSE and AVX instructions, our approach can be easily extended to computational platforms of high precision, like 256-bit or 512-bit platforms.

Appendix A. Analytical Derivation of Modified Newton–Raphson Coefficients

Appendix A.1. Algorithm InvSqrt2

We will determine the parameters d1 and d2 in formulas (22) that minimize the maximum error. Substituting (16) (with n=2) into (22), we get:

Δ1(2)(x˜,t,d1)=12d11+δ˜0(x˜,t)12δ˜02(x˜,t)3+δ˜0(x˜,t) (A1)
Δ2(2)(x˜,t,d1,d2)=12d21+Δ1(2)12Δ1(2)23+Δ1(2), (A2)

where Δ1(2)Δ1(2)(x˜,t,d1) and δ˜0(x˜,t) is the relative error of the zeroth approximation (the function δ˜0(x˜,t) is presented and discussed in [31,32]).

First, we are going to determine the t and d1(2) that minimize the maximum absolute value of the relative error of the first correction. We have to solve the following equation:

0=Δ1(2)(x˜,t)δ˜0(x˜,t)=12d1(2)3δ˜0(x˜,t)32δ˜02(x˜,t). (A3)

Its solution

δ˜+=1+d1(2)/31 (A4)

corresponds to the value

Δ1max(2)=12d1(2)(1+δ˜+)12δ˜+2(3+δ˜+), (A5)

which is a maximum of Δ1(2)(x˜,t) because its second derivative with respect to x˜, i.e.,

x˜2Δ1(2)(x˜,t)=x˜2δ˜0(x˜,t)δ˜0Δ1(2)(x˜,t)3(1+δ˜0(x˜,t))(xδ˜0(x˜,t))2, (A6)

is negative. In order to determine the dependence of d1(2) on the parameter t, we solve the equation

Δ1(2)(t,t)=Δ1max(2), (A7)

which (for some t=t1(2)) equates the maximum value of error with the modulus of the minimum value of error. Thus, we obtain the following relations:

δ+=114t+18tf(t)+12f(t), (A8)
d1(2)=3+916t+364t2f2(t)316t3/2f1(t)34tf(t)+34f2(t), (A9)

where

f(t)=8+t3/2/8+44+t3/2/81/3.

The last step consists in equating the minimum boundary value of the error of analyzed correction with its smallest local minimum:

Δ1(2)(t,t)=12d1(2)(1+δ˜0(x˜0II,t))12δ˜02(x˜0II,t)(3+δ˜0(x˜0II,t)), (A10)

where x0II=(4+t)/3 (see [31]). Solving the Equation (A10) numerically, we obtain the following value of t:

t1(2)3.73157124016, (A11)

which corresponds to the following magic constant:

R(2)=1597466888=0x5F376908. (A12)

Taking into account (A8), we compute

d1(2)=1.75791023259·103, (A13)

and, using (A4) and (A5), we get

Δ1max(2)8.7908386407·104δ˜1max1.99. (A14)

In the case of the second correction, we keep the obtained value t=t1(2) and determine the parameter d2(2), which equates the maximum value of the error with the modulus of its global minimum. Δ2(2)(x˜,t1(2)) is increasing (decreasing) with respect to negative (positive) Δ1(2)(x˜,t1(2)) and has local minima that come only from positive maxima and negative minima. Therefore, the global minimum should correspond to the global minimum Δ1max(2) or to the global maximum Δ1max(2). Substituting these values into Equation (A2) in the place of Δ1(2)(x˜,t1(2)), we obtain that deeper minima of (Δ2max(2)) come from the global minimum of the first correction:

Δ2max(2)=12d2(2)(1Δ1max(2))12Δ1max(2)2(3Δ1max(2)), (A15)

and the maximum, by analogy to the first correction, corresponds to the following value of Δ1(2)(x˜,t1(2)):

Δ+=1+d2(2)/31. (A16)

Solving the equation

Δ2max(2)=12d2(2)(1+Δ+)12Δ+2(3+Δ+), (A17)

we get

d2(2)1.159352515·106andΔ2max(2)5.796763137·107δ˜2max7.93. (A18)

Appendix A.2. Algorithm InvSqrt3

Parameters k1,k2,k3, and k4 in the formula (28) will be determined by minimization of the maximum error. The relative error functions for (28) are given by:

Δj(3)=x˜y˜j(3)1, (A19)

where j=1,2. Substituting (A19) into (28), we obtain:

Δ1(3)(x˜,t,k1,k2)=k1k2(δ˜0(x˜,t)+1)k1(δ˜0(x˜,t)+1)31,Δ2(3)(x˜,t,k)=k3k4(Δ1(3)(x˜,t,k1,k2)+1)k3(Δ1(3)(x˜,t,k1,k2)+1)31, (A20)

where k=(k1,k2,k3,k4) and δ˜0(x˜,t) is the relative error of the zeroth approximation (see [31,32]).

We are going to find parameters t and k such that the error functions take extreme values. We begin with Δ1(3).

x˜Δ1(3)(x˜,t,k1,k2)=k1k23k1(δ˜0(x˜,t)+1)2x˜δ˜0(x˜,t). (A21)

Therefore, the local extremes of Δ1(3) can be located either at the same points as the extremes of δ˜0(x˜,t) or at the x˜ satisfying the equation:

δ˜0(x˜,t)=δ1(e) (A22)

where

δ1(e)=k2/31. (A23)

The extremes corresponding to δ1(e) are global maxima equal to

Δ1max(3)=k1k2(δ1(e)+1)k1(δ1(e)+1)31=2k1k233/21. (A24)

The two extremes of δ˜0(x˜,t), located at x˜0I=(6+t)/6 and x˜0II=(4+t)/3 (see [31]), can correspond either to minima or to maxima of Δ1(3) (depending on parameters t, k1, and k2). If δ˜0(x˜0I/II,t)<δ1(e), we have a maximum. The case δ˜0(x˜0I/II,t)>δ1(e) corresponds to a minimum.

Global extremes of Δ1(3) can be either local extremes or boundary values (which, in turn, correspond to global extremes of δ˜0(x˜,t)). We recall that the global minimum of δ˜0(x˜,t) is at x˜=t and the global maximum is at x˜0I or x˜0II [31]. Therefore, in order to find the parameters k1 and k2 that minimize the maximal value of |Δ1(3)|, we have to solve two equations:

Δ1max(3)+Δ1(3)(t,t,k1,k2)=0, (A25)
Δ1(3)(x˜0N,t,k1,k2)=Δ1(3)(t,t,k1,k2),[2ex] (A26)

where N=I for t(2,25/3+24/32) and N=II for t(25/3+24/32,4). Note that δ˜(x˜0N,t)=max{δ˜(x˜0I,t),δ˜(x˜0II,t)} and Δ1(3)(x˜0N,t,k1,k2) is a minimum of Δ1(3).

The solution of the system (A25) and (A26) corresponds to the case N=I and is given by:

k1=22·33/2k23/2+t1/2k2/2t3/2/81k2=(1+t/6)3+t(1+t/6)3/2+t/4. (A27)

Thus, Δ1max(3), given by (A24), is a function of one variable t, and we can easily find its minimum value. It is enough to compute

dΔ1max(3)dtk2323k2dk1dt+k1dk2dt=0. (A28)

We obtain t=t1(3), where

t1(3)=3,R(3)=1595932672=0x5F200000, (A29)

and, inserting t=t1(3) into (A24) and (A27):

Δ1max(3)=543366+2(17+62)3/2543+366+2(17+62)3/26.5007·104, (A30)
k1=256543+366+1217+62+1734+1220.7039520,k2=51+182322.3892451. (A31)

In order to find the parameters k3 and k4 that minimize the maximal relative error of the second correction, we fix t=t1(3). Then, we have to solve the following Equations (obtained in the same way as Equations (A25) and (A26)):

Δ2(3)(t,t,k1,k2,k3,k4)=k3k4(Δ1max(3)+1)k3(Δ1max(3)+1)31,Δ2(3)(t,t,k1,k2,k3,k4)=k3k4(δ2(e)+1)+k3(δ2(e)+1)3+1, (A32)

where

δ2(e)=k4/31 (A33)

corresponds to Δ1(3)(x˜,t,k1,k2) satisfying:

0=Δ1(3)(x˜,t,k1,k2)Δ2(3)(x˜,t,k1,k2,k3,k4)=k3k43k3(Δ1(3)(x˜,t,k1,k2)+1)2.

Solving the system (A32), we get:

k4=3+(Δ1max(3))2,k3=22Δ1max(3)+δ2(e)2δ2(e)(1+Δ1max(3)+δ2(e))+Δ1max(3)1,Δ2max(3)=k3k4(δ2(e)+1)k3(δ2(e)+1)31. (A34)

Then, using (A30) and (A33), we get numerical values:

k30.50000005,k43.0000004,Δ2max(3)3.16943579·107. (A35)

One can easily see that the obtained error Δ2max(3) is only about half (55%) of the error Δ2max(2).

Appendix B. Numerical Experiments Using Different Processors and Compilers

The accuracy of our codes depends, to some extent, on the devices used for testing. In Section 4, we limited ourselves to the Intel Core i5 with the 32-bit compiler. In this Appendix, we present, for comparison, data from other devices (Table A1 and Table A2). All data are for the type float (single precision).

The first two columns with data correspond to the Intel Core i5 with the 32-bit compiler (described, in more detail, in Section 4), the next two columns correspond to the same processor, but with the 64-bit compiler. Then, we have results (the same) for three microcontrollers: STM32L432KC and TM4C123GH6PM (ARM Cortex-M4), as well as STM32F767ZIT6 (ARM Cortex-M7). The last two columns contain results for the ESP32-D0WDQ5 system with two Xtensa LX6 microprocessors.

Table A1.

The range of numerical errors for the first correction depending on the CPU used.

Code Intel Core i5 (32-bit) Intel Core i5 (64-bit) ARM Cortex M4-7 ESP32
103Δmin 103Δmax 103Δmin 103Δmax 103Δmin 103Δmax 103Δmin 103Δmax
InvSqrt1 0.87642 0.87644 0.87646 0.87654 0.87649 0.87656 0.87646 0.87652
InvSqrt2 0.87916 0.87911 0.87922 0.87924 0.87923 0.87927 0.87921 0.87922
InvSqrt3 0.65017 0.65006 0.65029 0.65017 0.65028 0.65018 0.65025 0.65014

Table A2.

The range of numerical errors for the second correction depending on the processor used.

Code Intel Core i5 (32-bit) Intel Core i5 (64-bit) ARM Cortex M4-7 ESP32
106Δmin 106Δmax 106Δmin 106Δmax 106Δmin 106Δmax 106Δmin 106Δmax
InvSqrt1 0.66221 0.63504 0.75813 0.78832 0.80341 0.81933 0.75548 0.77074
InvSqrt2 0.62060 0.65287 0.70266 0.77609 0.74198 0.81605 0.69991 0.76667
InvSqrt3 0.38701 0.35198 0.48605 0.45363 0.51755 0.48057 0.47314 0.44122

Author Contributions

Conceptualization, L.V.M.; Formal analysis, C.J.W.; Investigation, C.J.W., L.V.M., and J.L.C.; Methodology, C.J.W. and L.V.M.; Visualization, C.J.W.; Writing—original draft, J.L.C.; Writing—review and editing, J.L.C. All authors have read and agreed to the published version of the manuscript.

Funding

This research received no external funding.

Data Availability Statement

Data is contained within the article.

Conflicts of Interest

The authors declare no conflict of interest.

Footnotes

Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations.

References

  • 1.Ercegovac M.D., Lang T. Digital Arithmetic. Morgan Kaufmann; San Francisco, CA, USA: 2003. [Google Scholar]
  • 2.Parhami B. Computer Arithmetic: Algorithms and Hardware Designs. 2nd ed. Oxford University Press; New York, NY, USA: 2010. [Google Scholar]
  • 3.Muller J.-M., Brunie N., Dinechin F., Jeannerod C.-P., Joldes M., Lefèvre V., Melquiond G., Revol N., Torres S. Handbook of Floating-Point Arithmetic. 2nd ed. Birkhäuser; Basel, Switzerland: 2018. [Google Scholar]
  • 4.Eberly D.H. GPGPU Programming for Games and Science. CRC Press; Boca Raton, FL, USA: 2015. [Google Scholar]
  • 5.Beebe N.H.F. The Mathematical-Function Computation Handbook: Programming Using the MathCW Portable Software Library. Springer; Berlin/Heidelberg, Germany: 2017. [Google Scholar]
  • 6.Blanchard P., Higham N.J., Mary T. A class of fast and accurate summation algorithms. SIAM J. Sci. Comput. 2020;42:A1541–A1557. doi: 10.1137/19M1257780. [DOI] [Google Scholar]
  • 7.Moroz L., Samotyy W. Efficient floating-point division for digital signal processing application. IEEE Signal Process. Mag. 2019;36:159–163. doi: 10.1109/MSP.2018.2875977. [DOI] [Google Scholar]
  • 8.Liu W., Nannarelli A. Power Efficient Division and Square root Unit. IEEE Trans. Comp. 2012;61:1059–1070. doi: 10.1109/TC.2012.82. [DOI] [Google Scholar]
  • 9.Viitanen T., Jääskeläinen P., Esko O., Takala J. Simplified floating-point division and square root; Proceedings of the IEEE International Conference Acoustics Speech and Signal Process; Vancouver, BC, Canada. 26–31 May 2013; pp. 2707–2711. [Google Scholar]
  • 10.Cornea M. Intel® AVX-512 Instructions and Their Use in the Implementation of Math Functions. Intel Corporation; Santa Clara, CA, USA: 2015. [Google Scholar]
  • 11.Ivanchenko V.N., Apostolakis J., Bagulya A., Bogdanov A., Grichine V., Incerti S., Ivantchenko A., Maire M., Pandola L., Pokorski W., et al. Geant4 Electromagnetic Physics for LHC Upgrade. J. Phys. Conf. Seriies. 2014;513:022015. doi: 10.1088/1742-6596/513/2/022015. [DOI] [Google Scholar]
  • 12.Piparo D., Innocente V., Hauth T. Speeding up HEP experiment software with a library of fast and auto-vectorisable mathematical functions. J. Phys. Conf. Seriies. 2014;513:052027. doi: 10.1088/1742-6596/513/5/052027. [DOI] [Google Scholar]
  • 13.Faerber C. Acceleration of Cherenkov angle reconstruction with the new Intel Xeon/FPGA compute platform for the particle identification in the LHCb Upgrade. J. Phys. Conf. Seriies. 2017;898:032044. doi: 10.1088/1742-6596/898/3/032044. [DOI] [Google Scholar]
  • 14.Ercegovac M.D., Lang T. Division and Square Root: Digit Recurrence Algorithms and Implementations. Kluwer Academic Publishers; Boston, MA, USA: 1994. [Google Scholar]
  • 15.Kwon T.J., Draper J. Floating-point Division and Square root Implementation using a Taylor-Series Expansion Algorithm with Reduced Look-Up Table; Proceedings of the 51st Midwest Symposium on Circuits and Systems; Knoxville, TN, USA. 10–13 August 2008. [Google Scholar]
  • 16.Aguilera-Galicia C.R. Ph.D. Thesis. ITESO; Tlaquepaque, Jalisco, Mexico: 2019. Design and Implementation of Reciprocal Square Root Units on Digital ASIC Technology for Low Power Embedded Applications. [Google Scholar]
  • 17.Lemaitre F. Ph.D. Thesis. Paris University IV (Sorbonne); Paris, France: 2019. Tracking Haute Frequence Pour Architectures SIMD: Optimization de la Reconstruction LHCb. (CERN-THESIS-2019-014) [Google Scholar]
  • 18.Oberman S., Favor G., Weber F. AMD 3DNow! technology: Architecture and implementations. IEEE Micro. 1999;19:37–48. doi: 10.1109/40.755466. [DOI] [Google Scholar]
  • 19.id software, quake3-1.32b/code/game/q_math.c, Quake III Arena. [(accessed on 8 January 2021)];1999 Available online: https://github.com/id-Software/Quake-III-Arena/blob/master/code/game/q_math.c.
  • 20.Sarma D.D., Matula D.W. Faithful bipartite ROM reciprocal tables; Proceedings of the 12th IEEE Symposium on Computer Arithmetic; Bath, UK. 19–21 July 1995; Jul 19–21, pp. 17–29. [Google Scholar]
  • 21.Stine J.E., Schulte M.J. The symmetric table addition method for accurate function approximation. J. VLSI Signal Process. 1999;11:1–12. [Google Scholar]
  • 22.Blinn J. Floating-point tricks. IEEE Comput. Graph. Appl. 1997;17:80–84. doi: 10.1109/38.595279. [DOI] [Google Scholar]
  • 23.Lomont C. Fast Inverse Square Root, Purdue University, Technical Report. [(accessed on 8 January 2021)];2003 Available online: http://www.lomont.org/papers/2003/InvSqrt.pdf.
  • 24.Robertson M. Bachelor’s Thesis. University of New Brunswick; Fredericton, NB, Canada: 2012. A Brief History of InvSqrt. [Google Scholar]
  • 25.Warren H.S. Hacker’s Delight. 2nd ed. Pearson Education; Upper Saddle River, NJ, USA: 2013. [Google Scholar]
  • 26.Hänninen T., Janhunen J., Juntti M. Novel detector implementations for 3G LTE downlink and uplink. Analog. Integr. Circ. Sig. Process. 2014;78:645–655. doi: 10.1007/s10470-013-0128-5. [DOI] [Google Scholar]
  • 27.Hsu C.J., Chen J.L., Chen L.G. An Efficient Hardware Implementation of HON4D Feature Extraction for Real-time Action Recognition; Proceedings of the 2015 IEEE International Symposium on Consumer Electronics (ISCE); Madrid, Spain. 17 June 2015. [Google Scholar]
  • 28.Hsieh C.H., Chiu Y.F., Shen Y.H., Chu T.S., Huang Y.H. A UWB Radar Signal Processing Platform for Real-Time Human Respiratory Feature Extraction Based on Four-Segment Linear Waveform Model. IEEE Trans. Biomed. Circ. Syst. 2016;10:219–230. doi: 10.1109/TBCAS.2014.2376956. [DOI] [PubMed] [Google Scholar]
  • 29.Sangeetha D., Deepa P. 2017 30th International Conference on VLSI Design and 2017 16th International Conference on Embedded Systems. IEEE; Piscataway, NJ, USA: 2016. Efficient Scale Invariant Human Detection using Histogram of Oriented Gradients for IoT Services; pp. 61–66. [Google Scholar]
  • 30.Hasnat A., Bhattacharyya T., Dey A., Halder S., Bhattacharjee D. A fast FPGA based architecture for computation of square root and Inverse Square Root; Proceedings of the 2nd International Conference on Devices for Integrated Circuit, DevIC 2017; Kalyani, Nadia, India. 23–24 March 2017; pp. 383–387. [Google Scholar]
  • 31.Moroz L., Walczyk C.J., Hrynchyshyn A., Holimath V., Cieśliński J.L. Fast calculation of inverse square root with the use of magic constant – analytical approach. Appl. Math. Comput. 2018;316:245–255. doi: 10.1016/j.amc.2017.08.025. [DOI] [Google Scholar]
  • 32.Walczyk C.J., Moroz L.V., Cieśliński J.L. A Modification of the Fast Inverse Square Root Algorithm. Computation. 2019;7:41. doi: 10.3390/computation7030041. [DOI] [Google Scholar]
  • 33.Graillat S., Jézéquel F., Picot R., Févotte F., Lathuilière B. Auto-tuning for floating-point precision with Discrete Stochastic Arithmetic. J. Comput. Sci. 2019;36:101017. doi: 10.1016/j.jocs.2019.07.004. [DOI] [Google Scholar]

Associated Data

This section collects any data citations, data availability statements, or supplementary materials included in this article.

Data Availability Statement

Data is contained within the article.


Articles from Entropy are provided here courtesy of Multidisciplinary Digital Publishing Institute (MDPI)

RESOURCES