Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sincos function #3082

Open
spinkney opened this issue Jun 6, 2024 · 1 comment
Open

add sincos function #3082

spinkney opened this issue Jun 6, 2024 · 1 comment

Comments

@spinkney
Copy link
Collaborator

spinkney commented Jun 6, 2024

Neither boost nor Eigen has a sincos function however Julia has a succinct implementation in C at https://github.com/JuliaLang/julia/blob/eabd0212ed974b7128ec77180424090edb4a6d04/base/fastmath.jl#L299. The code is MIT license that is compatible with ours.

A few questions:

  • Is it possible to add llvm code like this?
  • Do we want to?

The output from this function will be a tuple of whatever the input type was. So if the input is a real the output will be a tuple of reals. If the input is complex then this falls back to calculating sin and cos separately and returning a tuple of complex types.

@andrjohns
Copy link
Collaborator

It looks like Julia is actually just wrapping the sincos() function in libm and it can just be called directly:

#include <cmath>

double f(double X){
    double s,c;
    sincos(X, &s, &c);
    return s + c;
}

Apparently GCC will automatically optimise separate sin and cos calls for this, but clang won't.

It looks like clang will only optimise sin and cos to sincos when -ffast-math is set, because of differences in error-handling.

If we're explicitly managing error cases, then I don't see any reason against us using sincos directly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants