Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would I use 2's complement to compare two doubles instead of comparing their differences against an epsilon value?

Referenced here and here...Why would I use two's complement over an epsilon method? It seems like the epsilon method would be good enough for most cases.


Update: I'm purely looking for a theoretical reason why you'd use one over the other. I've always used the epsilon method.

Has anyone used the 2's complement comparison successfully? Why? Why Not?

like image 274
Steve Duitsman Avatar asked Dec 06 '25 04:12

Steve Duitsman


1 Answers

the second link you reference mentions an article that has quite a long description of the issue:

http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm

but unless you are tweaking performance I would stick with epsilon so people can debug your code

like image 95
Oskar Avatar answered Dec 08 '25 19:12

Oskar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!