Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/zf2-572' into develop
Browse files Browse the repository at this point in the history
Forward port #2387
  • Loading branch information
weierophinney committed Sep 19, 2012
2 parents c198073 + 1ade32b commit 15fa021
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
17 changes: 16 additions & 1 deletion library/Zend/Validator/Step.php
Expand Up @@ -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);
}
}
1 change: 1 addition & 0 deletions tests/ZendTest/Validator/StepTest.php
Expand Up @@ -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),
Expand Down

0 comments on commit 15fa021

Please sign in to comment.