Hacker News new | ask | show | jobs
by svat 483 days ago
Nice! Looking into them a bit deeper, they all rely on two facts involving quantities that are off by 1 ulp:

    √2 - 2/√2 as a float64 is exactly equal to 2^{-52}

    √2 * √2   as a float64 is exactly equal to 2 + 2^{-51}
and all other calculations after that are mathematically exact. For example:

    √(2 / √√(√2 - (2 / √2))) := √(2 / √√(2^{-52})) = √(2 / 2^{-13}) = 2^7 = 128
and

    √√(2 / ((√2 * √2) - 2)) := √√(2 / 2^{-51}) = √√(2^{52}) = 2^{13} = 8192
In your last one,

    6369051672525773 = 2^{52} * 1.4142135623730951454746218587388284504413604736328125
(https://float.exposed/0x4336a09e667f3bcd) where the second value is the exact value of the floating-point representation of √2 (i.e. the closest representable-in-float64 value to √2).