rust icon indicating copy to clipboard operation
rust copied to clipboard

Unexpected result of fuzzy_eq() on large number

Open ILyoan opened this issue 13 years ago • 3 comments

fuzzy_eq() is well working with small float numbers but when the number become too large that even the round-off error exceed the epsilon(default is 1e-6), the function can return an unexpected result.

See this https://gist.github.com/ILyoan/5136141 fuzzy_eq() in 21th line will return false because 27272727272727276822 = 1e20 * (1/11) * 3 27272727272727272406 = 1e20 * (3/11) and the difference between two numbers is larger than default epsilon

How about we use relative error method like this https://gist.github.com/ILyoan/5136153

ILyoan avatar Mar 11 '13 18:03 ILyoan

We can also use an ulp-based approach, like Google's C++ testing framework.

lifthrasiir avatar Mar 12 '13 01:03 lifthrasiir

nominating production ready

metajack avatar Jul 11 '13 17:07 metajack

accepted for production-ready milestone

graydon avatar Aug 08 '13 17:08 graydon