Error propagation for trigonometric and hyperbolic functions#3854
Error propagation for trigonometric and hyperbolic functions#3854
Conversation
| template <typename T> | ||
| constexpr auto acos(const ValueAndVariance<T> a) noexcept { | ||
| using std::acos; | ||
| return ValueAndVariance(acos(a.value), a.variance / (1 - a.value * a.value)); |
There was a problem hiding this comment.
There should be an absolute value here applied to the denominator, and similar for the asin case.
There was a problem hiding this comment.
How can the denominator be > 1? That is outside the domain of these functions and asin and acos return NaN in that case. So if anything, I think the variance should also be NaN. Do you agree?
There was a problem hiding this comment.
Yeah it makes sense to set the variance to nan 👍
|
Thank you very much for this! Would it be possible to also implement the sinc function (i.e. sin(x)/x for x~=0 and 1 for x=0)? :) |
Possible, but that would be a separate issue and PR. Can you open one? |
d467d1f to
c6e620b
Compare
Fixes #3826
There is a bit more code here than before because I moved from generating code for trigonometric functions on variables to writing it manually. I did this because I didn't want to add more specialisations to the generator.
This also optimises the trig functions for inputs in degrees. The used to first convert the entire variable to radians, making a separate, temporary array. The new code avoids that with the extra cost of adding more element functions.