private function _compare(LargeInteger $obj) { $pattern = '/^\\+?(\\d+)(\\.\\d+)?$/'; if (!preg_match($pattern, $this->that->get_value(), $matchFirst) || !preg_match($pattern, $obj->get_value(), $matchSecond)) { return 0; } $intOne = ltrim($matchFirst[1], '0') . str_pad('', 0, '0'); $intTwo = ltrim($matchSecond[1], '0') . str_pad('', 0, '0'); if (strlen($intOne) > strlen($intTwo)) { return 1; } else { if (strlen($intOne) < strlen($intTwo)) { return -1; } } for ($i = 0; $i < strlen($intOne); $i++) { if ((int) $intOne[$i] > (int) $intTwo[$i]) { return 1; } else { if ((int) $intOne[$i] < (int) $intTwo[$i]) { return -1; } } } return 0; }
public function testGetValueShouldReturnInt() { $li = new LargeInteger("12323543598732149872958714082798523523489723897423897423897429874987239847"); $this->assertInternalType("int", (int) $li->get_value()); }