我什么时候使用fabs,什么时候足够使用std :: abs? [英] When do I use fabs and when is it sufficient to use std::abs?
本文介绍了我什么时候使用fabs,什么时候足够使用std :: abs?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我假设abs和fabs在使用math.h时表现不同。但是当我只使用cmath和std :: abs,我必须使用std :: fabs?或晶圆厂?
I assume that abs and fabs are behaving different when using math.h. But when I use just cmath and std::abs, do I have to use std::fabs? or fabs? Or isn't this defined?
推荐答案
在C ++中,使用 std :: abs
;它对所有的数字类型重载。
In C++, it's always sufficient to use std::abs
; it's overloaded for all the numerical types.
在C中, abs
仅适用于整数,您需要 fabs
表示浮点值。这些都可以在C ++(与所有的C库),但没有必要使用它们。
In C, abs
only works on integers, and you need fabs
for floating point values. These are available in C++ (along with all of the C library), but there's no need to use them.
这篇关于我什么时候使用fabs,什么时候足够使用std :: abs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文