1 − cos x loses its digits as x shrinks
At the direct form has lost 7 of 16 digits, while keeps at least 15 down to .
2 sin^2(x/2)1 - cos x
| Quantity | Viv | Checked by |
|---|---|---|
digits direct | [13.9542, 12.5402, 10.8051, … ] (7 values) | at x = 1e-7 fewer than 4 digits remain; the direct form never keeps more than 2 digits above 16 - log10(2 / x^2) |
digits half angle | [15.7604, 15.5669, 17, … ] (7 values) | 2 sin^2(x / 2) keeps at least 15 digits from x = 1e-1 to 1e-7 |
lost at 1e4 | 7.71967 | at x = 1e-4 the direct form has lost at least 7 digits |
one_minus_cos.viv
Output · native build · Oct 14, 2026 · 0.57 s
digits_direct: [13.9542, 12.5402, 10.8051, 8.28033, 7.08224, 4.0511, 3.0973] digits_half_angle: [15.7604, 15.5669, 17, 15.7814, 15.8886, 17, 17] lost_at_1e4: 7.71967
- ✓ at x = 1e-4 the direct form has lost at least 7 digits
- ✓ at x = 1e-7 fewer than 4 digits remain
- ✓ the direct form never keeps more than 2 digits above 16 - log10(2 / x^2)
- ✓ 2 sin^2(x / 2) keeps at least 15 digits from x = 1e-1 to 1e-7
Open in the workbenchAtlasMore math claims
- Full statement
- Computing directly for small loses digits as shrinks, never keeping more than 2 digits above (at at least 7 of 16 digits are lost, at fewer than 4 remain), while the equivalent keeps at least 15 digits at every from to .
- Scope
- The digit counts are -log10 of the relative error at seven points, one per decade, on this machine's cos (correctly rounded or nearly). The loss comes from rounding to double before the subtraction, not from the subtraction itself.
- Reference
- The identity , evaluated with the series for the true value (its truncation error is below relative for ); Higham, Accuracy and Stability of Numerical Algorithms, section 1.7.
claims/math/one_minus_cos.viv#ee9be0d9b3