【发布时间】:2017-11-06 15:59:16
【问题描述】:
int is_infinity/is_zero/is_denormal(float f){
//do something, return 0 or 1
}
这就是我检查float 是否为负数的方法。我想为其他功能做类似的事情,但我不确定如何。
int is_negative(float val){
union sp_object copy;
copy.frep = val;
if((copy.irep & 0x80000000) != 0)
return 1;
else
return 0;
}
【问题讨论】:
-
std::isinf等。如果你追求各种价值观,也许是std::fpclassify。 -
@FrançoisAndrieux - 没关系。
fpclassify是 C 标准库的一部分。 -
@StoryTeller
std::fpclassify不是 -
查看函数here。具体在分类和比较部分
-
@HOHO 如果你不需要的话,你真的不想进入位域。 C99 为您提供了更简单的方法
标签: c floating-point