📄 stdmath_details.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <meta name="generator" content="HTML Tidy for Linux/x86 (vers 1st October 2002), see www.w3.org"> <title>Standard C Math</title> </head> <body bgcolor="#ffffff"> <table width="100%" bgcolor="#eeeeff"> <tr> <td><a href="index.html">cppreference.com</a> -> <a href="stdmath.html">Standard C Math</a> -> Details</td> </tr> </table> <h1>Standard C Math</h1> <hr> <h2><a name="abs">abs</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <stdlib.h> int abs( int num );</pre> </td> </tr> </table> <p>The abs() function returns the absolute value of <i>num</i>. For example:</p><pre> int magic_number = 10; cout << "Enter a guess: "; cin >> x; cout << "Your guess was " << abs( magic_number - x ) << " away from the magic number." << endl;</pre> <i>Related topics:</i><br> <strong><a href="#labs">labs()</a>.</strong> <hr> <h2><a name="acos">acos</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <math.h> double acos( double arg );</pre> </td> </tr> </table> <p>The acos() function returns the arc cosine of <i>arg</i>. <i>arg</i> should be between -1 and 1.</p> <i>Related topics:</i><br> <strong><a href="#asin">asin()</a>, <a href="#atan">atan()</a>, <a href="#atan2">atan2()</a>, <a href= "#sin">sin()</a>, <a href="#cos">cos()</a>, <a href="#tan">tan()</a>, <a href="#sinh">sinh()</a>, <a href="#cosh">cosh()</a>, and <a href="#tanh">tanh()</a>.</strong> <hr> <h2><a name="asin">asin</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <math.h> double asin( double arg );</pre> </td> </tr> </table> <p>The asin() function returns the arc sine of <i>arg</i>. <i>arg</i> should be between -1 and 1.</p> <i>Related topics:</i><br> <strong><a href="#asin">acos()</a>, <a href="#atan">atan()</a>, <a href="#atan2">atan2()</a>, <a href= "#sin">sin()</a>, <a href="#cos">cos()</a>, <a href="#tan">tan()</a>, <a href="#sinh">sinh()</a>, <a href="#cosh">cosh()</a>, and <a href="#tanh">tanh()</a>.</strong> <hr> <h2><a name="atan">atan</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <math.h> double atan( double arg );</pre> </td> </tr> </table> <p>The function atan() returns the arc tangent of <i>arg</i>.</p> <i>Related topics:</i><br> <strong><a href="#asin">asin()</a>, <a href="#acos">acos()</a>, <a href="#atan2">atan2()</a>, <a href= "#sin">sin()</a>, <a href="#cos">cos()</a>, <a href="#tan">tan()</a>, <a href="#sinh">sinh()</a>, <a href="#cosh">cosh()</a>, and <a href="#tanh">tanh()</a>.</strong> <hr> <h2><a name="atan2">atan2</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <math.h> double atan2( double y, double x );</pre> </td> </tr> </table> <p>The atan2() function computes the arc tangent of y/x, using the signs of the arguments to compute the quadrant of the return value.</p> <i>Related topics:</i><br> <strong><a href="#asin">asin()</a>, <a href="#acos">acos()</a>, <a href="#atan">atan()</a>, <a href= "#sin">sin()</a>, <a href="#cos">cos()</a>, <a href="#tan">tan()</a>, <a href="#sinh">sinh()</a>, <a href="#cosh">cosh()</a>, and <a href="#tanh">tanh()</a>.</strong> <hr> <h2><a name="ceil">ceil</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <math.h> double ceil( double num );</pre> </td> </tr> </table> <p>The ceil() function returns the smallest integer no less than <i>num</i>. For example,</p><pre> y = 6.04; x = ceil( y );</pre> <p>would set x to 7.0.</p> <i>Related topics:</i><br> <strong><a href="#floor">floor()</a> and <a href="#fmod">fmod()</a>.</strong> <hr> <h2><a name="cos">cos</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <math.h> double cos( double arg );</pre> </td> </tr> </table> <p>The cos() function returns the cosine of <i>arg</i>, where <i>arg</i> is expressed in radians.</p> <i>Related topics:</i><br> <strong><a href="#asin">asin()</a>, <a href="#acos">acos()</a>, <a href="#atan">atan()</a>, <a href= "#sin">sin()</a>, <a href="#atan2">atan2()</a>, <a href="#tan">tan()</a>, <a href="#sinh">sinh()</a>, <a href="#cosh">cosh()</a>, and <a href="#tanh">tanh()</a>.</strong> <hr> <h2><a name="cosh">cosh</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <math.h> double cosh( double arg );</pre> </td> </tr> </table> <p>The function cosh() returns the hyperbolic cosine of <i>arg</i>.</p> <i>Related topics:</i><br> <strong><a href="#asin">asin()</a>, <a href="#acos">acos()</a>, <a href="#atan">atan()</a>, <a href= "#sin">sin()</a>, <a href="#atan2">atan2()</a>, <a href="#tan">tan()</a>, <a href="#sinh">sinh()</a>, <a href="#cos">cos()</a>, and <a href="#tanh">tanh()</a>.</strong> <hr> <h2><a name="div">div</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <stdlib.h> div_t div( int numerator, int denominator );</pre> </td> </tr> </table> <p>The function div() returns the quotient and remainder of the operation <i>numerator</i> / <i>denominator</i>. The <strong>div_t</strong> structure is defined in stdlib.h, and has at least:</p><pre> int quot; // The quotient int rem; // The remainder</pre> <p>For example, the following code displays the quotient and remainder of x/y:</p><pre> div_t temp; temp = div( x, y ); printf( "%d divided by %d yields %d with a remainder of %d\n", x, y, temp.quot, temp.rem );</pre> <i>Related topics:</i><br> <strong><a href="#ldiv">ldiv()</a>.</strong> <hr> <h2><a name="exp">exp</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <math.h> double exp( double arg );</pre> </td> </tr> </table> <p>The exp() function returns e (2.7182818) raised to the <i>arg</i>th power.</p> <i>Related topics:</i><br> <strong><a href="#log">log()</a>.</strong> <hr> <h2><a name="fabs">fabs</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <math.h> double fabs( double arg );</pre> </td> </tr> </table> <p>The function fabs() returns the absolute value of <i>arg</i>.</p> <i>Related topics:</i><br> <strong><a href="#abs">abs()</a>.</strong> <hr> <h2><a name="floor">floor</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <math.h> double floor( double arg );</pre> </td> </tr> </table> <p>The function floor() returns the largest integer not greater than <i>arg</i>. For example,</p><pre> y = 6.04; x = floor( y );</pre> <p>would result in x being set to 6.0.</p> <i>Related topics:</i><br> <strong><a href="#ceil">ceil()</a>.</strong> <hr> <h2><a name="fmod">fmod</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <math.h> double fmod( double x, double y );</pre> </td> </tr> </table> <p>The fmod() function returns the remainder of <i>x</i>/<i>y</i>.</p> <i>Related topics:</i><br> <strong><a href="#ceil">ceil()</a>, <a href="#floor">floor()</a>, and <a href= "#fabs">fabs()</a>.</strong> <hr> <h2><a name="frexp">frexp</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <math.h> double frexp( double num, int *exp );</pre> </td> </tr> </table> <p>The function frexp() is used to decompose <i>num</i> into two parts: a mantissa between 0.5 and 1 (returned by the function) and an exponent returned as <i>exp</i>. Scientific notation works like this:</p><pre> num = mantissa * (2 ^ exp)</pre> <i>Related topics:</i><br> <strong><a href="#ldexp">ldexp()</a>.</strong> <hr> <h2><a name="labs">labs</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <stdlib.h> long labs( long num );</pre> </td> </tr> </table> <p>The function labs() returns the absolute value of <i>num</i>.</p> <i>Related topics:</i><br> <strong><a href="#abs">abs()</a>.</strong> <hr> <h2><a name="ldexp">ldexp</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <math.h> double ldexp( double num, int exp );</pre> </td> </tr> </table> <p>The ldexp() function returns <i>num</i> * (2 ^ <i>exp</i>). And get this: if an overflow occurs, <strong>HUGE_VAL</strong> is returned.</p> <i>Related topics:</i><br> <strong><a href="#frexp">frexp()</a> and <a href="#modf">modf()</a>.</strong> <hr> <h2><a name="ldiv">ldiv</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <stdlib.h> ldiv_t ldiv( long numerator, long denominator );</pre> </td> </tr> </table> <p>The ldiv() function returns the quotient and remainder of the operation <i>numerator</i> / <i>denominator</i>. The <strong>ldiv_t</strong> structure is defined in stdlib.h and has at least:</p><pre> long quot; // the quotient long rem; // the remainder</pre> <i>Related topics:</i><br> <strong><a href="#div">div()</a>.</strong> <hr> <h2><a name="log">log</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <math.h> double log( double num );</pre> </td> </tr> </table> <p>The function log() returns the natural logarithm of <i>num</i>. There's a domain error if <i>num</i> is negative, a range error if <i>num</i> is zero.</p> <i>Related topics:</i><br> <strong><a href="#log10">log10()</a>.</strong> <hr> <h2><a name="log10">log10</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <math.h> double log10( double num );</pre> </td> </tr> </table> <p>The log10() function returns the base 10 logarithm for <i>num</i>. There's a domain error if <i>num</i> is negative, a range error if <i>num</i> is zero.</p> <i>Related topics:</i><br> <strong><a href="#log">log()</a>.</strong> <hr> <h2><a name="modf">modf</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <math.h> double modf( double num, double *i );</pre> </td> </tr> </table> <p>The function modf() splits <i>num</i> into its integer and fraction parts. It returns the fractional part and loads the integer part into <i>i</i>.</p> <i>Related topics:</i><br> <strong><a href="#frexp">frexp()</a> and <a href="#ldexp">ldexp()</a>.</strong> <hr> <h2><a name="pow">pow</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <math.h> double pow( double base, double exp );</pre> </td> </tr> </table> <p>The pow() function returns <i>base</i> raised to the <i>exp</i> power. There's a domain error if <i>base</i> is zero and <i>exp</i> is less than or equal to zero. There's also a domain error if <i>base</i> is negative and <i>exp</i> is not an integer. There's a range error if there's an overflow.</p> <i>Related topics:</i><br> <strong><a href="#exp">exp()</a>, <a href="#log">log()</a>, and <a href="#sqrt">sqrt()</a>.</strong> <hr> <h2><a name="sin">sin</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <math.h> double sin( double arg );</pre> </td> </tr> </table> <p>The function sin() returns the sine of <i>arg</i>, where <i>arg</i> is given in radians.</p> <i>Related topics:</i><br> <strong><a href="#asin">asin()</a>, <a href="#acos">acos()</a>, <a href="#atan">atan()</a>, <a href= "#cosh">cosh()</a>, <a href="#atan2">atan2()</a>, <a href="#tan">tan()</a>, <a href="#sinh">sinh()</a>, <a href="#cos">cos()</a>, and <a href="#tanh">tanh()</a>.</strong> <hr> <h2><a name="sinh">sinh</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <math.h> double sinh( double arg );</pre> </td> </tr> </table> <p>The function sinh() returns the hyperbolic sine of <i>arg</i>.</p> <i>Related topics:</i><br> <strong><a href="#asin">asin()</a>, <a href="#acos">acos()</a>, <a href="#atan">atan()</a>, <a href= "#cosh">cosh()</a>, <a href="#atan2">atan2()</a>, <a href="#tan">tan()</a>, <a href="#sin">sin()</a>, <a href="#cos">cos()</a>, and <a href="#tanh">tanh()</a>.</strong> <hr> <h2><a name="sqrt">sqrt</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <math.h> double sqrt( double num );</pre> </td> </tr> </table> <p>The sqrt() function returns the square root of <i>num</i>. If <i>num</i> is negative, a domain error occurs.</p> <i>Related topics:</i><br> <strong><a href="#exp">exp()</a>, <a href="#log">log()</a>, and <a href="#pow">pow()</a>.</strong> <hr> <h2><a name="tan">tan</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <math.h> double tan( double arg );</pre> </td> </tr> </table> <p>The tan() function returns the tangent of <i>arg</i>, where <i>arg</i> is given in radians.</p> <i>Related topics:</i><br> <strong><a href="#asin">asin()</a>, <a href="#acos">acos()</a>, <a href="#atan">atan()</a>, <a href= "#cosh">cosh()</a>, <a href="#atan2">atan2()</a>, <a href="#sinh">sinh()</a>, <a href="#sin">sin()</a>, <a href="#cos">cos()</a>, and <a href="#tanh">tanh()</a>.</strong> <hr> <h2><a name="tanh">tanh</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <math.h> double tanh( double arg );</pre> </td> </tr> </table> <p>The function tanh() returns the hyperbolic tangent of <i>arg</i>.</p> <i>Related topics:</i><br> <strong><a href="#asin">asin()</a>, <a href="#acos">acos()</a>, <a href="#atan">atan()</a>, <a href= "#cosh">cosh()</a>, <a href="#atan2">atan2()</a>, <a href="#tan">tan()</a>, <a href="#sin">sin()</a>, <a href="#cos">cos()</a>, and <a href="#sinh">sinh()</a>.</strong> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -