功能fpclassify(x) == FP_NAN
上等同于?isnan(x)
同样的问题适用于:
fpclassify(x) == FP_INFINITE
对比isinf(x)
fpclassify(x) == FP_NORMAL
对比isnormal(x)
fpclassify(x) == FP_SUBNORMAL
对比issubnormal(x)
fpclassify(x) == FP_ZERO
对比iszero(x)
如果它们在功能上是等效的,那么为什么需要重复呢?
功能fpclassify(x) == FP_NAN
上等同于?isnan(x)
同样的问题适用于:
fpclassify(x) == FP_INFINITE
对比isinf(x)
fpclassify(x) == FP_NORMAL
对比isnormal(x)
fpclassify(x) == FP_SUBNORMAL
对比issubnormal(x)
fpclassify(x) == FP_ZERO
对比iszero(x)
如果它们在功能上是等效的,那么为什么需要重复呢?
它们在功能上是等效的。但是fpclassify
允许您执行单个测试并使用一个switch
语句,这可能比链式 // 块用于执行逐个类型检查的速度稍快和/或生成更简单的代码if
(假设else if
它自己有有效的方法来区分自己;不会t 发誓),例如根据cppreference 示例:else
fpclassify
const char *show_classification(double x) {
switch(fpclassify(x)) {
case FP_INFINITE: return "Inf";
case FP_NAN: return "NaN";
case FP_NORMAL: return "normal";
case FP_SUBNORMAL: return "subnormal";
case FP_ZERO: return "zero";
default: return "unknown";
}
}