Created
October 5, 2022 09:42
-
-
Save mebjas/f5422839ad308f009d9372b790a89cdd to your computer and use it in GitHub Desktop.
modified version of isNearlyEqual(..) that works relative to the value of input floating values.
This file contains hidden or 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
inline bool isNearlyEqual(float val_a, float val_b, float max_relative_diff = FLT_EPSILON) { | |
float abs_diff = abs(val_a - val_b); | |
val_a = fabs(val_a); | |
val_b = fabs(val_b); | |
float scaled_epsilon = max_relative_diff * max(val_a, val_b); | |
return abs_diff <= scaled_epsilon; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment