gcc-ARM交叉編譯器死活不支持math.h中的isnormal、isfinite兩個宏

 最近寫了個應用程序,其中用到了math.h中的不少函數,包括檢查一個浮點數是否是正常數,或者檢查一個浮點數是否是有限的。這兩個宏分別是isnormal和isfinite,在PC上本地編譯運行後結果徹底正確,可是交叉編譯時卻死活不支持這兩個宏,我前後嘗試了幾個版本的gcc交叉編譯器,包括4.3.2  4.4.3  3.4.5等幾個版本。在Google上Search了很久也沒有答案,卻是Search出來了windows平臺下的防UNIX環境軟件cygwin在這兩個宏有問題。最後只能換成isnan、isinf這兩個宏代替,編譯能夠經過。html

  浮點數在運算中可能產生一些特殊的值,有關這方面的定義能夠看一些manpage的解釋:express

複製代碼

NAME
fpclassify, isfinite, isnormal, isnan, isinf - floating-point classification macroswindows

SYNOPSIS
#include <math.h>ide

int fpclassify(x);函數

int isfinite(x);ui

int isnormal(x);orm

int isnan(x);htm

int isinf(x);blog

Link with -lm.ci

Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

fpclassify(), isfinite(), isnormal(): _XOPEN_SOURCE >= 600 || _ISOC99_SOURCE; or cc -std=c99
isnan(): _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE || _ISOC99_SOURCE; or cc -std=c99
isinf(): _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE >= 600 || _ISOC99_SOURCE; or cc -std=c99

DESCRIPTION
Floating point numbers can have special values, such as infinite or NaN. With the macro fpclassify(x) you can
find out what type x is. The macro takes any floating-point expression as argument. The result is one of the
following values:

FP_NAN x is "Not a Number".

FP_INFINITE x is either positive infinity or negative infinity.

FP_ZERO x is zero.

FP_SUBNORMAL x is too small to be represented in normalized format.

FP_NORMAL if nothing of the above is correct then it must be a normal floating-point number.

The other macros provide a short answer to some standard questions.

isfinite(x) returns a non-zero value if
(fpclassify(x) != FP_NAN && fpclassify(x) != FP_INFINITE)

isnormal(x) returns a non-zero value if (fpclassify(x) == FP_NORMAL)

isnan(x) returns a non-zero value if (fpclassify(x) == FP_NAN)

isinf(x) returns 1 if x is positive infinity, and -1 if x is negative infinity.

CONFORMING TO
C99, POSIX.1.

For isinf(), the standards merely say that the return value is non-zero if and only if the argument has an infi‐
nite value.

複製代碼

能夠看出來,浮點數計算中可能產生這五種異常 「FP_NAN FP_INFINITE   FP_ZERO   FP_SUBNORMAL   FP_NORMAL」 ,這些異常值繼續計算是出錯的。所以須要排除這些值,或者對此進行一些處理,所以定義了一些宏函數來進行檢測。

在沒有硬浮點協處理器支持的ARM平臺上,須要軟浮點技術進行浮點數運算(其實就是一個庫函數)。這方面可能有一些問題存在須要詳細瞭解。。

 

分類: Linux

相關文章
相關標籤/搜索