454 lines
11 KiB
HTML
454 lines
11 KiB
HTML
<html>
|
|
<head>
|
|
<title>
|
|
C Guide--2.7 math.h
|
|
</title>
|
|
<!-- Changed by: eric huss, 12-Mar-1997 -->
|
|
</head>
|
|
<body text="#000000" bgcolor="#FFFFFF">
|
|
|
|
<center>
|
|
<table border=0 width=100%>
|
|
<tr>
|
|
<td align=left width=20% valign=top>
|
|
<a href="2.6.html">
|
|
<img src="left.gif" border=0>
|
|
Previous Section<br>
|
|
2.6 locale.h</a></td>
|
|
<td align=center width=60% valign=top>
|
|
| <a href="index.html">Table of Contents</a> |
|
|
<a href="index2.html">Index</a> |</td>
|
|
<td align=right width=20% valign=top>
|
|
<a href="2.8.html">
|
|
Next Section
|
|
<img src="right.gif" border=0><br>
|
|
2.8 setjmp.h</a></td>
|
|
</tr>
|
|
</table>
|
|
</center>
|
|
<hr>
|
|
|
|
|
|
<h1> 2.7 math.h</h1>
|
|
<p>
|
|
The math header defines several mathematic functions.
|
|
<p>
|
|
Macros:
|
|
<blockquote>
|
|
<code><b>HUGE_VAL</b></code>
|
|
</blockquote>
|
|
<p>
|
|
Functions:
|
|
<blockquote><code><b>
|
|
acos();<br>
|
|
asin();<br>
|
|
atan();<br>
|
|
atan2();<br>
|
|
ceil();<br>
|
|
cos();<br>
|
|
cosh();<br>
|
|
exp();<br>
|
|
fabs();<br>
|
|
floor();<br>
|
|
fmod();<br>
|
|
frexp();<br>
|
|
ldexp();<br>
|
|
log();<br>
|
|
log10();<br>
|
|
modf();<br>
|
|
pow();<br>
|
|
sin();<br>
|
|
sinh();<br>
|
|
sqrt();<br>
|
|
tan();<br>
|
|
tanh();<br>
|
|
</b></code></blockquote>
|
|
<p>
|
|
<a name="variables"></a>
|
|
<h2>2.7.1 Error Conditions</h2>
|
|
<p>
|
|
All math.h functions handle errors similarly.
|
|
<p>
|
|
In the case that the argument passed to the function exceeds the range of that function,
|
|
then the variable <code><b>errno</b></code> is set to <code><b>EDOM</b></code>. The value that the function returns is implementation
|
|
specific.
|
|
<p>
|
|
In the case that the value being returned is too large to be represented in a double, then
|
|
the function returns the macro <code><b>HUGE_VAL</b></code>, and sets the variable <code><b>errno</b></code> to <code><b>ERANGE</b></code> to represent
|
|
an overflow. If the value is too small to be represented in a double, then the function returns
|
|
zero. In this case whether or not <code><b>errno</b></code> is set to <code><b>ERANGE</b></code> is implementation specific.
|
|
<p>
|
|
<code><b>errno</b></code>, <code><b>EDOM</b></code>, and <code><b>ERANGE</b></code> are defined in the errno.h header.
|
|
<p>
|
|
Note that in all cases when it is stated that there is no range limit, it is implied that the
|
|
value is limited by the minimum and maximum values of type double.
|
|
<p>
|
|
<h2> 2.7.2 Trigonometric Functions</h2>
|
|
<a name="acos"></a>
|
|
<h2>2.7.2.1 acos</h2>
|
|
<p>
|
|
Declaration:
|
|
<blockquote>
|
|
<code><b>double acos(double</b></code><i> x</i><code><b>);</b></code>
|
|
<p>
|
|
Returns the arc cosine of <i>x</i> in radians.
|
|
</blockquote>
|
|
<p>
|
|
Range:
|
|
<blockquote>
|
|
The value <i>x</i> must be within the range of -1 to +1 (inclusive). The returned value is in the
|
|
range of 0 to pi (inclusive).
|
|
</blockquote>
|
|
<p>
|
|
<a name="asin"></a>
|
|
<h2>2.7.2.2 asin</h2>
|
|
<p>
|
|
Declaration:
|
|
<blockquote>
|
|
<code><b>double asin(double</b></code> <i>x</i><code><b>);</b></code>
|
|
<p>
|
|
Returns the arc sine of <i>x</i> in radians.
|
|
</blockquote>
|
|
|
|
Range:
|
|
<blockquote>
|
|
The value of <i>x</i> must be within the range of -1 to +1 (inclusive). The returned value is in
|
|
the range of -p/2 to +p/2 (inclusive).
|
|
</blockquote>
|
|
|
|
<a name="atan"></a>
|
|
<h2>2.7.2.3 atan</h2>
|
|
|
|
Declaration:
|
|
<blockquote>
|
|
<code><b>double atan(double</b></code><i> x</i><code><b>);</b></code>
|
|
<p>
|
|
Returns the arc tangent of <i>x</i> in radians.
|
|
</blockquote>
|
|
|
|
Range:
|
|
<blockquote>
|
|
The value of <i>x </i>has no range. The returned value is in the range of -p/2 to +p/2
|
|
(inclusive).
|
|
</blockquote>
|
|
|
|
<a name="atan2"></a>
|
|
<h2>2.7.2.4 atan2</h2>
|
|
|
|
Declaration:
|
|
<blockquote>
|
|
<code><b>double atan2(doubly</b></code><i> y</i><code><b>, double</b></code><i> x</i><code><b>);</b></code>
|
|
<p>
|
|
Returns the arc tangent in radians of <i>y/x</i> based on the signs of both values to determine
|
|
the correct quadrant.
|
|
</blockquote>
|
|
|
|
Range:
|
|
<blockquote>
|
|
Both <i>y</i> and <i>x</i> cannot be zero. The returned value is in the range of -p/2 to +p/2
|
|
(inclusive).
|
|
</blockquote>
|
|
|
|
<a name="cos"></a>
|
|
<h2>2.7.2.5 cos</h2>
|
|
|
|
Declaration:
|
|
<blockquote>
|
|
<code><b>double cos(double</b></code><i> x</i><code><b>);</b></code>
|
|
<p>
|
|
Returns the cosine of a radian angle <i>x</i>.
|
|
</blockquote>
|
|
|
|
Range:
|
|
<blockquote>
|
|
The value of <i>x</i> has no range. The returned value is in the range of -1 to +1 (inclusive).
|
|
</blockquote>
|
|
|
|
<a name="cosh"></a>
|
|
<h2>2.7.2.6 cosh</h2>
|
|
|
|
Declaration:
|
|
<blockquote>
|
|
<code><b>double cosh(double</b></code><i> x</i><code><b>);</b></code>
|
|
<p>
|
|
|
|
Returns the hyperbolic cosine of <i>x</i>.
|
|
</blockquote>
|
|
|
|
Range:
|
|
<blockquote>
|
|
There is no range limit on the argument or return value.
|
|
</blockquote>
|
|
|
|
<a name="sin"></a>
|
|
<h2>2.7.2.7 sin</h2>
|
|
|
|
Declaration:
|
|
<blockquote>
|
|
<code><b>double sin(double</b></code><i> x</i><code><b>);</b></code>
|
|
<p>
|
|
Returns the sine of a radian angle <i>x</i>.
|
|
</blockquote>
|
|
|
|
Range:
|
|
<blockquote>
|
|
The value of <i>x</i> has no range. The returned value is in the range of -1 to +1 (inclusive).
|
|
</blockquote>
|
|
|
|
<a name="sinh"></a>
|
|
<h2>2.7.2.8 sinh</h2>
|
|
|
|
Declaration:
|
|
<blockquote>
|
|
<code><b>double sinh(double</b></code><i> x</i><code><b>);</b></code>
|
|
<p>
|
|
Returns the hyperbolic sine of <i>x</i>.
|
|
</blockquote>
|
|
|
|
Range:
|
|
<blockquote>
|
|
There is no range limit on the argument or return value.
|
|
</blockquote>
|
|
|
|
<a name="tan"></a>
|
|
<h2>2.7.2.9 tan</h2>
|
|
|
|
Declaration:
|
|
<blockquote>
|
|
<code><b>double tan(double</b></code><i> x</i><code><b>);</b></code>
|
|
<p>
|
|
Returns the tangent of a radian angle <i>x</i>.
|
|
</blockquote>
|
|
|
|
Range:
|
|
<blockquote>
|
|
There is no range limit on the argument or return value.
|
|
</blockquote>
|
|
|
|
<a name="tanh"></a>
|
|
<h2>2.7.2.10 tanh</h2>
|
|
|
|
Declaration:
|
|
<blockquote>
|
|
<code><b>double tanh(double</b></code><i> x</i><code><b>);</b></code>
|
|
<p>
|
|
Returns the hyperbolic tangent of <i>x</i>.
|
|
</blockquote>
|
|
|
|
Range:
|
|
<blockquote>
|
|
The value of <i>x</i> has no range. The returned value is in the range of -1 to +1 (inclusive).
|
|
</blockquote>
|
|
<h2> 2.7.3 Exponential, Logarithmic, and Power Functions</h2>
|
|
<a name="exp"></a>
|
|
<h2>2.7.3.1 exp</h2>
|
|
|
|
Declaration:
|
|
<blockquote>
|
|
<code><b>double exp(double</b></code><i> x</i><code><b>);</b></code>
|
|
<p>
|
|
Returns the value of e raised to the <i>x</i>th power.
|
|
</blockquote>
|
|
|
|
Range:
|
|
<blockquote>
|
|
There is no range limit on the argument or return value.
|
|
</blockquote>
|
|
|
|
<a name="frexp"></a>
|
|
<h2>2.7.3.2 frexp</h2>
|
|
|
|
Declaration:
|
|
<blockquote>
|
|
<code><b>double frexp(double</b></code><i> x</i><code><b>, int *</b></code><i>exponent</i><code><b>);</b></code>
|
|
<p>
|
|
The floating-point number <i>x</i> is broken up into a mantissa and exponent.<br>
|
|
The returned value is the mantissa and the integer pointed to by <i>exponent</i> is the
|
|
exponent. The resultant value is <tt>x=mantissa * 2^exponent</tt>.
|
|
</blockquote>
|
|
|
|
Range:
|
|
<blockquote>
|
|
The mantissa is in the range of .5 (inclusive) to 1 (exclusive).
|
|
</blockquote>
|
|
|
|
<a name="ldexp"></a>
|
|
<h2>2.7.3.3 ldexp</h2>
|
|
|
|
Declaration:
|
|
<blockquote>
|
|
<code><b>double ldexp(double</b></code><i> x</i><code><b>, int</b></code> <i>exponent</i><code><b>);</b></code>
|
|
<p>
|
|
Returns <i>x</i> multiplied by 2 raised to the power of <i>exponent</i>.<br>
|
|
<tt>x*2^exponent</tt>
|
|
</blockquote>
|
|
|
|
Range:
|
|
<blockquote>
|
|
There is no range limit on the argument or return value.
|
|
</blockquote>
|
|
|
|
<a name="log"></a>
|
|
<h2>2.7.3.4 log</h2>
|
|
|
|
Declaration:
|
|
<blockquote>
|
|
<code><b>double log(double</b></code><i> x</i><code><b>);</b></code>
|
|
<p>
|
|
Returns the natural logarithm (base-e logarithm) of <i>x</i>.
|
|
</blockquote>
|
|
|
|
Range:
|
|
<blockquote>
|
|
There is no range limit on the argument or return value.
|
|
</blockquote>
|
|
|
|
|
|
<a name="log10"></a>
|
|
<h2>2.7.3.5 log10</h2>
|
|
|
|
Declaration:
|
|
<blockquote>
|
|
<code><b>double log10(double</b></code><i> x</i><code><b>);</b></code>
|
|
<p>
|
|
Returns the common logarithm (base-10 logarithm) of <i>x</i>.
|
|
</blockquote>
|
|
|
|
Range:
|
|
<blockquote>
|
|
There is no range limit on the argument or return value.
|
|
</blockquote>
|
|
|
|
<a name="modf"></a>
|
|
<h2>2.7.3.6 modf</h2>
|
|
|
|
Declaration:
|
|
<blockquote>
|
|
<code><b>double modf(double</b></code><i> x</i><code><b>, double *</b></code><i>integer</i><code><b>);</b></code>
|
|
<p>
|
|
Breaks the floating-point number <i>x</i> into integer and fraction components.<br>
|
|
The returned value is the fraction component (part after the decimal), and sets <i>integer</i> to
|
|
the integer component.
|
|
</blockquote>
|
|
|
|
Range:
|
|
<blockquote>
|
|
There is no range limit on the argument or return value.
|
|
</blockquote>
|
|
|
|
<a name="pow"></a>
|
|
<h2>2.7.3.7 pow</h2>
|
|
|
|
Declaration:
|
|
<blockquote>
|
|
<code><b>double pow(double</b></code><i> x</i><code><b>, double</b></code><i> y</i><code><b>);</b></code>
|
|
<p>
|
|
Returns <i>x</i> raised to the power of <i>y</i>.
|
|
</blockquote>
|
|
|
|
Range:
|
|
<blockquote>
|
|
<i>x</i> cannot be negative if <i>y</i> is a fractional value. <i>x</i> cannot be zero if <i>y</i> is less than or equal
|
|
to zero.
|
|
</blockquote>
|
|
|
|
<a name="sqrt"></a>
|
|
<h2>2.7.3.8 sqrt</h2>
|
|
|
|
Declaration:
|
|
<blockquote>
|
|
<code><b>double sqrt(double</b></code><i> x</i><code><b>);</b></code>
|
|
<p>
|
|
Returns the square root of <i>x</i>.
|
|
</blockquote>
|
|
|
|
Range:
|
|
<blockquote>
|
|
The argument cannot be negative. The returned value is always positive.
|
|
</blockquote>
|
|
<h2> 2.7.4 Other Math Functions</h2>
|
|
<a name="ceil"></a>
|
|
<h2>2.7.4.1 ceil</h2>
|
|
|
|
Declaration:
|
|
<blockquote>
|
|
<code><b>double ceil(double</b></code><i> x</i><code><b>);</b></code>
|
|
<p>
|
|
Returns the smallest integer value greater than or equal to <i>x</i>.
|
|
</blockquote>
|
|
|
|
Range:
|
|
<blockquote>
|
|
There is no range limit on the argument or return value.
|
|
</blockquote>
|
|
|
|
<a name="fabs"></a>
|
|
<h2>2.7.4.2 fabs</h2>
|
|
|
|
Declaration:
|
|
<blockquote>
|
|
<code><b>double fabs(double</b></code><i> x</i><code><b>);</b></code>
|
|
<p>
|
|
Returns the absolute value of<i> x</i> (a negative value becomes positive, positive value is
|
|
unchanged).
|
|
</blockquote>
|
|
|
|
Range:
|
|
<blockquote>
|
|
There is no range limit on the argument. The return value is always positive.
|
|
</blockquote>
|
|
|
|
<a name="floor"></a>
|
|
<h2>2.7.4.3 floor</h2>
|
|
|
|
Declaration:
|
|
<blockquote>
|
|
<code><b>double floor(double</b></code><i> x</i><code><b>);</b></code>
|
|
<p>
|
|
Returns the largest integer value less than or equal to<i> x</i>.
|
|
</blockquote>
|
|
|
|
Range:
|
|
<blockquote>
|
|
There is no range limit on the argument or return value.
|
|
</blockquote>
|
|
|
|
<a name="fmod"></a>
|
|
<h2>2.7.4.4 fmod</h2>
|
|
|
|
Declaration:
|
|
<blockquote>
|
|
<code><b>double fmod(double</b></code><i> x</i><code><b>, double</b></code><i> y</i><code><b>);</b></code>
|
|
<p>
|
|
Returns the remainder of <i>x</i> divided by <i>y</i>.
|
|
</blockquote>
|
|
|
|
Range:
|
|
<blockquote>
|
|
There is no range limit on the return value. If <i>y</i> is zero, then either a range error will
|
|
occur or the function will return zero (implementation-defined).
|
|
</blockquote>
|
|
<hr>
|
|
<center>
|
|
<table border=0 width=100%>
|
|
<tr>
|
|
<td align=left width=20% valign=top>
|
|
<a href="2.6.html">
|
|
<img src="left.gif" border=0>
|
|
Previous Section<br>
|
|
2.6 locale.h</a></td>
|
|
<td align=center width=60% valign=top>
|
|
| <a href="index.html">Table of Contents</a> |
|
|
<a href="index2.html">Index</a> |</td>
|
|
<td align=right width=20% valign=top>
|
|
<a href="2.8.html">
|
|
Next Section
|
|
<img src="right.gif" border=0><br>
|
|
2.8 setjmp.h</a></td>
|
|
</tr>
|
|
</table>
|
|
</center>
|
|
|
|
</body>
|
|
</html>
|