C# Class Pchp.Library.PhpMath

Implements PHP mathematical functions and constants.
Show file Open project: iolevel/peachpie

Private Properties

Property Type Description
AbsolutizeRange void
BaseToDouble double
ConvertToLong PhpNumber
DoubleToBase string
FindExtreme Pchp.Core.PhpValue
GetExtreme Pchp.Core.PhpValue
Power10Value double
Random01 int
RoundInternal double
_Log10Abs int
base_convert string

Public Methods

Method Description
abs ( PhpNumber x ) : PhpNumber

Returns the absolute value of x.

abs ( long lx ) : PhpNumber
abs ( double x ) : double
acos ( double x ) : double

Returns the arc cosine of arg in radians. acos() is the complementary function of cos(), which means that x==cos(acos(x)) for every value of a that is within acos()' range.

acosh ( double x ) : double
asin ( double x ) : double

Returns the arc sine of arg in radians. asin() is the complementary function of sin(), which means that x==sin(asin(x)) for every value of a that is within asin()'s range.

asinh ( double x ) : double
atan ( double x ) : double
atan2 ( double y, double x ) : double
atanh ( double x ) : double
bindec ( string str ) : PhpNumber

Returns the decimal equivalent of the binary number represented by the binary_string argument. bindec() converts a binary number to an integer or, if needed for size reasons, double.

ceil ( double x ) : double

Returns the next highest integer value by rounding up x if necessary.

cos ( double x ) : double
cosh ( double x ) : double
decbin ( double number ) : string

Converts the lowest 32 bits of the given number to a binary string.

dechex ( long number ) : string

Returns a string containing a hexadecimal representation of the given number argument.

decoct ( int number ) : string

Returns a string containing an octal representation of the given number argument.

deg2rad ( double degrees ) : double

Degrees to radians.

exp ( double x ) : double

Returns e raised to the power of x.

expm1 ( double x ) : double

expm1() returns the equivalent to 'exp(arg) - 1' computed in a way that is accurate even if the value of arg is near zero, a case where 'exp (arg) - 1' would be inaccurate due to subtraction of two numbers that are nearly equal.

floor ( double x ) : double

Returns the next lowest integer value by rounding down x if necessary.

fmod ( double x, double y ) : double

Returns the floating point remainder (modulo) of the division of the arguments.

getrandmax ( ) : int

Show largest possible random value.

hexdec ( string str ) : PhpNumber

Hexadecimal to decimal. Returns the decimal equivalent of the hexadecimal number represented by the hex_string argument. hexdec() converts a hexadecimal string to a decimal number. hexdec() will ignore any non-hexadecimal characters it encounters.

hypot ( double x, double y ) : double
is_finite ( double x ) : bool
is_infinite ( double x ) : bool
is_nan ( double x ) : bool
lcg_value ( ) : double

Generates a pseudo-random number using linear congruential generator in the range of (0,1).

This method uses the Framwork rand() generator which may or may not be the same generator as the PHP one (L(CG(2^31 - 85),CG(2^31 - 249))).

log ( double x ) : double
log ( double x, double logBase ) : double

If the optional logBase parameter is specified, log() returns log(logBase) x, otherwise log() returns the natural logarithm of x.

log10 ( double x ) : double

Returns the base-10 logarithm of x.

log1p ( double x ) : double

log1p() returns log(1 + number) computed in a way that is accurate even when the value of number is close to zero. log() might only return log(1) in this case due to lack of precision.

max ( ) : PhpValue

Find highest value. If the first and only parameter is an array, max() returns the highest value in that array. If at least two parameters are provided, max() returns the biggest of these values.

max ( PhpArray array ) : PhpValue

Find highest value.

max ( long a, long b ) : long

Find highest value.

min ( ) : PhpValue

Find lowest value. If the first and only parameter is an array, min() returns the lowest value in that array. If at least two parameters are provided, min() returns the smallest of these values.

