Division.php 837 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Math;
  7. /**
  8. * Division library
  9. *
  10. * @api
  11. * @since 100.0.2
  12. */
  13. class Division
  14. {
  15. /**
  16. * Const for correct dividing decimal values
  17. */
  18. const DIVIDE_EPSILON = 10000;
  19. /**
  20. * Returns the floating point remainder (modulo) of the division of the arguments
  21. *
  22. * @param float|int $dividend
  23. * @param float|int $divisor
  24. * @return float|int
  25. */
  26. public function getExactDivision($dividend, $divisor)
  27. {
  28. $epsilon = $divisor / self::DIVIDE_EPSILON;
  29. $remainder = fmod($dividend, $divisor);
  30. if (abs($remainder - $divisor) < $epsilon || abs($remainder) < $epsilon) {
  31. $remainder = 0;
  32. }
  33. return $remainder;
  34. }
  35. }