⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 library_17.html

📁 Linux程序员的工作手册
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!-- This HTML file has been created by texi2html 1.27     from library.texinfo on 3 March 1994 --><TITLE>The GNU C Library - Mathematics</TITLE><P>Go to the <A HREF="library_16.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_16.html">previous</A>, <A HREF="library_18.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_18.html">next</A> section.<P><H1><A NAME="SEC290" HREF="library_toc.html#SEC290" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC290">Mathematics</A></H1><P>This chapter contains information about functions for performingmathematical computations, such as trigonometric functions.  Most ofthese functions have prototypes declared in the header file<TT>`math.h'</TT>.<A NAME="IDX1246"></A><P>All of the functions that operate on floating-point numbers acceptarguments and return results of type <CODE>double</CODE>.  In the future,there may be additional functions that operate on <CODE>float</CODE> and<CODE>long double</CODE> values.  For example, <CODE>cosf</CODE> and <CODE>cosl</CODE>would be versions of the <CODE>cos</CODE> function that operate on<CODE>float</CODE> and <CODE>long double</CODE> arguments, respectively.  In themeantime, you should avoid using these names yourself.  See section <A HREF="library_1.html#SEC11" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_1.html#SEC11">Reserved Names</A>.<P><H2><A NAME="SEC291" HREF="library_toc.html#SEC291" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC291">Domain and Range Errors</A></H2><A NAME="IDX1247"></A><P>Many of the functions listed in this chapter are defined mathematicallyover a domain that is only a subset of real numbers.  For example, the<CODE>acos</CODE> function is defined over the domain between <CODE>-1</CODE> and<CODE>1</CODE>.  If you pass an argument to one of these functions that isoutside the domain over which it is defined, the function sets<CODE>errno</CODE> to <CODE>EDOM</CODE> to indicate a <DFN>domain error</DFN>.  Onmachines that support IEEE floating point, functions reporting error<CODE>EDOM</CODE> also return a NaN.<P>Some of these functions are defined mathematically to result in acomplex value over parts of their domains.  The most familiar example ofthis is taking the square root of a negative number.  The functions inthis chapter take only real arguments and return only real values;therefore, if the value ought to be nonreal, this is treated as a domainerror.<A NAME="IDX1248"></A><P>A related problem is that the mathematical result of a function may notbe representable as a floating point number.  If magnitude of thecorrect result is too large to be represented, the function sets<CODE>errno</CODE> to <CODE>ERANGE</CODE> to indicate a <DFN>range error</DFN>, andreturns a particular very large value (named by the macro<CODE>HUGE_VAL</CODE>) or its negation (<CODE>- HUGE_VAL</CODE>).<P>If the magnitude of the result is too small, a value of zero is returnedinstead.  In this case, <CODE>errno</CODE> might or might not beset to <CODE>ERANGE</CODE>.<P>The only completely reliable way to check for domain and range errors isto set <CODE>errno</CODE> to <CODE>0</CODE> before you call the mathematical function and test <CODE>errno</CODE> afterward.  As a consequence of this use of <CODE>errno</CODE>, use of the mathematical functions is not reentrant if youcheck for errors.<P>None of the mathematical functions ever generates signals as a result ofdomain or range errors.  In particular, this means that you won't see<CODE>SIGFPE</CODE> signals generated within these functions.  (See section <A HREF="library_21.html#SEC330" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_21.html#SEC330">Signal Handling</A>, for more information about signals.)<P><A NAME="IDX1249"></A><U>Macro:</U> double <B>HUGE_VAL</B><P>An expression representing a particular very large number.  On machinesthat use IEEE floating point format, the value is "infinity".  Onother machines, it's typically the largest positive number that can berepresented.<P>The value of this macro is used as the return value from various mathematical functions in overflow situations.<P>For more information about floating-point representations and limits,see section <A HREF="library_28.html#SEC489" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_28.html#SEC489">Floating Point Parameters</A>.  In particular, the macro<CODE>DBL_MAX</CODE> might be more appropriate than <CODE>HUGE_VAL</CODE> for manyuses other than testing for an error in a mathematical function.<P><A NAME="IDX1250"></A><H2><A NAME="SEC292" HREF="library_toc.html#SEC292" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC292">Trigonometric Functions</A></H2><P>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; recallthat pi radians equals 180 degrees.<A NAME="IDX1251"></A><P>The math library doesn't define a symbolic constant for pi, but you candefine your own if you need one:<P><PRE>#define PI 3.14159265358979323846264338327</PRE><P>You can also compute the value of pi with the expression <CODE>acos(-1.0)</CODE>.<P><A NAME="IDX1252"></A><U>Function:</U> double <B>sin</B> <I>(double <VAR>x</VAR>)</I><P>This function returns the sine of <VAR>x</VAR>, where <VAR>x</VAR> is given inradians.  The return value is in the range <CODE>-1</CODE> to <CODE>1</CODE>.<P><A NAME="IDX1253"></A><U>Function:</U> double <B>cos</B> <I>(double <VAR>x</VAR>)</I><P>This function returns the cosine of <VAR>x</VAR>, where <VAR>x</VAR> is given inradians.  The return value is in the range <CODE>-1</CODE> to <CODE>1</CODE>.<P><A NAME="IDX1254"></A><U>Function:</U> double <B>tan</B> <I>(double <VAR>x</VAR>)</I><P>This function returns the tangent of <VAR>x</VAR>, where <VAR>x</VAR> is given inradians.<P>The following <CODE>errno</CODE> error conditions are defined for this function:<P><DL COMPACT><DT><CODE>ERANGE</CODE><DD>Mathematically, the tangent function has singularities at odd multiplesof pi/2.  If the argument <VAR>x</VAR> is too close to one of thesesingularities, <CODE>tan</CODE> sets <CODE>errno</CODE> to <CODE>ERANGE</CODE> and returnseither positive or negative <CODE>HUGE_VAL</CODE>.</DL><P><A NAME="IDX1255"></A><H2><A NAME="SEC293" HREF="library_toc.html#SEC293" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC293">Inverse Trigonometric Functions</A></H2><P>These are the usual arc sine, arc cosine and arc tangent functions,which are the inverses of the sine, cosine and tangent functions,respectively.<P><A NAME="IDX1256"></A><U>Function:</U> double <B>asin</B> <I>(double <VAR>x</VAR>)</I><P>This function computes the arc sine of <VAR>x</VAR>---that is, the value whosesine is <VAR>x</VAR>.  The value is in units of radians.  Mathematically,there are infinitely many such values; the one actually returned is theone between <CODE>-pi/2</CODE> and <CODE>pi/2</CODE> (inclusive).<P><CODE>asin</CODE> fails, and sets <CODE>errno</CODE> to <CODE>EDOM</CODE>, if <VAR>x</VAR> isout of range.  The arc sine function is defined mathematically onlyover the domain <CODE>-1</CODE> to <CODE>1</CODE>.<P><A NAME="IDX1257"></A><U>Function:</U> double <B>acos</B> <I>(double <VAR>x</VAR>)</I><P>This function computes the arc cosine of <VAR>x</VAR>---that is, the valuewhose cosine is <VAR>x</VAR>.  The value is in units of radians.Mathematically, there are infinitely many such values; the one actuallyreturned is the one between <CODE>0</CODE> and <CODE>pi</CODE> (inclusive).<P><CODE>acos</CODE> fails, and sets <CODE>errno</CODE> to <CODE>EDOM</CODE>, if <VAR>x</VAR> isout of range.  The arc cosine function is defined mathematically onlyover the domain <CODE>-1</CODE> to <CODE>1</CODE>.<P><A NAME="IDX1258"></A><U>Function:</U> double <B>atan</B> <I>(double <VAR>x</VAR>)</I><P>This function computes the arc tangent of <VAR>x</VAR>---that is, the valuewhose tangent is <VAR>x</VAR>.  The value is in units of radians.Mathematically, there are infinitely many such values; the one actuallyreturned is the one between <CODE>-pi/2</CODE> and <CODE>pi/2</CODE>(inclusive).<P><A NAME="IDX1259"></A><U>Function:</U> double <B>atan2</B> <I>(double <VAR>y</VAR>, double <VAR>x</VAR>)</I><P>This is the two argument arc tangent function.  It is similar to computingthe arc tangent of <VAR>y</VAR>/<VAR>x</VAR>, except that the signs of both argumentsare used to determine the quadrant of the result, and <VAR>x</VAR> ispermitted to be zero.  The return value is given in radians and is inthe range <CODE>-pi</CODE> to <CODE>pi</CODE>, inclusive.<P>If <VAR>x</VAR> and <VAR>y</VAR> are coordinates of a point in the plane,<CODE>atan2</CODE> returns the signed angle between the line from the originto that point and the x-axis.  Thus, <CODE>atan2</CODE> is useful forconverting Cartesian coordinates to polar coordinates.  (To compute theradial coordinate, use <CODE>hypot</CODE>; see section <A HREF="library_17.html#SEC294" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_17.html#SEC294">Exponentiation and Logarithms</A>.)<P>The function <CODE>atan2</CODE> sets <CODE>errno</CODE> to <CODE>EDOM</CODE> if both<VAR>x</VAR> and <VAR>y</VAR> are zero; the return value is not defined in thiscase.<P><A NAME="IDX1260"></A><A NAME="IDX1261"></A><A NAME="IDX1262"></A><H2><A NAME="SEC294" HREF="library_toc.html#SEC294" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC294">Exponentiation and Logarithms</A></H2><P><A NAME="IDX1263"></A><U>Function:</U> double <B>exp</B> <I>(double <VAR>x</VAR>)</I><P>The <CODE>exp</CODE> function returns the value of e (the base of naturallogarithms) raised to power <VAR>x</VAR>.<P>The function fails, and sets <CODE>errno</CODE> to <CODE>ERANGE</CODE>, if themagnitude of the result is too large to be representable.<P><A NAME="IDX1264"></A><U>Function:</U> double <B>log</B> <I>(double <VAR>x</VAR>)</I><P>This function returns the natural logarithm of <VAR>x</VAR>.  <CODE>exp (log(<VAR>x</VAR>))</CODE> equals <VAR>x</VAR>, exactly in mathematics and approximately inC.<P>The following <CODE>errno</CODE> error conditions are defined for this function:<P><DL COMPACT><DT><CODE>EDOM</CODE><DD>The argument <VAR>x</VAR> is negative.  The log function is definedmathematically to return a real result only on positive arguments.<P><DT><CODE>ERANGE</CODE><DD>The argument is zero.  The log of zero is not defined.</DL><P><A NAME="IDX1265"></A><U>Function:</U> double <B>log10</B> <I>(double <VAR>x</VAR>)</I><P>This function returns the base-10 logarithm of <VAR>x</VAR>.  Except for thedifferent base, it is similar to the <CODE>log</CODE> function.  In fact,<CODE>log10 (<VAR>x</VAR>)</CODE> equals <CODE>log (<VAR>x</VAR>) / log (10)</CODE>.<P>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -