Trig functions across various programming languages
Unfortunately programming languages are inconsistent in how the support trig functions and their inverses. The table below summarizes how to call trig functions in several languages. Note that "C" means the C language itself but also a large number of other programming languages, like Python and JavaScript, that follow C's conventions.
Mathematica | bc | C | NumPy | Perl | Math::Trig | CL |
---|---|---|---|---|---|---|
Sin | s | sin | sin | sin | - | sin |
Cos | c | cos | cos | cos | - | cos |
Tan | - | tan | tan | - | tan | tan |
Sec | - | - | - | - | sec | - |
Csc | - | - | - | - | csc | - |
Cot | - | - | - | - | cot | - |
ArcSin | - | asin | arcsin | - | asin | asin |
ArcCos | - | acos | arccos | - | acos | acos |
ArcTan 1 arg | a | atan | arctan | - | atan | atan |
ArcTan 2 arg | - | atan2 | arctan2 | atan2 | atan2 | atan |
ArcSec | - | - | - | - | asec | - |
ArcCsc | - | - | - | - | acsc | - |
ArcCot | - | - | - | - | acot | - |
This blog post goes through the table in detail. For example, it explains why Mathematica's ArcTan
with two arguments doesn't always return the same value as C's atan2
.
See also trig identities