Argument order to std::min changes compiler output for floating-point

前端 未结 3 1140
礼貌的吻别
礼貌的吻别 2021-02-03 16:39

I was fiddling in Compiler Explorer, and I found that the order of arguments passed to std::min changes the emitted assembly.

Here\'s the example on Godbolt Compiler Expl

3条回答
  •  抹茶落季
    2021-02-03 17:16

    Consider: std::signbit(std::min(+0.0, -0.0)) == false && std::signbit(std::min(-0.0, +0.0)) == true.

    The only other difference is if both arguments are (possibly different) NaNs, the second argument should be returned.


    You can allow gcc to reorder the arguments by using the -funsafe-math-optimizations -fno-math-errno optimsations (Both enabled by -ffast-math). unsafe-math-optimizations allows the compiler to not care about signed zero, and finite-math-only to not care about NaNs

提交回复
热议问题