?
Dieses Dokument verwendet PHP-Handbuch für chinesische Websites Freigeben
在頭文件<math.h>中定義 | ||
---|---|---|
float scalbnf( float arg, int exp ); | (1) | (since C99) |
double scalbn( double arg, int exp ); | (2) | (since C99) |
long double scalbnl( long double arg, int exp ); | (3) | (since C99) |
Defined in header <tgmath.h> | ||
#define scalbn( arg, exp ) | (4) | (since C99) |
Defined in header <math.h> | ||
float scalblnf( float arg, long exp ); | (5) | (since C99) |
double scalbln( double arg, long exp ); | (6) | (since C99) |
long double scalblnl( long double arg, long exp ); | (7) | (since C99) |
Defined in header <tgmath.h> | ||
#define scalbln( arg, exp ) | (8) | (since C99) |
1-3,5-7)將浮點(diǎn)值arg
乘以FLT_RADIX
功率exp
。
4,8)型,通用宏:如果arg
有型long double
,scalbnl
或scalblnl
叫。否則,如果arg
有整數(shù)類型或類型double
,scalbn
或者scalbln
被調(diào)用。否則,scalbnf
或scalblnf
分別被調(diào)用。
arg | - | 浮點(diǎn)值 |
---|---|---|
exp | - | 整數(shù)值 |
如果沒有出現(xiàn)錯誤,arg
乘以FLT_RADIX
給力exp
(ARG×FLT_RADIXexp
)返回。
如果范圍誤差由于發(fā)生溢出,±HUGE_VAL
,±HUGE_VALF
,或±HUGE_VALL
返回。
如果發(fā)生下溢引起的范圍錯誤,則返回正確的結(jié)果(舍入后)。
按照math_errhandling中的指定報告錯誤。
如果實(shí)現(xiàn)支持IEEE浮點(diǎn)運(yùn)算(IEC 60559),
除非發(fā)生范圍錯誤,否則FE_INEXACT
不會引發(fā)(結(jié)果是確切的)
除非發(fā)生范圍錯誤,否則當(dāng)前舍入模式將被忽略
如果arg
為±0,則返回,未修改
如果arg
是±∞,則返回,未修改
如果exp
為0,則arg
返回,未修改
如果arg
是NaN,則返回NaN
二進(jìn)制系統(tǒng)(其中,FLT_RADIX
是2
),scalbn
相當(dāng)于ldexp
。
雖然std::scalbn
并被std::scalbln
指定為有效地執(zhí)行操作,但在許多實(shí)現(xiàn)中,它們比使用算術(shù)運(yùn)算符的乘法或乘除法的效率要低。
scalbln
提供該函數(shù)是因為從最小正浮點(diǎn)值縮放到最大有限值所需的因子可能大于標(biāo)準(zhǔn)保證的32767 INT_MAX
。特別是對于80位long double
,因子是32828。
GNU的實(shí)現(xiàn)不設(shè)置errno
不分math_errhandling
。
#include <stdio.h>#include <math.h>#include <float.h>#include <errno.h>#include <fenv.h>#pragma STDC FENV_ACCESS ON int main(void){ printf("scalbn(7, -4) = %f\n", scalbn(7, -4)); printf("scalbn(1, -1074) = %g (minimum positive subnormal double)\n", scalbn(1, -1074)); printf("scalbn(nextafter(1,0), 1024) = %g (largest finite double)\n", scalbn(nextafter(1,0), 1024)); // special values printf("scalbn(-0, 10) = %f\n", scalbn(-0.0, 10)); printf("scalbn(-Inf, -1) = %f\n", scalbn(-INFINITY, -1)); //error handling errno = 0; feclearexcept(FE_ALL_EXCEPT); printf("scalbn(1, 1024) = %f\n", scalbn(1, 1024)); if(errno == ERANGE) perror(" errno == ERANGE"); if(fetestexcept(FE_OVERFLOW)) puts(" FE_OVERFLOW raised");}
可能的輸出:
scalbn(7, -4) = 0.437500scalbn(1, -1074) = 4.94066e-324 (minimum positive subnormal double)scalbn(nextafter(1,0), 1024) = 1.79769e+308 (largest finite double)scalbn(-0, 10) = -0.000000scalbn(-Inf, -1) = -infscalbn(1, 1024) = inf errno == ERANGE: Numerical result out of range FE_OVERFLOW raised
C11標(biāo)準(zhǔn)(ISO / IEC 9899:2011):
7.12.6.13 scalbn函數(shù)(p:247)
7.25類型通用數(shù)學(xué)<tgmath.h>(p:373-375)
F.10.3.13 scalbn函數(shù)(p:523)
C99標(biāo)準(zhǔn)(ISO / IEC 9899:1999):
7.12.6.13 scalbn函數(shù)(p:228)
7.22類型通用數(shù)學(xué)<tgmath.h>(p:335-337)
F.9.3.13 scalbn函數(shù)(p:460)