Networking · function
simSqrt
Square root, by Newton's method on integers.
Explained in Networking and rollback.
function simSqrt(a: Sim): Simimport { simSqrt } from '@driftengine/network';Parameters
| Parameter | Type | Description |
|---|---|---|
a | Sim |
In depth
Not Math.sqrt of the scaled value, even though Math.sqrt is exactly rounded and would be
reproducible: the scaling back and forth introduces a rounding this file has no way to pin, and
the whole argument for fixed point is that no floating-point reasoning is needed to believe it.
Newton on integers converges in a bounded number of steps and every step is exact.
Negative input answers zero, the way a length does. It is not an error worth a branch at every call site.