I'd suggest simply adding `assert(-M_PI/2 <= x && x <= M_PI/2)` to your function. It won't slow down the code in optimized builds, and makes it obvious that it isn't designed to work outside that range even if people copy/paste the code without reading it or any comments.
Also, it would be good to have even in a "production" use of a function like this, in case something outside that range reaches it by accident.
Yes, that’s a very productive suggestion! Feel free to open a PR, or I’ll just patch it myself in a couple of hours when I’m back to the computer. Thanks!
Also, it would be good to have even in a "production" use of a function like this, in case something outside that range reaches it by accident.