Namespaces
Variants

cbrt, cbrtf, cbrtl

From cppreference.net
< c ‎ | numeric ‎ | math
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99) (C99) (C99) (C23)
Maximum/minimum operations
Exponential functions
Power functions
cbrt
(C99)
(C23)
(C23)

Trigonometric and hyperbolic functions
Nearest integer floating-point
(C99) (C99) (C99)
(C23) (C23) (C23) (C23)
Floating-point manipulation
Narrowing operations
(C23)
(C23)
(C23)
(C23)
(C23)
(C23)
Quantum and quantum exponent
Decimal re-encoding functions
Total order and payload functions
Classification
Error and gamma functions
(C99)
(C99)
(C99)
(C99)
Types
Macro constants
Special floating-point values
Arguments and return values
Error handling
Fast operation indicators
ヘッダー <math.h> で定義
float cbrtf ( float arg ) ;
(1) (C99以降)
double cbrt ( double arg ) ;
(2) (C99以降)
long double cbrtl ( long double arg ) ;
(3) (C99以降)
ヘッダー <tgmath.h> で定義
#define cbrt( arg )
(4) (C99以降)
1-3) arg の立方根を計算します。
4) 型総称マクロ: arg の型が long double の場合、 cbrtl が呼び出される。それ以外の場合、 arg が整数型または double 型を持つ場合、 cbrt が呼び出される。それ以外の場合、 cbrtf が呼び出される。

目次

パラメータ

arg - 浮動小数点値

戻り値

エラーが発生しない場合、 arg の立方根( 3 arg )が返されます。

アンダーフローによる範囲エラーが発生した場合、正しい結果(丸め後)が返されます。

エラーハンドリング

エラーは math_errhandling で指定された通りに報告されます。

IEEE浮動小数点演算(IEC 60559)を実装がサポートしている場合、

  • 引数が±0または±∞の場合、変更されずに返されます
  • 引数がNaNの場合、NaNが返されます。

注記

cbrt ( arg ) is not equivalent to pow ( arg, 1.0 / 3 ) because the rational number
1
3
is typically not equal to 1.0 / 3 and std::pow cannot raise a negative base to a fractional exponent. Moreover, cbrt ( arg ) usually gives more accurate results than pow ( arg, 1.0 / 3 ) (see example).

#include <float.h>
#include <math.h>
#include <stdio.h>
int main(void)
{
    printf("Normal use:\n"
           "cbrt(729)      = %f\n", cbrt(729));
    printf("cbrt(-0.125)   = %f\n", cbrt(-0.125));
    printf("Special values:\n"
           "cbrt(-0)       = %f\n", cbrt(-0.0));
    printf("cbrt(+inf)     = %f\n", cbrt(INFINITY));
    printf("Accuracy:\n"
           "cbrt(343)      = %.*f\n", DBL_DECIMAL_DIG, cbrt(343));
    printf("pow(343,1.0/3) = %.*f\n", DBL_DECIMAL_DIG, pow(343, 1.0/3));
}

出力例:

Normal use:
cbrt(729)      = 9.000000
cbrt(-0.125)   = -0.500000
Special values:
cbrt(-0)       = -0.000000
cbrt(+inf)     = inf
Accuracy:
cbrt(343)      = 7.00000000000000000
pow(343,1.0/3) = 6.99999999999999911

参考文献

  • C23規格 (ISO/IEC 9899:2024):
  • 7.12.7.1 cbrt関数群 (p: TBD)
  • 7.25 総称数学 <tgmath.h> (p: TBD)
  • F.10.4.1 cbrt関数群 (p: TBD)
  • C17規格 (ISO/IEC 9899:2018):
  • 7.12.7.1 cbrt関数群 (p: 180-181)
  • 7.25 総称数学 <tgmath.h> (p: 272-273)
  • F.10.4.1 cbrt関数群 (p: 381-)
  • C11規格 (ISO/IEC 9899:2011):
  • 7.12.7.1 cbrt関数群 (p: 247)
  • 7.25 総称数学 <tgmath.h> (p: 373-375)
  • F.10.4.1 cbrt関数群 (p: 524)
  • C99規格 (ISO/IEC 9899:1999):
  • 7.12.7.1 cbrt関数群 (p: 228)
  • 7.22 総称数学 <tgmath.h> (p: 335-337)
  • F.9.4.1 cbrt関数群 (p: 460)

関連項目

(C99) (C99)
指定された累乗を計算する ( x y )
(関数)
(C99) (C99)
平方根を計算する ( x )
(関数)
(C99) (C99) (C99)
2つの数値の二乗和の平方根を計算する ( x 2
+y 2
)
(関数)