cppreference.com -> 標準 C 数学関数 -> 詳細

標準 C 数学関数


abs

文法:

  #include <stdlib.h>
  int abs( int 数値 );

abs()は数値 の絶対値を返す関数である。サンプル:

    int magic_number = 10;
    cout << "値を推測してください: ";
    cin >> x;
    cout << "推測した値はマジックナンバーから " << abs( magic_number - x ) << " だけ離れています。" << endl;
関連トピック:
labs()

acos

文法:

  #include <math.h>
  double acos( double 引数 );

acos()は引数 のアークコサインを返す関数である。引数 は-1から1の間の値でなければならない。

関連トピック:
asin(), atan(), atan2(), sin(), cos(), tan(), sinh(), cosh(), tanh()

asin

文法:

  #include <math.h>
  double asin( double 引数 );

asin()は引数 のアークサインを返す関数である。引数 は-1から1の間の値でなければならない。

関連トピック:
acos(), atan(), atan2(), sin(), cos(), tan(), sinh(), cosh(), tanh()

atan

文法:

  #include <math.h>
  double atan( double 引数 );

atan()は引数 のアークタンジェントを返す関数である。

関連トピック:
asin(), acos(), atan2(), sin(), cos(), tan(), sinh(), cosh(), tanh()

atan2

文法:

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

atan2()はy/xのアークタンジェントを計算する関数である。x, yの符号を利用して象限まで求めることができる。

関連トピック:
asin(), acos(), atan(), sin(), cos(), tan(), sinh(), cosh(), tanh()

ceil

文法:

  #include <math.h>
  double ceil( double 数値 );

ceil()は数値 よりも大きい最小の整数を返す関数である。サンプル:

    y = 6.04;
    x = ceil( y );

xには7.0がセットされる。

関連トピック:
floor(), fmod()

cos

文法:

  #include <math.h>
  double cos( double 引数 );

cos()は引数 のコサインを求める関数である。引数 はラジアンである。

関連トピック:
asin(), acos(), atan(), sin(), atan2(), tan(), sinh(), cosh(), tanh()

cosh

文法:

  #include <math.h>
  double cosh( double 引数 );

cos()は引数 のハイパボリックコサインを求める関数である。

関連トピック:
asin(), acos(), atan(), sin(), atan2(), tan(), sinh(), cos(), tanh()

div

文法:

  #include <stdlib.h>
  div_t div( int 分子, int 分母 );

div()は分子 /分母 の割り算の商と余を求める関数である。div_t構造体はstdlib.hで定義されている:

    int quot;	// 商
    int rem;	// 余

次のコードはx/yの商と余を表示するサンプルコードである:

    div_t temp;
    temp = div( x, y );
    printf( "%d ÷ %d = %d 余 %d\n", x, y, temp.quot, temp.rem );
関連トピック:
ldiv()

exp

文法:

  #include <math.h>
  double exp( double 引数 );

exp()はe(2.7182818)を引数 乗する関数である。

関連トピック:
log()

fabs

文法:

  #include <math.h>
  double fabs( double 引数 );

fabs()は引数 の絶対値を返す関数である。

関連トピック:
abs()

floor

文法:

  #include <math.h>
  double floor( double 引数 );

floor()は引数 を超えない最大の整数を返す関数である。サンプル:

    y = 6.04;
    x = floor( y );

xは6.0にセットされる

関連トピック:
ceil()

fmod

文法:

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

fmod()はx/yの余りを求める関数である.

関連トピック:
ceil(), floor(), fabs()

frexp

文法:

  #include <math.h>
  double frexp( double 数値, int *指数部 );

frexp()は数値 を正規化小数(0.5から1、返値で返される)と、指数部 に格納される指数部分に分解する。数学的に以下の式が成り立つ:

    数値 = 正規化小数 * (2 ^ 指数部)
関連トピック:
ldexp()

labs

文法:

  #include <stdlib.h>
  long labs( long 数値 );

labs()は数値 の絶対値を返す関数である。

関連トピック:
abs()

ldexp

文法:

  #include <math.h>
  double ldexp( double 数値, int 指数部 );

ldexp()は数値 * (2 ^ 指数部 ) を計算して返す。オーバーフローが発生した場合にはHUGE_VALを返す。

関連トピック:
frexp(), modf()

ldiv

文法:

  #include <stdlib.h>
  ldiv_t ldiv( long 分子, long 分母 );

ldiv()は分子 /分母 の商と余りを求める関数である。ldiv_tはstdlib.hの中で以下のように定義されている:

    long quot;	// 商
    long rem;	  // 余
関連トピック:
div()

log

文法:

  #include <math.h>
  double log( double 数値 );

log()は数値 の自然対数を求める関数である。数値 が負の値の場合にはdomain errorが発生し、数値 がゼロの場合にはrange errorが発生する。

関連トピック:
log10()

log10

文法:

  #include <math.h>
  double log10( double 数値 );

log10()は数値 の常用対数を求める関数である。数値 が負の値の場合にはdomain errorが発生し、数値 がゼロの場合にはrange errorが発生する。

関連トピック:
log()

modf

文法:

  #include <math.h>
  double modf( double 数値, double *i );

modf()は数値 を実数部と整数部に分割する関数である。実数部は返値として、整数部はiに記録される形で返される。

関連トピック:
frexp(), ldexp()

pow

文法:

  #include <math.h>
  double pow( double 底, double 乗数 );

pow()は乗数 乗の計算を行って返す関数である。 がゼロで乗数 がゼロ以下の場合にはdomain errorが発生する。また、 が負で乗数 が小数の場合にもdomain errorになる。計算結果がオーバーフローする場合はrange errorが発生する。

関連トピック:
exp(), log(), sqrt()

sin

文法:

  #include <math.h>
  double sin( double 引数 );

sin()は引数 のサインを求める関数である。引数 はラジアンである。

関連トピック:
asin(), acos(), atan(), cosh(), atan2(), tan(), sinh(), cos(), tanh()

sinh

文法:

  #include <math.h>
  double sinh( double 引数 );

sinh()は引数 のハイパボリックサインを求める関数である。

関連トピック:
asin(), acos(), atan(), cosh(), atan2(), tan(), sin(), cos(), tanh()

sqrt

文法:

  #include <math.h>
  double sqrt( double 数値 );

sqrt()数値 の平方根を返す関数である。数値 が負の場合にはdomain errorが発生する。

関連トピック:
exp(), log(), pow()

tan

文法:

  #include <math.h>
  double tan( double 引数 );

tan()は引数 のタンジェントを求める関数である。引数 はラジアンである。

関連トピック:
asin(), acos(), atan(), cosh(), atan2(), sinh(), sin(), cos(), tanh()

tanh

文法:

  #include <math.h>
  double tanh( double 引数 );

tanh()は引数 のハイパボリックタンジェントを求める関数である。

関連トピック:
asin(), acos(), atan(), cosh(), atan2(), tan(), sin(), cos(), sinh()