Comparing IEEE floats and doubles for equality

前端 未结 15 2352
南方客
南方客 2020-11-30 06:00

What is the best method for comparing IEEE floats and doubles for equality? I have heard of several methods, but I wanted to see what the community thought.

15条回答
  •  悲&欢浪女
    2020-11-30 06:54

    If you are looking for two floats to be equal, then they should be identically equal in my opinion. If you are facing a floating point rounding problem, perhaps a fixed point representation would suit your problem better.

    Perhaps we cannot afford the loss of range or performance that such an approach would inflict.

提交回复
热议问题