Cast to int vs floor

前端 未结 7 1598
夕颜
夕颜 2020-11-27 14:25

Is there any difference between these:

float foo1 = (int)(bar / 3.0);
float foo2 = floor(bar / 3.0);

As I understand both cases have the sa

相关标签:
7条回答
  • 2020-11-27 14:48

    Casting to an int will truncate toward zero. floor() will truncate toward negative infinite. This will give you different values if bar were negative.

    0 讨论(0)
提交回复
热议问题