?
This document uses PHP Chinese website manual Release
在頭文件<math.h>中定義 | ||
---|---|---|
float frexpf(float arg,int * exp); | (1) | (自C99以來) |
double frexp(double arg,int * exp); | (2) | |
long double frexpl(long double arg,int * exp); | (3) | (自C99以來) |
在頭文件<tgmath.h>中定義 | ||
#define frexp(arg,exp) | (4) | (自C99以來) |
1-3)將給定浮點(diǎn)值x分解為歸一化分?jǐn)?shù)和2的整數(shù)冪。
4)類型 - 通用宏:如果arg的類型為long double,則調(diào)用frexpl。 否則,如果arg具有整數(shù)類型或類型double,則調(diào)用frexp。 否則,分別調(diào)用frexpf。
ARG | - | 浮點(diǎn)值 |
---|---|---|
EXP | - | 指向整數(shù)值以存儲(chǔ)指數(shù)的指針 |
如果arg為零,則返回零并在* exp中存儲(chǔ)零。
否則(如果arg不為零),如果沒有發(fā)生錯(cuò)誤,則返回范圍(-1; -0.5],[0.5; 1)中的值x并將* exp中的整數(shù)值存儲(chǔ)為x×2(* exp)
=arg.
如果要存儲(chǔ)在* exp中的值超出int范圍,則行為未指定。
如果arg不是浮點(diǎn)數(shù),則行為未指定。
此函數(shù)不受在math_errhandling中指定的任何錯(cuò)誤的影響。
如果實(shí)現(xiàn)支持IEEE浮點(diǎn)運(yùn)算(IEC 60559),
如果arg為±0,則返回,未修改,0存儲(chǔ)在* exp中。
如果arg為±∞,則返回該值,并將未指定的值存儲(chǔ)在* exp中。
如果arg是NaN,則返回NaN,并將未指定的值存儲(chǔ)在* exp中。
沒有引發(fā)浮點(diǎn)異常。
如果FLT_RADIX是2(或2的冪),則返回的值是精確的,當(dāng)前舍入模式將被忽略
在二進(jìn)制系統(tǒng)上(其中FLT_RADIX是2),frexp可以實(shí)現(xiàn)為:
{ *exp = (value == 0) ? 0 : (int)(1 + logb(value)); return scalbn(value, -(*exp));}
函數(shù)frexp及其雙重ldexp可用于操縱浮點(diǎn)數(shù)的表示,而無需直接位操作。
#include <stdio.h>#include <math.h>#include <float.h> int main(void){ double f = 123.45; printf("Given the number %.2f or %a in hex,\n", f, f); double f3; double f2 = modf(f, &f3); printf("modf() makes %.0f + %.2f\n", f3, f2); int i; f2 = frexp(f, &i); printf("frexp() makes %f * 2^%d\n", f2, i); i = ilogb(f); printf("logb()/ilogb() make %f * %d^%d\n", f/scalbn(1.0, i), FLT_RADIX, i);}
可能的輸出:
Given the number 123.45 or 0x1.edccccccccccdp+6 in hex,modf() makes 123 + 0.45frexp() makes 0.964453 * 2^7logb()/ilogb() make 1.92891 * 2^6
C11標(biāo)準(zhǔn)(ISO / IEC 9899:2011):
7.12.6.4 frexp函數(shù)(p:243)
7.25類型通用數(shù)學(xué)<tgmath.h>(p:373-375)
F.10.3.4 frexp函數(shù)(p:521)
C99標(biāo)準(zhǔn)(ISO / IEC 9899:1999):
7.12.6.4 frexp函數(shù)(p:224)
7.22類型通用數(shù)學(xué)<tgmath.h>(p:335-337)
F.9.3.4 frexp函數(shù)(p:458)
C89 / C90標(biāo)準(zhǔn)(ISO / IEC 9899:1990):
4.5.4.2 frexp函數(shù)
ldexpldexpfldexpl(C99)(C99) | 將一個(gè)數(shù)字乘以2來提高權(quán)力(功能) |
---|---|
logblogbflogbl(C99)(C99)(C99) | 提取給定數(shù)字的指數(shù)(函數(shù)) |
ilogbilogbfilogbl(C99)(C99)(C99) | 提取給定數(shù)字的指數(shù)(函數(shù)) |
modfmodffmodfl(C99)(C99) | 將數(shù)字分成整數(shù)和小數(shù)部分(函數(shù)) |
| 用于frexp的C ++文檔 |