add function sncs1cs to get accurate 1-cosine #44
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently in three places in the code there is an expression like:
1-cosine(subexpr). The problem with that is that it sacrifices quite a
bit of precision the floating point type in use could provide. Because
of the subtraction, and the fact that floating point is MUCH denser near
zero than near one, 1-cosine(x) values that should be close to zero will
just be truncated to exactly zero.
The added function sncs1cs is not exported.
The changes apply only if the user has not specified a custom mfloat_t.
This improves mat3_rotation_axis, mat4_rotation_axis and
sine_ease_in_out. A side improvement in the former two is that the
computation of sine, cosine and 1-cosine should be cheaper when
computing them all at the same time than when calling a separate
function for each of the three (because the majority of the code is
shared between the three).
I checked that the improvements do materialize and, more importantly,
at the same time searched for big regressions:
https://github.com/nsajko/numericcompfricas (see the README.md)
Basically, the results are that there are no significant differences for
sin and cos (I think the accuracy only varies by one bit), but there are
big improvements for 1-cos (AKA omc AKA 1cs). The repository contains
the results of the check against glibc and against musl.
FriCAS (for the check) can be found here:
https://github.com/fricas/fricas