什么是避免输出负零的最好方法? [英] what is the best way to avoid negative zero in output?
本文介绍了什么是避免输出负零的最好方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这个问题中,有一些差异在浮点数的负和正零之间。我知道这是因为一些重要的原因。我想知道的是一个短代码,以避免输出中出现负零。
As in this question is said, there is some differences between negative and positive zero in floating point numbers. I know it's because of some important reasons. what I want to know is a short code to avoid negative zero in output.
例如在以下代码中:
cout << fixed << setprecision(3);
cout << (-0.0001) << endl;
- 0.000但我想要0.000。
"-0.000" is printed. but I want "0.000".
推荐答案
尝试取决于您的精度。
cout<< ((abs(ans)<0.0005)≤0.000:ans) endl;
这篇关于什么是避免输出负零的最好方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文