On Sun, 27 Jul 2014, Viral Shah wrote:
Is sincos a standard libm function?
Out of curiosity I looked into sincos since I had never heard of it. A quick check shows there's no sincos in fdlibm (on netlib). However, a little Googling reveals an old Sun math library libsunmath seems to implement it. I did find a couple of libm variants which implemented sincos. However, they simply called sin & cos separately. As Stephan says upthread, no performance improvement. As far as I know, sin & cos are usually computed using mod to fold the input x down to the first quadrant, and then using a power series (needs only 6 or 8 terms IIRC) to compute the function. Perhaps libsunmath computed e.g. cos first, and then did sin = sqrt(1 - cos^2)? Taking the sqrt seems non-performant compared to evaluating a short power series, but maybe they had a reason? Another thought: sin and cos are reflections of each other (over the line x = pi/4) in the first quadrant. Perhaps there some other clever way to get sin from cos? I couldn't think if any in the short time I spent considering it. Stuart On Sun, 27 Jul 2014, Viral Shah wrote:
Is sincos a standard libm function? Also, I wonder if creating the one entry array is too expensive, and if we should just call sin and cos separately. The vectorized version may be able to benefit from calling sincos directly. -viral On Monday, July 28, 2014 1:02:06 AM UTC+5:30, Isaiah wrote:It doesn't appear to be wrapped, but you can call it yourself like this: julia> sincos(x) = begin psin = Cdouble[0]; pcos = Cdouble[0]; ccall(:sincos, Void, (Cdouble, Ptr{Cdouble}, Ptr{Cdouble}), x, psin, pcos); (psin[1], pcos[1]); end sincos (generic function with 1 method) julia> sincos(pi) (1.2246467991473532e-16,-1.0) Feel free to open an issue or pull request if you think it should be exported - might have just been an oversight. On Sun, Jul 27, 2014 at 3:25 PM, Ken B <[email protected]> wrote:Hi, I want to calculated sine and cosine together of the same angle. I saw this function is implemented in openlibm, but is it available in julia and how? https://github.com/JuliaLang/openlibm/blob/18f475de56ec7b478b9220a5f28eb9a23cb51d96/src/s_sincos.c Thanks! Ken
