Created
March 20, 2021 11:44
-
-
Save sergiosvieira/5f3b8b7522fcfb6c9d64735cc9567d5b to your computer and use it in GitHub Desktop.
float comparasion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool approximatelyEqual(float a, float b, float epsilon) | |
{ | |
return fabs(a - b) <= ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon); | |
} | |
bool essentiallyEqual(float a, float b, float epsilon) | |
{ | |
return fabs(a - b) <= ( (fabs(a) > fabs(b) ? fabs(b) : fabs(a)) * epsilon); | |
} | |
bool definitelyGreaterThan(float a, float b, float epsilon) | |
{ | |
return (a - b) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon); | |
} | |
bool definitelyLessThan(float a, float b, float epsilon) | |
{ | |
return (b - a) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment