Skip to content

Instantly share code, notes, and snippets.

@mebjas
Created October 5, 2022 09:42
Show Gist options
  • Save mebjas/f5422839ad308f009d9372b790a89cdd to your computer and use it in GitHub Desktop.
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.
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