min ( PhpArray array ) : PhpValue

Find lowest value.

min ( long a, long b ) : long

Find lowest value.

mt_getrandmax ( ) : int
mt_rand ( ) : int
mt_rand ( int min, int max ) : int
mt_srand ( ) : void

Seed the better random number generator. No return value.

mt_srand ( int seed ) : void

Seed the better random number generator. No return value.

octdec ( string str ) : PhpNumber

Returns the decimal equivalent of the octal number represented by the str argument.

pi ( ) : double

Returns an approximation of pi.

pow ( PhpNumber @base, PhpNumber exp ) : PhpNumber

Returns base raised to the power of exp.

rad2deg ( double radians ) : double

Radians to degrees.

rand ( ) : int

Generate a random integer.

rand ( int min, int max ) : int

Generate a random integer.

round ( double x ) : double

Rounds a float.

round ( double x, int precision ) : double

Rounds a float.

round ( double x, int precision, RoundMode mode = RoundMode.HalfUp ) : double

Rounds a float.

sin ( double x ) : double
sinh ( double x ) : double
sqrt ( double x ) : double
srand ( ) : void

Seed the random number generator. No return value.

srand ( int seed ) : void

Seed the random number generator. No return value.

tan ( double x ) : double
tanh ( double x ) : double
uniqid ( ) : string

Generate a unique ID. Gets a prefixed unique identifier based on the current time in microseconds.

uniqid ( string prefix ) : string

Generate a unique ID. Gets a prefixed unique identifier based on the current time in microseconds.

uniqid ( string prefix, bool more_entropy ) : string

Generate a unique ID.

With an empty prefix, the returned string will be 13 characters long. If more_entropy is TRUE, it will be 23 characters.

Private Methods

Method Description
AbsolutizeRange ( int &offset, int &length, int count ) : void

Absolutizes range specified by an offset and a length relatively to a dimension of an array.

Ensures that [offset,offset + length] is subrange of [0,count].

BaseToDouble ( string number, int fromBase ) : double
ConvertToLong ( double number ) : PhpNumber

