Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
fpclassify(x)=FP_NAN在功能上等同于isnan(x)?_C_Floating Point_C17 - Fatal编程技术网

fpclassify(x)=FP_NAN在功能上等同于isnan(x)?

fpclassify(x)=FP_NAN在功能上等同于isnan(x)?,c,floating-point,c17,C,Floating Point,C17,fpclassify(x)==FP_NAN在功能上是否等同于isnan(x) 同样的问题也适用于: fpclassify(x)==FP_INFINITEvs.isinf(x) fpclassify(x)==FP_NORMALvs.isnormal(x) fpclassify(x)==FP_次正常vs.issubnormal(x) fpclassify(x)==FP\uzerovs.iszero(x) 如果它们在功能上是等价的,那么为什么需要复制品呢?它们在功能上是等价的。但是fpclassi

fpclassify(x)==FP_NAN
在功能上是否等同于
isnan(x)

同样的问题也适用于:

  • fpclassify(x)==FP_INFINITE
    vs.
    isinf(x)
  • fpclassify(x)==FP_NORMAL
    vs.
    isnormal(x)
  • fpclassify(x)==FP_次正常
    vs.
    issubnormal(x)
  • fpclassify(x)==FP\uzero
    vs.
    iszero(x)

如果它们在功能上是等价的,那么为什么需要复制品呢?

它们在功能上是等价的。但是
fpclassify
允许您执行单个测试并使用
switch
语句,与链式
if
/
else if
/
else
块用于执行逐类型检查相比,该语句可能稍快和/或生成更简单的代码(假设
fpclassify
本身有有效的方法来区分自己;不会发誓),例如:


相反,在只需要一次特定检查的情况下,这很可能比使用
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";
    }
}