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是整数类型指针。

指数。

输出

返回值

依赖

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
     * */