查了和你说法相关、但又不同的说法。没有想明白。
“但是abs存在有整形重载版本,所以在会输入整形的时候,abs触发整形提升和转换”
这句是笔误吧,还是含着深意?如果有 int std::abs(int) 的重载,输入整形,怎么会提升转换?
又读了cppreference,
-------------------
For integral arguments, the integral overloads of std::abs are likely better matches. If std::abs is called with an unsigned integral argument that cannot be converted to int by integral promotion, the program is ill-formed
-------------------
unsigned int正值范围比int大一半,你说的uint 向 int 的promotion?
【 在 KillnCov 的大作中提到: 】
: 建议一律用fabs。
: 如果输入是浮点数,两者没有区别。
: 但是abs存在有整形重载版本,所以在会输入整形的时候,abs触发整形提升和转换,这中间就可能会产生不可预知的行为,反正C++标准说了,不保证不出异常。
: ...................
--
FROM 61.185.187.*