liveBook · Manning

Heron approximation

As explained in Modern C, Third Edition

The Heron approximation is an iterative numerical method for refining an estimate of a reciprocal or square-root-related quantity.

Heron approximation refines an estimate x of the reciprocal 1/a by repeatedly multiplying it by (2 − a×x). The loop stops when a×x is sufficiently close to 1, with ε defining the required precision. section 3.2

Iterating to a reciprocal

With a = 34.0 and x = 0.5, a while loop tests fabs(1.0 − a*x) >= ε, then updates x *= (2.0 − a*x). A do loop performs the update once before testing; break can separate the product calculation, stopping test, and update. section 3.2

How Modern C, Third Edition covers it

How deep it goes
Explains the update and convergence test, then shows scaling, bounded refinement, and alternate loop forms.
Examples
Uses a = 34.0, initial x = 0.5, a complete inverse program, and outputs for 0.07, 5, and 6E+23.
What it assumes
Assumes basic C expressions and variables while demonstrating iteration conditions and updates through a numerical example.
What you can do after
Apply it via C while, do, or break-based loops to compute multiplicative inverses to a chosen tolerance.
How it connects
Connects reciprocal approximation with floating-point arithmetic, epsilon tolerances, loop control, and command-line processing.

Also explained in

Compare how 2 books explain Heron approximation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.