Permalink
Browse files

Merge branch 'hotfix/zf2-572' into develop

Forward port #2387
  • Loading branch information...
2 parents c198073 + 1ade32b commit 15fa021e3e096048ebdd3cc8368bfb29f948cb0e @weierophinney weierophinney committed Sep 19, 2012
Showing with 17 additions and 1 deletion.
  1. +16 −1 library/Zend/Validator/Step.php
  2. +1 −0 tests/ZendTest/Validator/StepTest.php
View
17 library/Zend/Validator/Step.php
@@ -127,11 +127,26 @@ public function isValid($value)
$this->setValue($value);
- if (fmod($value - $this->baseValue, $this->step) !== 0.0) {
+ if ($this->fmod($value - $this->baseValue, $this->step) !== 0.0) {
$this->error(self::NOT_STEP);
return false;
}
return true;
}
+
+ /**
+ * replaces the internal fmod function which give wrong results on many cases
+ *
+ * @param float $x
+ * @param float $y
+ * @return float
+ */
+ protected function fmod($x, $y)
+ {
+ if ($y == 0.0) {
+ return 1.0;
+ }
+ return $x - $y * floor($x / $y);
+ }
}
View
1 tests/ZendTest/Validator/StepTest.php
@@ -96,6 +96,7 @@ public function testDecimalStep()
array(0.1, false),
array(2.1, true),
array(3.1, false),
+ array(10.5, true),
array('2.1', true),
array('1.1', false),
array(1.11, false),

0 comments on commit 15fa021

Please sign in to comment.