Skip to content
This repository
Browse code

Merge branch 'hotfix/zf2-572' into develop

Forward port #2387
  • Loading branch information...
commit 15fa021e3e096048ebdd3cc8368bfb29f948cb0e 2 parents c198073 + 1ade32b
Matthew Weier O'Phinney authored September 19, 2012
17  library/Zend/Validator/Step.php
@@ -127,11 +127,26 @@ public function isValid($value)
127 127
 
128 128
         $this->setValue($value);
129 129
 
130  
-        if (fmod($value - $this->baseValue, $this->step) !== 0.0) {
  130
+        if ($this->fmod($value - $this->baseValue, $this->step) !== 0.0) {
131 131
             $this->error(self::NOT_STEP);
132 132
             return false;
133 133
         }
134 134
 
135 135
         return true;
136 136
     }
  137
+
  138
+    /**
  139
+     * replaces the internal fmod function which give wrong results on many cases
  140
+     *
  141
+     * @param float $x
  142
+     * @param float $y
  143
+     * @return float
  144
+     */
  145
+    protected function fmod($x, $y)
  146
+    {
  147
+        if ($y == 0.0) {
  148
+            return 1.0;
  149
+        }
  150
+        return $x - $y * floor($x / $y);
  151
+    }
137 152
 }
1  tests/ZendTest/Validator/StepTest.php
@@ -96,6 +96,7 @@ public function testDecimalStep()
96 96
             array(0.1, false),
97 97
             array(2.1, true),
98 98
             array(3.1, false),
  99
+            array(10.5, true),
99 100
             array('2.1', true),
100 101
             array('1.1', false),
101 102
             array(1.11, false),

0 notes on commit 15fa021

Please sign in to comment.
Something went wrong with that request. Please try again.