cppreference.com -> Standard C Math -> Details

Standard C Math


abs

Syntax:
  #include <stdlib.h>
  int abs( int num );

The abs() function returns the absolute value of num. For example:

    int magic_number = 10;
    cout << "Enter a guess: ";
    cin >> x;
    cout << "Your guess was " << abs( magic_number - x ) << " away from the magic number." << endl;
Related topics:
labs().

acos

Syntax:
  #include <math.h>
  double acos( double arg );

The acos() function returns the arc cosine of arg. arg should be between -1 and 1.

Related topics:
asin(), atan(), atan2(), sin(), cos(), tan(), sinh(), cosh(), and tanh().

asin

Syntax:
  #include <math.h>
  double asin( double arg );

The asin() function returns the arc sine of arg. arg should be between -1 and 1.

Related topics:
acos(), atan(), atan2(), sin(), cos(), tan(), sinh(), cosh(), and tanh().

atan

Syntax:
  #include <math.h>
  double atan( double arg );

The function atan() returns the arc tangent of arg.

Related topics:
asin(), acos(), atan2(), sin(), cos(), tan(), sinh(), cosh(), and tanh().

atan2

Syntax:
  #include <math.h>
  double atan2( double y, double x );

The atan2() function computes the arc tangent of y/x, using the signs of the arguments to compute the quadrant of the return value.

Related topics:
asin(), acos(), atan(), sin(), cos(), tan(), sinh(), cosh(), and tanh().

ceil

Syntax:
  #include <math.h>
  double ceil( double num );

The ceil() function returns the smallest integer no less than num. For example,

    y = 6.04;
    x = ceil( y );

would set x to 7.0.

Related topics:
floor() and fmod().

cos

Syntax:
  #include <math.h>
  double cos( double arg );

The cos() function returns the cosine of arg, where arg is expressed in radians.

Related topics:
asin(), acos(), atan(), sin(), atan2(), tan(), sinh(), cosh(), and tanh().

cosh

Syntax:
  #include <math.h>
  double cosh( double arg );

The function cosh() returns the hyperbolic cosine of arg.

Related topics:
asin(), acos(), atan(), sin(), atan2(), tan(), sinh(), cos(), and tanh().

div

Syntax:
  #include <stdlib.h>
  div_t div( int numerator, int denominator );

The function div() returns the quotient and remainder of the operation numerator / denominator. The div_t structure is defined in stdlib.h, and has at least:

    int quot;   // The quotient
    int rem;    // The remainder

For example, the following code displays the quotient and remainder of x/y:

    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 );
Related topics:
ldiv().

exp

Syntax:
  #include <math.h>
  double exp( double arg );

The exp() function returns e (2.7182818) raised to the argth power.

Related topics:
log().

fabs

Syntax:
  #include <math.h>
  double fabs( double arg );

The function fabs() returns the absolute value of arg.

Related topics:
abs().

floor

Syntax:
  #include <math.h>
  double floor( double arg );

The function floor() returns the largest integer not greater than arg. For example,

    y = 6.04;
    x = floor( y );

would result in x being set to 6.0.

Related topics:
ceil().

fmod

Syntax:
  #include <math.h>
  double fmod( double x, double y );

The fmod() function returns the remainder of x/y.

Related topics:
ceil(), floor(), and fabs().

frexp

Syntax:
  #include <math.h>
  double frexp( double num, int *exp );

The function frexp() is used to decompose num into two parts: a mantissa between 0.5 and 1 (returned by the function) and an exponent returned as exp. Scientific notation works like this:

    num = mantissa * (2 ^ exp)
Related topics:
ldexp().

labs

Syntax:
  #include <stdlib.h>
  long labs( long num );

The function labs() returns the absolute value of num.

Related topics:
abs().

ldexp

Syntax:
  #include <math.h>
  double ldexp( double num, int exp );

The ldexp() function returns num * (2 ^ exp). And get this: if an overflow occurs, HUGE_VAL is returned.

Related topics:
frexp() and modf().

ldiv

Syntax:
  #include <stdlib.h>
  ldiv_t ldiv( long numerator, long denominator );

The ldiv() function returns the quotient and remainder of the operation numerator / denominator. The ldiv_t structure is defined in stdlib.h and has at least:

    long quot;  // the quotient
    long rem;   // the remainder
Related topics:
div().

log

Syntax:
  #include <math.h>
  double log( double num );

The function log() returns the natural logarithm of num. There's a domain error if num is negative, a range error if num is zero.

Related topics:
log10().

log10

Syntax:
  #include <math.h>
  double log10( double num );

The log10() function returns the base 10 logarithm for num. There's a domain error if num is negative, a range error if num is zero.

Related topics:
log().

modf

Syntax:
  #include <math.h>
  double modf( double num, double *i );

The function modf() splits num into its integer and fraction parts. It returns the fractional part and loads the integer part into i.

Related topics:
frexp() and ldexp().

pow

Syntax:
  #include <math.h>
  double pow( double base, double exp );

The pow() function returns base raised to the exp power. There's a domain error if base is zero and exp is less than or equal to zero. There's also a domain error if base is negative and exp is not an integer. There's a range error if there's an overflow.

Related topics:
exp(), log(), and sqrt().

sin

Syntax:
  #include <math.h>
  double sin( double arg );

The function sin() returns the sine of arg, where arg is given in radians.

Related topics:
asin(), acos(), atan(), cosh(), atan2(), tan(), sinh(), cos(), and tanh().

sinh

Syntax:
  #include <math.h>
  double sinh( double arg );

The function sinh() returns the hyperbolic sine of arg.

Related topics:
asin(), acos(), atan(), cosh(), atan2(), tan(), sin(), cos(), and tanh().

sqrt

Syntax:
  #include <math.h>
  double sqrt( double num );

The sqrt() function returns the square root of num. If num is negative, a domain error occurs.

Related topics:
exp(), log(), and pow().

tan

Syntax:
  #include <math.h>
  double tan( double arg );

The tan() function returns the tangent of arg, where arg is given in radians.

Related topics:
asin(), acos(), atan(), cosh(), atan2(), sinh(), sin(), cos(), and tanh().

tanh

Syntax:
  #include <math.h>
  double tanh( double arg );

The function tanh() returns the hyperbolic tangent of arg.

Related topics:
asin(), acos(), atan(), cosh(), atan2(), tan(), sin(), cos(), and sinh().