且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

对于任何有限的浮点值,是否保证x - x == 0?

更新时间:2022-10-16 08:55:39

Although x - x may give you -0 rather than true 0, -0 compares as equal to 0, so you will be safe with your assumption that any finite number minus itself will compare equal to zero.

See Is there a floating point value of x, for which x-x == 0 is false? for more details.