AdvancedMultiple choice
Where doubles run out of digits · Part 3 of 3
Doubles (IEEE 754 binary64) have a 53-bit significand, so between and consecutive doubles are exactly apart. A risk system stores prices and their squares as doubles.
Which change gives an accurate variance for these prices?
- ASubtract a nearby value, such as the first price, before squaring, or use Welford’s update
- BSum the squares with Kahan compensated summation
- CTake the absolute value of the result so that it is never negative
- DUse
np.longdouble, which carries 64 bits of significand and so rescues the calculation on every platform
The worked solution is in Premium
The answer, the full working and the one idea to take away – for this and all 1,322 questions in the bank. Answer it in practice and your working is marked, with a known mistake named when you make one.
More numerical methods questions
- What is machine epsilon for IEEE 754 double precision, in units of 10⁻¹⁶, to…Foundation
- Why do exchange systems store prices as integer ticks rather than as…Applied
- In double precision, what does 1 - math.cos(1e-8) evaluate to?Applied
- Double precision can represent every integer up to 2ᵏ exactly, but not every…Applied
- A loop total = 0.0; for _ in range(10): total += 0.1 leaves total == 0.9999999999999999.Applied
- Computing a variance as 𝔼[X²]−(𝔼[X])² sometimes returns a small negative number. Why?Advanced