Skip to content

Compute sin(acos(x)) as sqrt(1-dot*dot), which is faster.#159

Open
rmlarsen wants to merge 1 commit into
boston-dynamics:masterfrom
rmlarsen:slerp
Open

Compute sin(acos(x)) as sqrt(1-dot*dot), which is faster.#159
rmlarsen wants to merge 1 commit into
boston-dynamics:masterfrom
rmlarsen:slerp

Conversation

@rmlarsen
Copy link
Copy Markdown

@rmlarsen rmlarsen commented Apr 24, 2025

Notice that despite the subtraction "1-dot*dot" there is no significant loss of accuracy here, even for small angles where "dot" is near 1. This is because our knowledge of the angle from "dot" (i.e. cos(theta)) is already limited by the floating point representation error near 1, which is 2^-23 (~1.1e-7) for single and 2^-52 (~2.2e-16) for double precision.

The following program tabulates the relative error of the two formulas, evaluated in single precision, compared to evaluating the original formula in double precision:

https://godbolt.org/z/qrzWcd43c

Notice that despite the subtraction "1-dot*dot" there is no significant
loss of accuracy here, even for small angles where "dot" is near 1. This is
because our knowledge of the angle from "dot (i.e. cos(theta)) is already
limited by the floating representation error near 1, which is 2^-23 (1.1e-7)
for single and 2^-52 (2.2e-16) for double precision.

The following program tabulates the relative error of the two formulas,
evaluated in single precision, compared to evaluating the original formula
in double precsion:

https://godbolt.org/z/qrzWcd43c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant