Skip to content

Unexpected result of fuzzy_eq() on large number #5316

Description

@ILyoan

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions