Skip to main content
QUICK REVIEW

[Paper Review] Improving the accuracy of the fast inverse square root algorithm

Cezary J. Walczyk, Leonid Moroz|arXiv (Cornell University)|Feb 17, 2018
Numerical Methods and AlgorithmsComputer Science14 references4 citations
TL;DR

This paper proposes two improved variants of the fast inverse square root algorithm for single-precision IEEE 754 floating-point numbers. By modifying the Newton-Raphson iteration coefficients and optimizing the magic constant, the new algorithms achieve significantly higher accuracy—up to 7 times more accurate than the original InvSqrt—while maintaining nearly identical computational cost, making them suitable for embedded systems and FPGAs without floating-point units.

ABSTRACT

We present improved algorithms for fast calculation of the inverse square root for single-precision floating-point numbers. The algorithms are much more accurate than the famous fast inverse square root algorithm and have the same or similar computational cost. The main idea of our work consists in modifying the Newton-Raphson method and demanding that the maximal error is as small as possible. Such modification is possible when the distribution of Newton-Raphson corrections is not symmetric (e.g., if they are non-positive functions).

Motivation & Objective

  • To develop more accurate variants of the fast inverse square root algorithm with minimal computational overhead.
  • To reduce the maximum relative error in inverse square root approximation without increasing the number of multiplications.
  • To optimize the magic constant and Newton-Raphson correction coefficients for improved error distribution and symmetry.
  • To evaluate the impact of floating-point precision and round-off errors on algorithm accuracy in practical implementations.
  • To provide analytically derived, numerically stable alternatives to the original InvSqrt for use in systems lacking hardware FPU support.

Proposed method

  • Modifies the Newton-Raphson iteration formula by introducing adjusted coefficients to improve convergence and reduce error amplitude.
  • Introduces a new magic constant R that minimizes the maximum relative error in the initial approximation step.
  • Uses analytical modeling of the inverse square root function over the interval [1, 4) to derive piecewise linear approximations of the initial estimate.
  • Applies a scaling invariance property to simplify analysis and ensure algorithmic invariance under x → 2⁻²ⁿx and yₖ → 2ⁿyₖ transformations.
  • Employs numerical simulations with 32-bit and 64-bit precision to compare error bounds and assess the impact of floating-point rounding.
  • Proposes two variants: InvSqrt1 (slightly higher cost, better theoretical accuracy) and InvSqrt2 (same cost as original, near-identical accuracy with improved error distribution).

Experimental results

Research questions

  • RQ1Can the Newton-Raphson correction step be modified to reduce maximum relative error while preserving computational efficiency?
  • RQ2What is the optimal magic constant R that minimizes the worst-case error in the initial approximation of the inverse square root?
  • RQ3How do round-off errors in single-precision arithmetic affect the theoretical accuracy gains of modified algorithms?
  • RQ4To what extent can the accuracy of the fast inverse square root be improved without increasing the number of multiplications?
  • RQ5How do the error distributions of the new algorithms compare to the original InvSqrt in practical floating-point implementations?

Key findings

  • The InvSqrt1 variant achieves approximately 2 times better accuracy than the original InvSqrt after one Newton-Raphson iteration.
  • After two iterations, InvSqrt1 improves accuracy by a factor of about 7 compared to the original InvSqrt, with a maximum relative error of ±6.53×10⁻⁷.
  • The InvSqrt2 variant matches the computational cost of the original InvSqrt but achieves a maximum relative error of ±6.53×10⁻⁷, comparable to InvSqrt1, despite slightly higher round-off error in numerical tests.
  • The theoretical error bound for InvSqrt1 is ±6.805×10⁻⁸, which is about 8 times smaller than the original InvSqrt’s error bound.
  • Round-off errors in single-precision arithmetic reduce the theoretical improvement by approximately 10⁻⁷, especially affecting InvSqrt1 more than InvSqrt2.
  • The proposed algorithms are particularly suitable for embedded systems and FPGAs lacking hardware FPU support, where speed and low resource usage are critical.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.