/** * Checks that the passed object is a valid Math_Integer number. * The object must be an instance of Math_Integer and have been properly * initialized. * * @param object Math_Integer $int1 * @return mixed TRUE if is a Math_Integer object, PEAR_Error otherwise * @access private */ function _validInt(&$int1) { /*{{{*/ $error = ''; if (!Math_IntegerOp::isMath_Integer($int1)) { $error = 'Is not a Math_Integer object.'; } elseif (!$int1->initialized()) { $error = 'Math_Integer object is uninitalized.'; } if (!empty($error)) { return PEAR::raiseError($error); } else { return true; } }
/** * Estimates the approximate index for a given number * It uses the approximate formula: * F(n) ~ (PHI^n)/sqrt(5), where '~' means the 'closest integer to' * This equation is based on the relation: phi = -1/PHI * Which turns Lucas' formula into: * F(n) = (PHI^2n + 1)/(PHI^n * sqrt(5)) * From which we get the formula above, after making the approximation: * (PHI^2n + 1) -> (PHI^2n) * * @param integer $num * @return integer the approximate index * @access private */ function &_estimateN(&$num) { /*{{{*/ if (Math_IntegerOp::isMath_Integer($num)) { $f = $num->toString(); } else { $f = $num; } return Math_Fibonacci::_closestInt((log($f) + MATH_LNSQRT5) / MATH_LNPHI); }
$i2 = new Math_Integer('11111'); } $i3 = new Math_Integer(6); echo '* Using lib: ' . MATH_INTLIB . "\n"; echo 'i1 = ' . $i1->toString() . "\n"; echo 'i2 = ' . $i2->toString() . "\n"; echo 'i3 = ' . $i3->toString() . "\n"; $res = Math_IntegerOp::add($i1, $i2); echo 'i1 + i2 = ' . $res->toString() . "\n"; $res = Math_IntegerOp::sub($i1, $i2); echo 'i1 - i2 = ' . $res->toString() . "\n"; $res = Math_IntegerOp::sub($i2, $i1); echo 'i2 - i1 = ' . $res->toString() . "\n"; $res = Math_IntegerOp::mul($i1, $i2); echo 'i1 * i2 = ' . $res->toString() . "\n"; $res = Math_IntegerOp::div($i1, $i3); echo 'i1 / i3 = ' . $res->toString() . "\n"; $res = Math_IntegerOp::mod($i2, $i3); echo 'i1 % i3 = ' . $res->toString() . "\n"; $res = Math_IntegerOp::neg($i1); echo 'neg(i1) = ' . $res->toString() . "\n"; echo 'sign(neg(i1)) = ' . Math_IntegerOp::sign($res) . "\n"; echo 'sign(neg(0)) = ' . Math_IntegerOp::sign(new Math_Integer(0)) . "\n"; echo 'sign(i2) = ' . Math_IntegerOp::sign($i2) . "\n"; echo 'compare(i1, i2) = ' . Math_IntegerOp::compare($i1, $i2) . "\n"; echo 'compare(i3, i3) = ' . Math_IntegerOp::compare($i3, $i3) . "\n"; echo 'compare(i2, i1) = ' . Math_IntegerOp::compare($i2, $i1) . "\n"; $res = Math_IntegerOp::abs(Math_IntegerOp::neg($i2)); echo 'abs(neg(i2)) = ' . $res->toString() . "\n"; // vim: ts=4:sw=4:et: // vim6: fdl=1: