---
title: frexp
description: "将x转换为归一化[1/2, 1)的有符号数乘以2的积分幂。返回归一化的有符号数，指数存储在exp中。"
url: https://www.hikunpeng.com/document/detail/zh/hpchistory/hpckit/develop2400/kunpengaccel_kml_0181.html
sourcePath: /source/zh/hpchistory/hpckit/develop2400/kunpengaccel_kml_0181.html
indexId: aeeaebe0dda6c3282de8b7e42cdcb529461c89476cd9255d1551201e7f8491c667
---
# frexp

将x转换为归一化[1/2, 1)的有符号数乘以2的积分幂。返回归一化的有符号数，指数存储在exp中。

#### 接口定义

C interface：

float frexpf(float x, int *exp);

double frexp(double x, int *exp);

long double frexpl(long double x, int *exp);


#### 参数

| 参数名 | 类型 | 描述 | 输入/输出 |
| --- | --- | --- | --- |
| x | 在frexpf中，x是单精度浮点类型。 在frexp中，x是双精度浮点类型。 在frexpl中，x是长双精度浮点类型。 | 表示输入数据的浮点值。 | 输入 |
| exp | exp是整数类型指针。 | 指数。 | 输出 |


#### 返回值

- 将x转换为归一化[1/2, 1)的有符号数乘以2的积分幂。返回归一化的有符号数，指数存储在exp中。
- 输入x为inf，返回inf，exp值无意义。
- 输入x为-inf，返回-inf，exp值无意义。
- 输入x为nan，返回nan，exp值无意义。


#### 依赖

C: "km.h"


#### 示例

C interface：```
// print result
    int32_t exp;
    printf("frexp(3.4, &exp) = %.15f, exp = %d\n", frexp(3.4, &exp), exp);
    printf("frexp(-4.8, &exp) = %.15f, exp = %d\n", frexp(-4.8, &exp), exp);
    printf("frexp(NAN, &exp) = %.15f, exp = %d\n", frexp(NAN, &exp), exp);
    printf("frexp(-NAN, &exp) = %.15f, exp = %d\n", frexp(-NAN, &exp), exp);
    printf("frexp(INFINITY, &exp) = %.15f, exp = %d\n", frexp(INFINITY, &exp), exp);
    printf("frexp(-INFINITY, &exp) = %.15f, exp = %d\n", frexp(-INFINITY, &exp), exp);

result
    /* 
     * frexp(3.4, &exp) = 0.850000000000000, exp = 2
     * frexp(-4.8, &exp) = -0.600000000000000, exp = 3
     * frexp(NAN, &exp) = nan, exp = 3
     * frexp(-NAN, &exp) = -nan, exp = 3
     * frexp(INFINITY, &exp) = inf, exp = 3
     * frexp(-INFINITY, &exp) = -inf, exp = 3
     * */
```