Converts the given number to int64 (if the number is whole and fits into the int64's range).

DoubleToBase ( double number, int toBase ) : string
FindExtreme ( IEnumerable array, bool maximum ) : PhpValue
GetExtreme ( PhpValue numbers, bool maximum ) : PhpValue
Power10Value ( int power ) : double

Returns precise value of 10^power.

Random01 ( ) : int

Gets 0 or 1 randomly.

RoundInternal ( double value, RoundMode mode ) : double
_Log10Abs ( double value ) : int
base_convert ( string number, int fromBase, int toBase ) : string

Method Details

abs() public static method

Returns the absolute value of x.
public static abs ( PhpNumber x ) : PhpNumber
x PhpNumber The numeric value to process.
return PhpNumber

abs() public static method

public static abs ( long lx ) : PhpNumber
lx long
return PhpNumber

abs() public static method

public static abs ( double x ) : double
x double
return double

acos() public static method

Returns the arc cosine of arg in radians. acos() is the complementary function of cos(), which means that x==cos(acos(x)) for every value of a that is within acos()' range.
public static acos ( double x ) : double
x double The argument to process.
return double

acosh() public static method

public static acosh ( double x ) : double
x double
return double

asin() public static method

Returns the arc sine of arg in radians. asin() is the complementary function of sin(), which means that x==sin(asin(x)) for every value of a that is within asin()'s range.
public static asin ( double x ) : double
x double The argument to process.
return double

asinh() public static method

public static asinh ( double x ) : double
x double
return double

atan() public static method

public static atan ( double x ) : double
x double
return double

atan2() public static method

public static atan2 ( double y, double x ) : double
y double
x double
return double

atanh() public static method

public static atanh ( double x ) : double
x double
return double

bindec() public static method

Returns the decimal equivalent of the binary number represented by the binary_string argument. bindec() converts a binary number to an integer or, if needed for size reasons, double.
public static bindec ( string str ) : PhpNumber
str string The binary string to convert.
return PhpNumber

ceil() public static method

Returns the next highest integer value by rounding up x if necessary.
public static ceil ( double x ) : double
x double The value to round.
return double

cos() public static method

public static cos ( double x ) : double
x double
return double

cosh() public static method

public static cosh ( double x ) : double
x double
return double

decbin() public static method

Converts the lowest 32 bits of the given number to a binary string.
public static decbin ( double number ) : string
number double
return string

dechex() public static method

Returns a string containing a hexadecimal representation of the given number argument.
public static dechex ( long number ) : string
number long Decimal value to convert.
return string

decoct() public static method

Returns a string containing an octal representation of the given number argument.
public static decoct ( int number ) : string
number int Decimal value to convert.
return string

deg2rad() public static method

Degrees to radians.
public static deg2rad ( double degrees ) : double
degrees double
return double

exp() public static method

Returns e raised to the power of x.
public static exp ( double x ) : double
x double
return double

expm1() public static method

expm1() returns the equivalent to 'exp(arg) - 1' computed in a way that is accurate even if the value of arg is near zero, a case where 'exp (arg) - 1' would be inaccurate due to subtraction of two numbers that are nearly equal.
public static expm1 ( double x ) : double
x double The argument to process
return double

floor() public static method

Returns the next lowest integer value by rounding down x if necessary.
public static floor ( double x ) : double
x double The numeric value to round.
return double

fmod() public static method

Returns the floating point remainder (modulo) of the division of the arguments.
public static fmod ( double x, double y ) : double
x double The dividend.
y double The divisor.
return double

getrandmax() public static method

Show largest possible random value.
public static getrandmax ( ) : int
return int

hexdec() public static method

Hexadecimal to decimal. Returns the decimal equivalent of the hexadecimal number represented by the hex_string argument. hexdec() converts a hexadecimal string to a decimal number. hexdec() will ignore any non-hexadecimal characters it encounters.
public static hexdec ( string str ) : PhpNumber
str string The hexadecimal string to convert.
return PhpNumber

hypot() public static method

public static hypot ( double x, double y ) : double
x double
y double
return double

is_finite() public static method

public static is_finite ( double x ) : bool
x double
return bool

is_infinite() public static method

public static is_infinite ( double x ) : bool
x double
return bool

is_nan() public static method

public static is_nan ( double x ) : bool
x double
return bool

lcg_value() public static method

Generates a pseudo-random number using linear congruential generator in the range of (0,1).
This method uses the Framwork rand() generator which may or may not be the same generator as the PHP one (L(CG(2^31 - 85),CG(2^31 - 249))).
public static lcg_value ( ) : double
return double

log() public static method

public static log ( double x ) : double
x double
return double

log() public static method

If the optional logBase parameter is specified, log() returns log(logBase) x, otherwise log() returns the natural logarithm of x.
public static log ( double x, double logBase ) : double
x double
logBase double
return double

log10() public static method

Returns the base-10 logarithm of x.
public static log10 ( double x ) : double
x double
return double

log1p() public static method

log1p() returns log(1 + number) computed in a way that is accurate even when the value of number is close to zero. log() might only return log(1) in this case due to lack of precision.
public static log1p ( double x ) : double
x double The argument to process
return double

max() public static method

Find highest value. If the first and only parameter is an array, max() returns the highest value in that array. If at least two parameters are provided, max() returns the biggest of these values.
public static max ( ) : PhpValue
return Pchp.Core.PhpValue

max() public static method

Find highest value.
public static max ( PhpArray array ) : PhpValue
array Pchp.Core.PhpArray
return Pchp.Core.PhpValue

max() public static method

Find highest value.
public static max ( long a, long b ) : long
a long
b long
return long

min() public static method

Find lowest value. If the first and only parameter is an array, min() returns the lowest value in that array. If at least two parameters are provided, min() returns the smallest of these values.
public static min ( ) : PhpValue
return Pchp.Core.PhpValue

min() public static method

Find lowest value.
public static min ( PhpArray array ) : PhpValue
array Pchp.Core.PhpArray
return Pchp.Core.PhpValue

min() public static method

Find lowest value.
public static min ( long a, long b ) : long
a long
b long
return long

mt_getrandmax() public static method

public static mt_getrandmax ( ) : int
return int

mt_rand() public static method

public static mt_rand ( ) : int
return int

mt_rand() public static method

public static mt_rand ( int min, int max ) : int
min int
max int
return int

mt_srand() public static method

Seed the better random number generator. No return value.
public static mt_srand ( ) : void
return void

mt_srand() public static method

Seed the better random number generator. No return value.
public static mt_srand ( int seed ) : void
seed int Optional seed value.
return void

octdec() public static method

Returns the decimal equivalent of the octal number represented by the str argument.
public static octdec ( string str ) : PhpNumber
str string The octal string to convert.
return PhpNumber

pi() public static method

Returns an approximation of pi.
public static pi ( ) : double
return double

pow() public static method

Returns base raised to the power of exp.
public static pow ( PhpNumber @base, PhpNumber exp ) : PhpNumber
@base PhpNumber
exp PhpNumber
return PhpNumber

rad2deg() public static method

Radians to degrees.
public static rad2deg ( double radians ) : double
radians double
return double

rand() public static method

Generate a random integer.
public static rand ( ) : int
return int

rand() public static method

Generate a random integer.
public static rand ( int min, int max ) : int
min int The lowest value to return.
max int The highest value to return.
return int

round() public static method

Rounds a float.
public static round ( double x ) : double
x double The value to round.
return double

round() public static method

Rounds a float.
public static round ( double x, int precision ) : double
x double The value to round.
precision int The optional number of decimal digits to round to. Can be less than zero to ommit digits at the end. Default is 0.
return double

round() public static method

Rounds a float.
public static round ( double x, int precision, RoundMode mode = RoundMode.HalfUp ) : double
x double The value to round.
precision int The optional number of decimal digits to round to. Can be less than zero to ommit digits at the end. Default is 0.
mode RoundMode One of PHP_ROUND_HALF_UP, PHP_ROUND_HALF_DOWN, PHP_ROUND_HALF_EVEN, or PHP_ROUND_HALF_ODD. Default is PHP_ROUND_HALF_UP.
return double

sin() public static method

public static sin ( double x ) : double
x double
return double

sinh() public static method

public static sinh ( double x ) : double
x double
return double

sqrt() public static method

public static sqrt ( double x ) : double
x double
return double

srand() public static method

Seed the random number generator. No return value.
public static srand ( ) : void
return void

srand() public static method

Seed the random number generator. No return value.
public static srand ( int seed ) : void
seed int Optional seed value.
return void

tan() public static method

public static tan ( double x ) : double
x double
return double

tanh() public static method

public static tanh ( double x ) : double
x double
return double

uniqid() public static method

Generate a unique ID. Gets a prefixed unique identifier based on the current time in microseconds.
public static uniqid ( ) : string
return string

uniqid() public static method

Generate a unique ID. Gets a prefixed unique identifier based on the current time in microseconds.
public static uniqid ( string prefix ) : string
prefix string Can be useful, for instance, if you generate identifiers simultaneously on several hosts that might happen to generate the identifier at the same microsecond. /// With an empty prefix , the returned string will be 13 characters long. ///
return string

uniqid() public static method

Generate a unique ID.
With an empty prefix, the returned string will be 13 characters long. If more_entropy is TRUE, it will be 23 characters.
public static uniqid ( string prefix, bool more_entropy ) : string
prefix string Use the specified prefix.
more_entropy bool Use LCG to generate a random postfix.
return string