Physics · function
exactAcos
Math.acos, reproducibly. Outside [-1, 1] this answers NaN, as Math.acos does.
Explained in Your first game, Rigid bodies.
function exactAcos(x: number): numberimport { exactAcos } from '@driftengine/physics';Parameters
| Parameter | Type | Description |
|---|---|---|
x | number |
In depth
Three branches rather than one, and the split at ±0.5 is the reason it is accurate near the ends:
acos has infinite derivative at ±1, so a polynomial in x loses its footing there. Substituting
s = sqrt((1 ∓ x)/2) moves the awkward point to zero, where a polynomial is comfortable — which
is also why sqrt being exactly rounded matters here rather than being a convenience.