更新时间: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.