cbrt, cbrtf, cbrtl
From cppreference.net
Common mathematical functions
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定义于头文件
<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
的立方根(
\(\small{\sqrt[3]{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 \(\small{\frac1{3} }\)| 1 |
| 3 |
示例
运行此代码
#include <float.h> #include <math.h> #include <stdio.h> int main(void) { printf("常规用法:\n" "cbrt(729) = %f\n", cbrt(729)); printf("cbrt(-0.125) = %f\n", cbrt(-0.125)); printf("特殊值:\n" "cbrt(-0) = %f\n", cbrt(-0.0)); printf("cbrt(+inf) = %f\n", cbrt(INFINITY)); printf("精度:\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)); }
可能的输出:
常规用法: cbrt(729) = 9.000000 cbrt(-0.125) = -0.500000 特殊值: cbrt(-0) = -0.000000 cbrt(+inf) = inf 精度: 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函数(页码:228)
-
- 7.22 泛型数学 <tgmath.h>(页码:335-337)
-
- F.9.4.1 cbrt函数(页码:460)
参见
|
(C99)
(C99)
|
计算一个数的指定次幂 (
\(\small{x^y}\)
x
y
)
(函数) |
|
(C99)
(C99)
|
计算平方根 (
\(\small{\sqrt{x} }\)
√
x
)
(函数) |
|
(C99)
(C99)
(C99)
|
计算两个给定数平方和的平方根 (
\(\scriptsize{\sqrt{x^2+y^2} }\)
√
x
2
+y 2 ) (函数) |
|
C++ documentation
for
cbrt
|
|