Namespaces
Variants

std:: cbrt, std:: cbrtf, std:: cbrtl

From cppreference.net
Common mathematical functions
Nearest integer floating point operations
(C++11)
(C++11)
(C++11) (C++11) (C++11)
Floating point manipulation functions
(C++11) (C++11)
(C++11)
(C++11)
Classification and comparison
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Types
(C++11)
(C++11)
(C++11)
Macro constants
ヘッダーで定義 <cmath>
(1)
float cbrt ( float num ) ;

double cbrt ( double num ) ;

long double cbrt ( long double num ) ;
(C++23まで)
/*floating-point-type*/
cbrt ( /*floating-point-type*/ num ) ;
(C++23から)
(constexpr C++26から)
float cbrtf ( float num ) ;
(2) (C++11から)
(constexpr C++26から)
long double cbrtl ( long double num ) ;
(3) (C++11から)
(constexpr C++26から)
ヘッダーで定義 <simd>
template < /*math-floating-point*/ V >

constexpr /*deduced-simd-t*/ < V >

cbrt ( const V & v_num ) ;
(S) (C++26から)
ヘッダーで定義 <cmath>
template < class Integer >
double cbrt ( Integer num ) ;
(A) (constexpr C++26から)
1-3) num の立方根を計算します。 ライブラリは、パラメータの型としてすべてのcv修飾されていない浮動小数点型に対する std::cbrt のオーバーロードを提供します。 (C++23以降)
S) SIMDオーバーロードは v_num に対して要素ごとに std::cbrt を実行します。
(詳細は math-floating-point および deduced-simd-t を参照)
(C++26以降)
A) すべての整数型に対して追加のオーバーロードが提供されており、これらは double として扱われます。
(since C++11)

目次

翻訳の説明: - 「Contents」を「目次」に翻訳しました - HTMLタグ、属性、
タグ内のテキストは翻訳していません
- C++固有の用語(Parameters、Return value、Error handling、Notes、Example、See also)は原文のまま保持しました
- 元のフォーマットと構造を完全に保持しています

パラメータ

num - 浮動小数点または整数値

戻り値

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

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

エラー処理

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

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

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

注記

std :: cbrt ( num ) is not equivalent to std:: pow ( num, 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, std :: cbrt ( num ) usually gives more accurate results than std:: pow ( num, 1.0 / 3 ) (see example).

追加のオーバーロードは (A) と完全に同一である必要はありません。整数型の引数 num に対して、 std :: cbrt ( num ) std :: cbrt ( static_cast < double > ( num ) ) と同じ効果を持つことを保証するのに十分なものであればよいのです。

#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
int main()
{
    std::cout
        << "通常の使用:\n"
        << "cbrt(729)       = " << std::cbrt(729) << '\n'
        << "cbrt(-0.125)    = " << std::cbrt(-0.125) << '\n'
        << "特殊な値:\n"
        << "cbrt(-0)        = " << std::cbrt(-0.0) << '\n'
        << "cbrt(+inf)      = " << std::cbrt(INFINITY) << '\n'
        << "精度と`pow`との比較:\n"
        << std::setprecision(std::numeric_limits<double>::max_digits10)
        << "cbrt(343)       = " << std::cbrt(343) << '\n'
        << "pow(343,1.0/3)  = " << std::pow(343, 1.0 / 3) << '\n'
        << "cbrt(-343)      = " << std::cbrt(-343) << '\n'
        << "pow(-343,1.0/3) = " << std::pow(-343, 1.0 / 3) << '\n';
}

出力例:

通常の使用:
cbrt(729)       = 9
cbrt(-0.125)    = -0.5
特殊な値:
cbrt(-0)        = -0
cbrt(+inf)      = inf
精度と`pow`との比較:
cbrt(343)       = 7
pow(343,1.0/3)  = 6.9999999999999991
cbrt(-343)      = -7
pow(-343,1.0/3) = -nan

関連項目

(C++11) (C++11)
数値を指定された累乗に引き上げる ( x y )
(関数)
(C++11) (C++11)
平方根を計算する ( x )
(関数)
(C++11) (C++11) (C++11)
斜辺を計算する x 2
+y 2
および x 2
+y 2
+z 2
(C++17以降)

(関数)