Best way of checking if a floating point is an integer

后端 未结 12 2010
陌清茗
陌清茗 2020-12-25 13:07

[There are a few questions on this but none of the answers are particularly definitive and several are out of date with the current C++ standard].

My research shows

12条回答
  •  感动是毒
    2020-12-25 13:42

    what about converting types like this?

    bool can_convert(float a, int i)
    {
      int b = a;
      float c = i;
      return a == c;
    }
    

提交回复
热议问题