math
math copied to clipboard
add `cospi()`, `sinpi()`, `tanpi()`
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
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.