scalbn, scalbnf, scalbnl, scalbln, scalblnf, scalblnl

将浮点数乘以 FLT_RADIX 的整数幂。

语法

double scalbn(
   double x,
   int exp
);
float scalbn(
   float x,
   int exp
);  // C++ only
long double scalbn(
   long double x,
   int exp
);  // C++ only
float scalbnf(
   float x,
   int exp
);
long double scalbnl(
   long double x,
   int exp
);

#define scalbn(X, INT) // Requires C11 or higher

double scalbln(
   double x,
   long exp
);

float scalblnf(
   float x,
   long exp
);
long double scalblnl(
   long double x,
   long exp
);

#define scalbln(X, LONG) // Requires C11 or higher

float scalbln(
   float x,
   long exp
);  // C++ only
long double scalbln(
   long double x,
   long exp
);  // C++ only

参数

x
浮点值。

exp
整数指数。

返回值

如果成功,scalbn 函数将返回 x * FLT_RADIXexp 的值。 溢出时(根据 x 的符号),scalbn 将返回 +/- HUGE_VAL;将 errno 值设置为 ERANGE

有关 errno 和可能的错误返回值的详细信息,请参阅 errno_doserrno_sys_errlist_sys_nerr

备注

在 <float.h> 中将 FLT_RADIX 定义为本机浮点基数;在二进制系统上,它具有值 2,并且 scalbn 等效于 ldexp

由于 C++ 支持重载,你可调用采用并返回 floatlong double 类型的 scalbnscalbln 重载。 在 C 程序中,除非你使用 <tgmath.h> 宏来调用此函数,否则 scalbn 始终采用 doubleint 并返回 double,而 scalbln 始终采用 doublelong 并返回 double

如果使用 <tgmath.h>scalbn()scalbln 宏,则参数的类型将决定选择哪个版本的函数。 有关详细信息,请参阅泛型类型数学

默认情况下,此函数的全局状态范围限定为应用程序。 若要更改此行为,请参阅 CRT 中的全局状态

要求

函数 C 标头 C++ 标头
scalbn, scalbnf, scalbnl, scalbln, scalblnf, scalblnl <math.h> <cmath>
scalbnscalbln <tgmath.h>

有关兼容性的详细信息,请参阅 兼容性

示例

// crt_scalbn.c
// Compile using: cl /W4 crt_scalbn.c
#include <math.h>
#include <stdio.h>

int main( void )
{
   double x = 6.4, y;
   int p = 3;

   y = scalbn( x, p );
   printf( "%2.1f times FLT_RADIX to the power of %d is %2.1f\n", x, p, y );
}

输出

6.4 times FLT_RADIX to the power of 3 is 51.2

另请参阅

数学和浮点支持
frexp
ldexp
modfmodffmodfl