非常教程

C参考手册

数值 | Numerics

cbrtl

在头文件<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不能将负基底提升为小数指数。

#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));
}

输出:

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

C 语言是一门通用计算机编程语言,应用广泛。C 语言的设计目标是提供一种能以简易的方式编译、处理低级存储器、产生少量的机器码以及不需要任何运行环境支持便能运行的编程语言。