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

相关文章
相关标签/搜索