math icon indicating copy to clipboard operation
math copied to clipboard

add `cospi()`, `sinpi()`, `tanpi()`

Open spinkney opened this issue 4 years ago • 1 comments

Stan math contains numerically stable versions of functions in error prone areas such as log1p, I suggest wrapping Boost's implementations of cospi(), sinpi(), tanpi(). These are useful when the input is a multiple of 0.5.

For example,

> stanFunction("cos", x = c(pi * 0.5, pi * 1.5)) # compiles and returns non-zero values
[1]  6.123234e-17 -1.836970e-16
> cospi(c(0.5, 1.5))
[1] 0 0

spinkney avatar Feb 18 '21 13:02 spinkney

I'm doing a bunch of stuff with trig functions and I'm finding this issue. It's problematic as the 0s don't propagate through all the calculations leaving that small remainder.

spinkney avatar Apr 05 '21 13:04 spinkney