Does abs(unsigned long) make any sense?

后端 未结 3 1192
梦毁少年i
梦毁少年i 2021-02-04 05:37

I\'ve come across this code, which incidentally my profiler reports as a bottleneck:

#include 

unsigned long a, b;
// Calculate values for a and         


        
3条回答
  •  梦谈多话
    2021-02-04 05:51

    I think when c=a-b is negative, if c is unsigned number, c is not the accurate answer. Using abs to guarantee c is a positive number.

提交回复
热议问题