?
This document uses PHP Chinese website manual Release
在頭文件<math.h>中定義 | ||
---|---|---|
float logbf( float arg ); | (1) | (since C99) |
double logb( double arg ); | (2) | (since C99) |
long double logbl( long double arg ); | (3) | (since C99) |
Defined in header <tgmath.h> | ||
#define logb( arg ) | (4) | (since C99) |
1-3)從浮點參數(shù)中提取無偏基本獨立的指數(shù)的值arg
,并將其作為浮點值返回。
4)類型 - 通用宏:如果arg
有類型long double
,logbl
則被調用。否則,如果arg
有整數(shù)類型或類型double
,logb
則調用。否則,logbf
被調用。
形式上,無偏指數(shù)是log的有符號整數(shù)部分
[R |阿根廷| (由此函數(shù)作為浮點值返回),對于非零arg,其中r
是FLT_RADIX
。如果arg
低于正常水平,則將其視為正?;?。
arg | - | 浮點值 |
---|
如果沒有錯誤發(fā)生,則無偏指數(shù)arg
作為帶符號的浮點值返回。
如果發(fā)生域錯誤,則返回實現(xiàn)定義的值。
如果發(fā)生極錯誤-HUGE_VAL
,-HUGE_VALF
或-HUGE_VALL
返回。
按照math_errhandling中的指定報告錯誤。
如果arg
為零,則可能會出現(xiàn)域或范圍錯誤。
如果實現(xiàn)支持IEEE浮點運算(IEC 60559),
如果arg
是±0,-∞返回并且FE_DIVBYZERO
被提升。
如果arg
是±∞,則返回+∞
如果arg
是NaN,則返回NaN。
在所有其他情況下,結果是確切的(FE_INEXACT
從不會提高),并且忽略當前舍入模式
如果arg
是±0 ,POSIX要求發(fā)生極點錯誤。
由于歸一化要求不同,返回的指數(shù)的值logb
總是小于指數(shù)的返回值frexp
:對于e
返回的指數(shù)logb
,| arg * re
| 介于1和r
(通常介于1
和之間2
),但對于e
由frexp
| arg * 2-e 返回的指數(shù)
| 介于0.5
和之間1
。
比較不同的浮點分解函數(shù)。
#include <stdio.h>#include <math.h>#include <float.h>#include <fenv.h> #pragma STDC FENV_ACCESS ON 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 = logb(f); printf("logb()/logb() make %f * %d^%d\n", f/scalbn(1.0, i), FLT_RADIX, i); // error handling feclearexcept(FE_ALL_EXCEPT); printf("logb(0) = %f\n", logb(0)); if(fetestexcept(FE_DIVBYZERO)) puts(" FE_DIVBYZERO raised");}
可能的輸出:
Given the number 123.45 or 0x1.edccccccccccdp+6 in hex,modf() makes 123 + 0.45frexp() makes 0.964453 * 2^7logb()/logb() make 1.928906 * 2^6logb(0) = -Inf FE_DIVBYZERO raised
C11標準(ISO / IEC 9899:2011):
7.12.6.11 logb函數(shù)(p:246)
7.25類型通用數(shù)學<tgmath.h>(p:373-375)
F.10.3.11 logb函數(shù)(p:522)
C99標準(ISO / IEC 9899:1999):
7.12.6.11 logb函數(shù)(p:227)
7.22類型通用數(shù)學<tgmath.h>(p:335-337)
F.9.3.11 logb函數(shù)(p:459)