diff --git a/core/includes/common.inc b/core/includes/common.inc index cf383c2..3da7fc0 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -1162,18 +1162,15 @@ function valid_url($url, $absolute = FALSE) { function valid_number_step($value, $step, $offset = 0.0) { $double_value = (double) abs($value - $offset); - // The precision length. Floating point numbers have limited precision. - // Although it depends on the system, PHP typically uses the IEEE 754 double - // precision format, which will give a maximum relative error due to rounding - // in the order of 1.11e-16. - $digits = 16; + // The number of digits a float has. + $digits = 24; - // This is max workable length for 32bit representation of mantissa. - $mantissa = 30; + // The number of digits a double has. + $mantissa = 53; // Double's fractional part size is $mantissa-bit. If the current value - // is greater than step*2^$mantissa, the following computation for - // remainder makes no sense. + // is greater than step*2^$mantissa, the following computation for remainder + // makes no sense. if ($double_value / pow(2.0, $mantissa) > $step) { return TRUE; } @@ -1182,11 +1179,10 @@ function valid_number_step($value, $step, $offset = 0.0) { // ... that number subtracted from the step base is not an integral multiple // of the allowed value step, the element is suffering from a step mismatch. $remainder = (double) abs($double_value - $step * round($double_value / $step)); - // Accepts erros in lower fractional part which IEEE 754 single-precision - // can't represent. + // Accepts erros in lower fractional part. $computed_acceptable_error = (double)($step / pow(2.0, $mantissa)); - return !($computed_acceptable_error < $remainder && $remainder < ($step - $computed_acceptable_error)); + return $computed_acceptable_error >= $remainder && $remainder >= ($step - $computed_acceptable_error); } /**