---
title: cbrt
description: "计算x的立方根。"
url: https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_0204.html
sourcePath: /source/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_0204.html
indexId: 7510b72a7c9a532db9747cccbb55a986e69a720952c8c8900ded463c027d77bf61
---
# cbrt

计算x的立方根。

#### 接口定义

C interface：

float cbrtf(float x);

double cbrt(double x);

double cbrt_18(double x);

long double cbrtl(long double x);

cbrt_18仅在高精度版本提供。


Fortran interface：

RES = CBRTF(X);

RES = CBRT(X);


#### 参数

| 参数名 | 类型 | 描述 | 输入/输出 |
| --- | --- | --- | --- |
| x | 在cbrtf中，x是单精度浮点类型。 在cbrt和cbrt\_18中，x是双精度浮点类型。 在cbrtl中，x是长双精度浮点类型。 | 表示输入数据的浮点值。 | 输入 |


#### 返回值

- 输入x为±0，返回±0。
- 输入x为±∞，返回±∞。
- 输入x为nan，返回nan。


#### 依赖

C: "km.h"


#### 示例

C interface：```
// typical usage 
    double x1 = 1.0, x2 = 2.0, x3 = 3.0, x4 = 4.0; 
    // special handling 
    double a = 0.0, b = INFINITY, c = -INFINITY, d = NAN; 
    // print result 
        printf("cbrt(1.0) = %.15f\n", cbrt(x1)); 
        printf("cbrt(2.0) = %.15f\n", cbrt(x2)); 
        printf("cbrt(3.0) = %.15f\n", cbrt(x3)); 
        printf("cbrt(4.0) = %.15f\n", cbrt(x4)); 
        printf("cbrt(0.0) = %.15f\n", cbrt(a)); 
        printf("cbrt(INFINITY) = %.15f\n", cbrt(b)); 
        printf("cbrt(-INFINITY) = %.15f\n", cbrt(c)); 
        printf("cbrt(NAN) = %.15f\n", cbrt(d)); 
    /* 
     *  
     *  cbrt(1.0) = 1.000000000000000
     *  cbrt(2.0) = 1.259921049894873
     *  cbrt(3.0) = 1.442249570307408
     *  cbrt(4.0) = 1.587401051968200
     *  cbrt(0.0) = 0.000000000000000
     *  cbrt(INFINITY) = inf
     *  cbrt(-INFINITY) = -inf
     *  cbrt(NAN) = nan
 
     * */
```


Fortran interface：

```
REAL(8) :: X = 3.0
PRINT*,  CBRT(X)
!
! OUTPUT
!     1.442249570307408
!
```
