首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

cbrt

在头文件<math.h>中定义

float cbrtf( float arg );

(1)

(since C99)

double cbrt( double arg );

(2)

(since C99)

long double cbrtl( long double arg );

(3)

(since C99)

Defined in header <tgmath.h>

#define cbrt( arg )

(4)

(since C99)

1-3)计算的立方根arg

4)类型 - 通用宏:如果arg有类型long doublecbrtl被调用。否则,如果arg有整数类型或类型doublecbrt则调用。否则,cbrtf被调用。

参数

arg

-

浮点值

返回值

如果没有错误发生arg,则返回(3√arg)的立方根。

如果由于下溢而发生范围错误,则返回正确的结果(舍入后)。

错误处理

按照math_errhandling中的指定报告错误。

如果实现支持IEEE浮点运算(IEC 60559),

  • 如果参数为±0或±∞,则返回,不变
  • 如果参数是NaN,则返回NaN。

笔记

cbrt(arg)并不等同于pow(arg, 1.0/3)因为pow不能将负基底提升为小数指数。

代码语言:javascript
复制
#include <stdio.h>
#include <math.h>
 
int main(void)
{
    // normal use
    printf("cbrt(729) = %f\n", cbrt(729));
    printf("cbrt(-0.125) = %f\n", cbrt(-0.125));
    // special values
    printf("cbrt(-0) = %f\n", cbrt(-0.0));
    printf("cbrt(+inf) = %f\n", cbrt(INFINITY));
}

输出:

代码语言:javascript
复制
cbrt(729) = 9.000000
cbrt(-0.125) = -0.500000
cbrt(-0) = -0.000000
cbrt(+inf) = inf

参考

  • 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)

扫码关注腾讯云开发者

领取腾讯云代金券