Chris@0: $step) { Chris@0: return TRUE; Chris@0: } Chris@0: Chris@0: // Now compute that remainder of a division by $step. Chris@0: $remainder = (double) abs($double_value - $step * round($double_value / $step)); Chris@0: Chris@0: // $remainder is a double precision floating point number. Remainders that Chris@0: // can't be represented with single precision floats are acceptable. The Chris@0: // fractional part of a float has 24 bits. That means remainders smaller than Chris@0: // $step * 2^-24 are acceptable. Chris@0: $computed_acceptable_error = (double) ($step / pow(2.0, 24)); Chris@0: Chris@0: return $computed_acceptable_error >= $remainder || $remainder >= ($step - $computed_acceptable_error); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Generates a sorting code from an integer. Chris@0: * Chris@0: * Consists of a leading character indicating length, followed by N digits Chris@0: * with a numerical value in base 36 (alphadecimal). These codes can be sorted Chris@0: * as strings without altering numerical order. Chris@0: * Chris@0: * It goes: Chris@0: * 00, 01, 02, ..., 0y, 0z, Chris@0: * 110, 111, ... , 1zy, 1zz, Chris@0: * 2100, 2101, ..., 2zzy, 2zzz, Chris@0: * 31000, 31001, ... Chris@0: * Chris@0: * @param int $i Chris@0: * The integer value to convert. Chris@0: * Chris@0: * @return string Chris@0: * The alpha decimal value. Chris@0: * Chris@0: * @see \Drupal\Component\Utility\Number::alphadecimalToInt Chris@0: */ Chris@0: public static function intToAlphadecimal($i = 0) { Chris@0: $num = base_convert((int) $i, 10, 36); Chris@0: $length = strlen($num); Chris@0: Chris@0: return chr($length + ord('0') - 1) . $num; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Decodes a sorting code back to an integer. Chris@0: * Chris@0: * @param string $string Chris@0: * The alpha decimal value to convert Chris@0: * Chris@0: * @return int Chris@0: * The integer value. Chris@0: * Chris@0: * @see \Drupal\Component\Utility\Number::intToAlphadecimal Chris@0: */ Chris@0: public static function alphadecimalToInt($string = '00') { Chris@0: return (int) base_convert(substr($string, 1), 36, 10); Chris@0: } Chris@0: Chris@0: }