---
title: invsqrt
description: "计算x的平方根的倒数。"
url: https://www.hikunpeng.com/document/detail/zh/hpchistory/hpckit/develop2400/kunpengaccel_kml_0200.html
sourcePath: /source/zh/hpchistory/hpckit/develop2400/kunpengaccel_kml_0200.html
indexId: 824986f9472078b3c5e3ba4e590adb6c6446a6eac571dd64d91501206ae07c4e67
---
# invsqrt

计算x的平方根的倒数。

#### 接口定义

C interface：

float invsqrtf(float x);

double invsqrt(double x);

long double invsqrtl(long double x);

Fortran interface：

RES = SQRTF(X);

RES = SQRT(X);


#### 参数

| 参数名 | 类型 | 描述 | 输入/输出 |
| --- | --- | --- | --- |
| x | 在invsqrtf中，x是单精度浮点类型。 在invsqrt中，x是双精度浮点类型。 在invsqrtl中，x是长双精度浮点类型。 | 表示输入数据的浮点值。 | 输入 |


#### 返回值

- 输入x为+0，返回+∞。
- 输入x为-0，返回-∞。
- 输入x<0，返回nan。
- 输入x为+∞，返回0.0。
- 输入x为nan，返回nan。


#### 依赖

C: "km.h"


#### 示例

C interface：

```
// typical usage 
    double x1 = 1.0, x2 = 2.0, x3 = 3.0, x4 = 4.0; 
    // special handing 
    double a = 0.0, b = INFINITY, c = -INFINITY, d = NAN; 
    // print result 
        printf("invsqrt(1.0) = %.15f\n", invsqrt(x1)); 
        printf("invsqrt(2.0) = %.15f\n", invsqrt(x2)); 
        printf("invsqrt(3.0) = %.15f\n", invsqrt(x3)); 
        printf("invsqrt(4.0) = %.15f\n", invsqrt(x4)); 
        printf("invsqrt(0.0) = %.15f\n", invsqrt(a)); 
        printf("invsqrt(INFINITY) = %.15f\n", invsqrt(b)); 
        printf("invsqrt(-INFINITY) = %.15f\n", invsqrt(c)); 
        printf("invsqrt(NAN) = %.15f\n", invsqrt(d)); 
    /* 
     *  invsqrt(1.0) = 1.000000000000000 
     *  invsqrt(2.0) = 0.707106781186548 
     *  invsqrt(3.0) = 0.577350269189626 
     *  invsqrt(4.0) = 0.500000000000000 
     *  invsqrt(0.0) = inf 
     *  invsqrt(INFINITY) = 0.000000000000000 
     *  invsqrt(-INFINITY) = nan
     *  invsqrt(NAN) = nan 
     * */
```
