FloatComparison.h 473 B

12345678910111213141516171819
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #pragma once
  8. namespace facebook {
  9. namespace react {
  10. inline bool floatEquality(float a, float b, float epsilon = 0.005f) {
  11. return (std::isnan(a) && std::isnan(b)) ||
  12. (!std::isnan(a) && !std::isnan(b) && fabs(a - b) < epsilon);
  13. }
  14. } // namespace react
  15. } // namespace facebook