| <html lang="en"> |
| <head> |
| <title>Trig Functions - The GNU C Library</title> |
| <meta http-equiv="Content-Type" content="text/html"> |
| <meta name="description" content="The GNU C Library"> |
| <meta name="generator" content="makeinfo 4.13"> |
| <link title="Top" rel="start" href="index.html#Top"> |
| <link rel="up" href="Mathematics.html#Mathematics" title="Mathematics"> |
| <link rel="prev" href="Mathematical-Constants.html#Mathematical-Constants" title="Mathematical Constants"> |
| <link rel="next" href="Inverse-Trig-Functions.html#Inverse-Trig-Functions" title="Inverse Trig Functions"> |
| <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> |
| <!-- |
| This file documents the GNU C library. |
| |
| This is Edition 0.12, last updated 2007-10-27, |
| of `The GNU C Library Reference Manual', for version |
| 2.8 (Sourcery G++ Lite 2011.03-41). |
| |
| Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002, |
| 2003, 2007, 2008, 2010 Free Software Foundation, Inc. |
| |
| Permission is granted to copy, distribute and/or modify this document |
| under the terms of the GNU Free Documentation License, Version 1.3 or |
| any later version published by the Free Software Foundation; with the |
| Invariant Sections being ``Free Software Needs Free Documentation'' |
| and ``GNU Lesser General Public License'', the Front-Cover texts being |
| ``A GNU Manual'', and with the Back-Cover Texts as in (a) below. A |
| copy of the license is included in the section entitled "GNU Free |
| Documentation License". |
| |
| (a) The FSF's Back-Cover Text is: ``You have the freedom to |
| copy and modify this GNU manual. Buying copies from the FSF |
| supports it in developing GNU and promoting software freedom.''--> |
| <meta http-equiv="Content-Style-Type" content="text/css"> |
| <style type="text/css"><!-- |
| pre.display { font-family:inherit } |
| pre.format { font-family:inherit } |
| pre.smalldisplay { font-family:inherit; font-size:smaller } |
| pre.smallformat { font-family:inherit; font-size:smaller } |
| pre.smallexample { font-size:smaller } |
| pre.smalllisp { font-size:smaller } |
| span.sc { font-variant:small-caps } |
| span.roman { font-family:serif; font-weight:normal; } |
| span.sansserif { font-family:sans-serif; font-weight:normal; } |
| --></style> |
| <link rel="stylesheet" type="text/css" href="../cs.css"> |
| </head> |
| <body> |
| <div class="node"> |
| <a name="Trig-Functions"></a> |
| <p> |
| Next: <a rel="next" accesskey="n" href="Inverse-Trig-Functions.html#Inverse-Trig-Functions">Inverse Trig Functions</a>, |
| Previous: <a rel="previous" accesskey="p" href="Mathematical-Constants.html#Mathematical-Constants">Mathematical Constants</a>, |
| Up: <a rel="up" accesskey="u" href="Mathematics.html#Mathematics">Mathematics</a> |
| <hr> |
| </div> |
| |
| <h3 class="section">19.2 Trigonometric Functions</h3> |
| |
| <p><a name="index-trigonometric-functions-2084"></a> |
| These are the familiar <code>sin</code>, <code>cos</code>, and <code>tan</code> functions. |
| The arguments to all of these functions are in units of radians; recall |
| that pi radians equals 180 degrees. |
| |
| <p><a name="index-pi-_0028trigonometric-constant_0029-2085"></a>The math library normally defines <code>M_PI</code> to a <code>double</code> |
| approximation of pi. If strict ISO and/or POSIX compliance |
| are requested this constant is not defined, but you can easily define it |
| yourself: |
| |
| <pre class="smallexample"> #define M_PI 3.14159265358979323846264338327 |
| </pre> |
| <p class="noindent">You can also compute the value of pi with the expression <code>acos |
| (-1.0)</code>. |
| |
| <!-- math.h --> |
| <!-- ISO --> |
| <div class="defun"> |
| — Function: double <b>sin</b> (<var>double x</var>)<var><a name="index-sin-2086"></a></var><br> |
| <blockquote><!-- math.h --> |
| <!-- ISO --> |
| — Function: float <b>sinf</b> (<var>float x</var>)<var><a name="index-sinf-2087"></a></var><br> |
| <blockquote><!-- math.h --> |
| <!-- ISO --> |
| — Function: long double <b>sinl</b> (<var>long double x</var>)<var><a name="index-sinl-2088"></a></var><br> |
| <blockquote><p>These functions return the sine of <var>x</var>, where <var>x</var> is given in |
| radians. The return value is in the range <code>-1</code> to <code>1</code>. |
| </p></blockquote></div> |
| |
| <!-- math.h --> |
| <!-- ISO --> |
| <div class="defun"> |
| — Function: double <b>cos</b> (<var>double x</var>)<var><a name="index-cos-2089"></a></var><br> |
| <blockquote><!-- math.h --> |
| <!-- ISO --> |
| — Function: float <b>cosf</b> (<var>float x</var>)<var><a name="index-cosf-2090"></a></var><br> |
| <blockquote><!-- math.h --> |
| <!-- ISO --> |
| — Function: long double <b>cosl</b> (<var>long double x</var>)<var><a name="index-cosl-2091"></a></var><br> |
| <blockquote><p>These functions return the cosine of <var>x</var>, where <var>x</var> is given in |
| radians. The return value is in the range <code>-1</code> to <code>1</code>. |
| </p></blockquote></div> |
| |
| <!-- math.h --> |
| <!-- ISO --> |
| <div class="defun"> |
| — Function: double <b>tan</b> (<var>double x</var>)<var><a name="index-tan-2092"></a></var><br> |
| <blockquote><!-- math.h --> |
| <!-- ISO --> |
| — Function: float <b>tanf</b> (<var>float x</var>)<var><a name="index-tanf-2093"></a></var><br> |
| <blockquote><!-- math.h --> |
| <!-- ISO --> |
| — Function: long double <b>tanl</b> (<var>long double x</var>)<var><a name="index-tanl-2094"></a></var><br> |
| <blockquote><p>These functions return the tangent of <var>x</var>, where <var>x</var> is given in |
| radians. |
| |
| <p>Mathematically, the tangent function has singularities at odd multiples |
| of pi/2. If the argument <var>x</var> is too close to one of these |
| singularities, <code>tan</code> will signal overflow. |
| </p></blockquote></div> |
| |
| <p>In many applications where <code>sin</code> and <code>cos</code> are used, the sine |
| and cosine of the same angle are needed at the same time. It is more |
| efficient to compute them simultaneously, so the library provides a |
| function to do that. |
| |
| <!-- math.h --> |
| <!-- GNU --> |
| <div class="defun"> |
| — Function: void <b>sincos</b> (<var>double x, double *sinx, double *cosx</var>)<var><a name="index-sincos-2095"></a></var><br> |
| <blockquote><!-- math.h --> |
| <!-- GNU --> |
| — Function: void <b>sincosf</b> (<var>float x, float *sinx, float *cosx</var>)<var><a name="index-sincosf-2096"></a></var><br> |
| <blockquote><!-- math.h --> |
| <!-- GNU --> |
| — Function: void <b>sincosl</b> (<var>long double x, long double *sinx, long double *cosx</var>)<var><a name="index-sincosl-2097"></a></var><br> |
| <blockquote><p>These functions return the sine of <var>x</var> in <code>*</code><var>sinx</var> and the |
| cosine of <var>x</var> in <code>*</code><var>cos</var>, where <var>x</var> is given in |
| radians. Both values, <code>*</code><var>sinx</var> and <code>*</code><var>cosx</var>, are in |
| the range of <code>-1</code> to <code>1</code>. |
| |
| <p>This function is a GNU extension. Portable programs should be prepared |
| to cope with its absence. |
| </p></blockquote></div> |
| |
| <p><a name="index-complex-trigonometric-functions-2098"></a> |
| ISO C99<!-- /@w --> defines variants of the trig functions which work on |
| complex numbers. The GNU C library provides these functions, but they |
| are only useful if your compiler supports the new complex types defined |
| by the standard. |
| <!-- XXX Change this when gcc is fixed. -zw --> |
| (As of this writing GCC supports complex numbers, but there are bugs in |
| the implementation.) |
| |
| <!-- complex.h --> |
| <!-- ISO --> |
| <div class="defun"> |
| — Function: complex double <b>csin</b> (<var>complex double z</var>)<var><a name="index-csin-2099"></a></var><br> |
| <blockquote><!-- complex.h --> |
| <!-- ISO --> |
| — Function: complex float <b>csinf</b> (<var>complex float z</var>)<var><a name="index-csinf-2100"></a></var><br> |
| <blockquote><!-- complex.h --> |
| <!-- ISO --> |
| — Function: complex long double <b>csinl</b> (<var>complex long double z</var>)<var><a name="index-csinl-2101"></a></var><br> |
| <blockquote><p>These functions return the complex sine of <var>z</var>. |
| The mathematical definition of the complex sine is |
| |
| <p>sin (z) = 1/(2*i) * (exp (z*i) - exp (-z*i)). |
| </p></blockquote></div> |
| |
| <!-- complex.h --> |
| <!-- ISO --> |
| <div class="defun"> |
| — Function: complex double <b>ccos</b> (<var>complex double z</var>)<var><a name="index-ccos-2102"></a></var><br> |
| <blockquote><!-- complex.h --> |
| <!-- ISO --> |
| — Function: complex float <b>ccosf</b> (<var>complex float z</var>)<var><a name="index-ccosf-2103"></a></var><br> |
| <blockquote><!-- complex.h --> |
| <!-- ISO --> |
| — Function: complex long double <b>ccosl</b> (<var>complex long double z</var>)<var><a name="index-ccosl-2104"></a></var><br> |
| <blockquote><p>These functions return the complex cosine of <var>z</var>. |
| The mathematical definition of the complex cosine is |
| |
| <p>cos (z) = 1/2 * (exp (z*i) + exp (-z*i)) |
| </p></blockquote></div> |
| |
| <!-- complex.h --> |
| <!-- ISO --> |
| <div class="defun"> |
| — Function: complex double <b>ctan</b> (<var>complex double z</var>)<var><a name="index-ctan-2105"></a></var><br> |
| <blockquote><!-- complex.h --> |
| <!-- ISO --> |
| — Function: complex float <b>ctanf</b> (<var>complex float z</var>)<var><a name="index-ctanf-2106"></a></var><br> |
| <blockquote><!-- complex.h --> |
| <!-- ISO --> |
| — Function: complex long double <b>ctanl</b> (<var>complex long double z</var>)<var><a name="index-ctanl-2107"></a></var><br> |
| <blockquote><p>These functions return the complex tangent of <var>z</var>. |
| The mathematical definition of the complex tangent is |
| |
| <p>tan (z) = -i * (exp (z*i) - exp (-z*i)) / (exp (z*i) + exp (-z*i)) |
| |
| <p class="noindent">The complex tangent has poles at pi/2 + 2n, where n is an |
| integer. <code>ctan</code> may signal overflow if <var>z</var> is too close to a |
| pole. |
| </p></blockquote></div> |
| |
| </body></html> |
| |