Source for file IntegerOp.php
Documentation is available at IntegerOp.php
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Jesus M. Castagnetto <jmcastagnetto@php.net> |
// +----------------------------------------------------------------------+
// $Id: IntegerOp.php 303940 2010-10-02 13:53:19Z clockwerx $
include_once 'Math/Integer.php';
* Class implementing operations on Math_Integer objects. If available it
* will use the GMP or BCMATH libraries. Will default to the standard PHP
* integer representation otherwise.
* The operations are implemented as static methods of the class.
* @author Jesus M. Castagnetto <jmcastagnetto@php.net>
* Checks if the given parameter is a Math_Integer object
* @param object Math_Integer $int1
* @return boolean TRUE if parameter is an instance of Math_Integer, FALSE otherwise
* Checks if the Math_Integer object is Odd
* @param object Math_Integer $int1
* @return mixed TRUE if Math_Integer object is odd, FALSE if it is not, PEAR_Error on error.
function isOdd(&$int) {/*{{{*/
if (PEAR ::isError ($err)) {
* Checks if the Math_Integer object is even
* @param object Math_Integer $int1
* @return mixed TRUE if Math_Integer object is even, FALSE if it is not, PEAR_Error on error.
function isEven(&$int) {/*{{{*/
if (PEAR ::isError ($err)) {
* Checks if the Math_Integer object is positive
* @param object Math_Integer $int1
* @return mixed TRUE if Math_Integer object is positive, FALSE if it is not, PEAR_Error on error.
if (PEAR ::isError ($err)) {
return $int->isPositive ();
* Checks if the Math_Integer object is negative
* @param object Math_Integer $int1
* @return mixed TRUE if Math_Integer object is negative, FALSE if it is not, PEAR_Error on error.
if (PEAR ::isError ($err)) {
return $int->isNegative ();
* Checks if the Math_Integer object is zero
* @param object Math_Integer $int1
* @return mixed TRUE if Math_Integer object is zero, FALSE if it is not, PEAR_Error on error.
function isZero(&$int) {/*{{{*/
if (PEAR ::isError ($err)) {
* Add two Math_Integer objects: $i1 + $i2
* @param object Math_Integer $int1
* @param object Math_Integer $int2
* @return object Math_Integer on success, PEAR_Error otherwise
function &add(&$int1, &$int2) {/*{{{*/
$res = $int1->makeClone ();
if (PEAR ::isError ($err)) {
* Substract two Math_Integer objects: $i1 - $i2
* @param object Math_Integer $int1
* @param object Math_Integer $int2
* @return object Math_Integer on success, PEAR_Error otherwise
function &sub(&$int1, &$int2) {/*{{{*/
$res = $int1->makeClone ();
if (PEAR ::isError ($err)) {
* Multiply two Math_Integer objects: $i1 * $i2
* @param object Math_Integer $int1
* @param object Math_Integer $int2
* @return object Math_Integer on success, PEAR_Error otherwise
function &mul(&$int1, &$int2) {/*{{{*/
$res = $int1->makeClone ();
if (PEAR ::isError ($err)) {
* Divide two Math_Integer objects: $i1 / $i2
* @param object Math_Integer $int1
* @param object Math_Integer $int2
* @return object Math_Integer on success, PEAR_Error otherwise
function &div(&$int1, &$int2) {/*{{{*/
$res = $int1->makeClone ();
if (PEAR ::isError ($err)) {
* Calculate the modulus of $i1 and $i2: $i1 % $i2
* @param object Math_Integer $int1
* @param object Math_Integer $int2
* @return object Math_Integer on success, PEAR_Error otherwise
function &mod(&$int1, &$int2) {/*{{{*/
$res = $int1->makeClone ();
if (PEAR ::isError ($err)) {
* Raise $i1 to the $i2 exponent: $i1^$i2
* @param object Math_Integer $int1
* @param object Math_Integer $int2
* @return object Math_Integer on success, PEAR_Error otherwise
function &pow(&$int1, &$int2) {/*{{{*/
$res = $int1->makeClone ();
if (PEAR ::isError ($err)) {
* Calculates the GCD of 2 Math_Integer objects
* @param object Math_Integer $int1
* @param object Math_Integer $int2
* @return mixed and integer on success, PEAR_Error otherwise
* @see Math_IntegerOp::sign
function &gcd(&$int1, &$int2) {/*{{{*/
return $int1->gcd ($int2);
* Compare two Math_Integer objects.
* if $i1 > $i2, returns +1,
* if $i1 == $i2, returns +0,
* if $i1 < $i2, returns -1,
* @param object Math_Integer $int1
* @param object Math_Integer $int2
* @return mixed and integer on success, PEAR_Error otherwise
* @see Math_IntegerOp::sign
function &compare(&$int1, &$int2) {/*{{{*/
return $int1->compare ($int2);
* Returns the sign of a Math_Integer number
* if $i1 > 0, returns +1,
* if $i1 == 0, returns +0,
* if $i1 < 0, returns -1,
* @param object Math_Integer $int1
* @return mixed and integer on success, PEAR_Error otherwise
function &sign(&$int1) {/*{{{*/
* Returns the negative of a Math_Integer number: -1 * $i1
* @param object Math_Integer $int1
* @return object Math_Integer on success, PEAR_Error otherwise
function &negate(&$int1) {/*{{{*/
$res = $int1->makeClone ();
if (PEAR ::isError ($err)) {
* Returns the (integer) square root of a Math_Integer number
* @param object Math_Integer $int1
* @return object Math_Integer on success, PEAR_Error otherwise
function &sqrt(&$int1) {/*{{{*/
$res = $int1->makeClone ();
if (PEAR ::isError ($err)) {
* Returns the absolute value of a Math_Integer number
* @param object Math_Integer $int1
* @return object Math_Integer on success, PEAR_Error otherwise
function &abs(&$int1) {/*{{{*/
$res = $int1->makeClone ();
if (PEAR ::isError ($err)) {
* Checks that the 2 passed objects are valid Math_Integer numbers.
* The objects must be instances of Math_Integer and have been properly
* @param object Math_Integer $int1
* @param object Math_Integer $int2
* @return mixed TRUE if both are Math_Integer objects, PEAR_Error otherwise
function _validInts (&$int1, &$int2) {/*{{{*/
if (PEAR ::isError ($err1)) {
$error .= 'First parameter: '. $err1->getMessage ();
if (PEAR ::isError ($err2)) {
$error .= ' Second parameter: '. $err2->getMessage ();
return PEAR ::raiseError ($error);
* Checks that the passed object is a valid Math_Integer number.
* The object must be an instance of Math_Integer and have been properly
* @param object Math_Integer $int1
* @return mixed TRUE if is a Math_Integer object, PEAR_Error otherwise
function _validInt (&$int1) {/*{{{*/
$error = 'Is not an Integer object.';
} elseif (is_null($int1->getValue ())) {
$error = 'Integer object is uninitalized.';
return PEAR ::raiseError ($error);
}/*}}} end of Math_IntegerOp */
Documentation generated on Mon, 11 Mar 2019 15:39:15 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|