\Malenki\BahN

Defines numbers.

This class play with numbers, float, integer or double, add can use some mathematical stuffs.

You can play with number properties (odd/even, is zero, has decimal part, opposite number, inverse numbers, get its divisors, test its sign…)

You can translate number to another numerals, like hindi, chinese, roman…

So many feature to discover!

Summary

Methods
Properties
Constants
__get()
__toString()
__construct()
less()
lt()
lte()
le()
greater()
gt()
gte()
ge()
mod()
modulo()
pow()
power()
log()
root()
equal()
notEqual()
eq()
neq()
round()
roundUp()
roundDown()
roundEven()
roundOdd()
test()
plus()
minus()
multiply()
divide()
greek()
hindi()
chinese()
abjad()
hebrew()
base()
times()
$hex
$oct
$bin
$h
$o
$b
$n
$p
$incr
$decr
$negative
$sign
$zero
$prime
$abs
$absolute
$opposite
$inverse
$divisors
$square
$ln
$sqrt
$factorial
$triangular
$fact
$positive
$hindi
$roman
$greek
$chinese
$mandarin
$putonghua
$chinese_other_zero
$mandarin_other_zero
$putonghua_other_zero
$to_s
$to_c
$string
$str
$integer
$int
$float
$double
No constants found
mustBeStringOrScalar()
mustBeString()
mustBeInteger()
mustBeFloat()
mustBeDouble()
mustBeNumeric()
mustBeArray()
mustBeHash()
mustBeArrayOrHash()
mustBeCallable()
_string()
_str()
_integer()
_int()
_float()
_double()
_incr()
_decr()
_n()
_p()
_next()
_previous()
_negative()
_zero()
_positive()
_abs()
_absolute()
_opposite()
_inverse()
_prime()
_divisors()
_square()
_cube()
_ln()
_sqrt()
_cubeRoot()
_factorial()
_fact()
_triangular()
_sign()
_ceil()
_floor()
_decimal()
_odd()
_even()
_roman()
_arabic()
_hex()
_oct()
_bin()
_h()
_o()
_b()
_cos()
_sin()
_tan()
_cosh()
_sinh()
_tanh()
_acos()
_asin()
_atan()
_acosh()
_asinh()
_atanh()
$value
N/A
No private methods found
No private properties found
N/A

Properties

$hex

$hex : 

Get hexadecimal form as S class

Type

$oct

$oct : 

Get octogonal form as S class

Type

$bin

$bin : 

Get binary form as S class

Type

$h

$h : 

Shorthand for $hex

Type

$o

$o : 

Shorthand for $o

Type

$b

$b : 

Shorthand for $b

Type

$n

$n : 

Type

$p

$p : 

Type

$incr

$incr : 

Get increment number

Type

$decr

$decr : 

Get decrement number

Type

$negative

$negative : 

Check if number is negative or not

Type

$sign

$sign : 

Check if number is negative, positive or null

Type

$zero

$zero : 

Check if number is nul

Type

$prime

$prime : 

Check if number is prime number or not

Type

$abs

$abs : 

Gets absolute value

Type

$absolute

$absolute : 

Gets absolute value

Type

$opposite

$opposite : 

Gets its opposite number

Type

$inverse

$inverse : 

Gets its inverse number

Type

$divisors

$divisors : 

Gets divisors

Type

$square

$square : 

Gets square number

Type

$ln

$ln : 

Gets neperian logarithm

Type

$sqrt

$sqrt : 

Gets neperian logarithm

Type

$factorial

$factorial : 

Gets factorial

Type

$triangular

$triangular : 

Gets triangular number (1+2+3+4… to current number)

Type

$fact

$fact : 

Gets factorial

Type

$positive

$positive : 

Check if number is positive

Type

$hindi

$hindi : 

Get hindi number as S class.

Type

$roman

$roman : 

Get roman number as S class.

Type

$greek

$greek : 

Get greek number as S class.

Type

$chinese

$chinese : 

Get chinese mandarin number as S class.

Type

$mandarin

$mandarin : 

Get chinese mandarin number as S class.

Type

$putonghua

$putonghua : 

Get chinese mandarin number as S class.

Type

$chinese_other_zero

$chinese_other_zero : 

Get chinese mandarin number as S class (other way to print zero).

Type

$mandarin_other_zero

$mandarin_other_zero : 

Get chinese mandarin number as S class (other way to print zero).

Type

$putonghua_other_zero

$putonghua_other_zero : 

Get chinese mandarin number as S class (other way to print zero).

Type

$to_s

$to_s : 

Get as \Malenki\Bah\S object

Type

$to_c

$to_c : 

Get as \Malenki\Bah\C object (if possible)

Type

$string

$string : 

Get as primitive string

Type

$str

$str : 

Get as primitive string

Type

$integer

$integer : 

Get as primitive integer

Type

$int

$int : 

Get as primitive integer

Type

$float

$float : 

Get as primitive float

Type

$double

$double : 

Get as primitive double

Type

$value

$value : mixed

Type

mixed — Primitive value

Methods

__get()

__get(string $name) : mixed

Defines a lot of magic getters.

By default, return internal O::$value attribute.

Parameters

string $name

Returns

mixed

__toString()

__toString() : string

Convert current object into string when this is in string context.

Returns

string

__construct()

__construct( $num)

Parameters

$num

less()

less(mixed $num) : boolean

Checks whether current number is less than given one.

This is equivalent of $n < 3. So, for example:

$n = new N(M_PI);
$n->less(4); // true
$n->less(3); // false

Parameters

mixed $num

N or primitive numeric value

Throws

\InvalidArgumentException

If argument is not numeric-like

Returns

boolean

lt()

lt(mixed $num) : boolean

Shorthand for less() method

Parameters

mixed $num

N or numeric value

Throws

\InvalidArgumentException

If argument is not numeric or N class

Returns

boolean

lte()

lte(mixed $num) : boolean

Tests whether current number is less than or equal to given one.

This is equivalent of $n <= 3. For example;

$n = new N(3);
$n->lte(3); // true
$n->lte(4); // true
$n->lte(1); // false

Parameters

mixed $num

N or numeric value

Throws

\InvalidArgumentException

If argument is not numeric-like value

Returns

boolean

le()

le(mixed $num) : boolean

Tests whether current number is less than or equal to given one (Alias).

Parameters

mixed $num

N or numeric value

Throws

\InvalidArgumentException

If argument is not numeric-like value

Returns

boolean

greater()

greater(mixed $num) : boolean

Tests whether current number is greater than given one.

This is equivalent of $n > 3. For example:

$n = new N(M_PI);
$n->greater(2); // true
$n->greater(4); // false

Parameters

mixed $num

N or numeric value.

Throws

\InvalidArgumentException

If argument is not numeric-like value

Returns

boolean

gt()

gt(mixed $num) : boolean

Shorthand of greater() method

Parameters

mixed $num

N or numeric value

Throws

\InvalidArgumentException

If argument is not numeric-like value

Returns

boolean

gte()

gte(mixed $num) : boolean

Tests whether current number is greater than or equal to the given number.

This is equivalent of $n >= 3. For example:

$n = new N(3);
$n->gte(3); // true
$n->gte(1); // true
$n->gte(5); // false

Parameters

mixed $num

N or numeric value

Throws

\InvalidArgumentException

If argument is not numeric or N class

Returns

boolean

ge()

ge( $num)

Parameters

$num

mod()

mod(integer|float|double|\Malenki\Bah\N $mod) : \Malenki\Bah\N

Computes modulo of current number

Computes modulo of current number using given number as divisor. Unlike mod() function, this can use integer or float value, into primitive PHP type or into \Malenki\Bah\N object.

Example:

$n = new N(2001);
echo $n->mod(5); // '1';
echo $n->mod(3); // '0'

Parameters

integer|float|double|\Malenki\Bah\N $mod

Divisor as an integer/float/double-like value

Throws

\InvalidArgumentException

If given number is not valid type

\InvalidArgumentException

If given number is zero

Returns

\Malenki\Bah\N

modulo()

modulo(integer|float|double|\Malenki\Bah\N $mod) : \Malenki\Bah\N

Computes modulo of current number (Alias)

Parameters

integer|float|double|\Malenki\Bah\N $mod

Divisor as an integer/float/double-like value

Throws

\InvalidArgumentException

If given number is not valid type

\InvalidArgumentException

If given number is zero

Returns

\Malenki\Bah\N

pow()

pow(\Malenki\Bah\numeric|\Malenki\Bah\N $num) : \Malenki\Bah\N

Computes current number at given power.

Takes current number to raise it at given power.

Example:

$n = new N(3);
echo $n->pow(2); // '9'
echo $n->pow(3); // '27'

Parameters

\Malenki\Bah\numeric|\Malenki\Bah\N $num

Power

Throws

\InvalidArgumentException

If given power is not numeric-like value.

Returns

\Malenki\Bah\N

power()

power(\Malenki\Bah\numeric|\Malenki\Bah\N $num) : \Malenki\Bah\N

Computes current number at given power (Alias).

Parameters

\Malenki\Bah\numeric|\Malenki\Bah\N $num

Power

Throws

\InvalidArgumentException

If given power is not numeric-like value.

Returns

\Malenki\Bah\N

log()

log( $base)

Parameters

$base

root()

root(\Malenki\Bah\numeric|\Malenki\Bah\N $num) : \Malenki\Bah\N

Gets nth root of current number.

Gets Nth root of given number.

Example:

$n = new N(8);
echo $n->root(3); // '2'
echo $n->root(1); // '8'

Parameters

\Malenki\Bah\numeric|\Malenki\Bah\N $num

Root

Throws

\InvalidArgumentException

If root level is 0.

Returns

\Malenki\Bah\N

equal()

equal(\Malenki\Bah\numeric|\Malenki\Bah\N $num) : boolean

Checks if current number is equal to given argument.

This tests current number with given argument, an object or primitive numeric value.

Example:

$n = new N(5);
var_dump($n->eq(5)); // true
var_dump($n->eq(5.0)); // true
var_dump($n->eq(new N(5))); // true
var_dump($n->eq(new N(5.0))); // true

Parameters

\Malenki\Bah\numeric|\Malenki\Bah\N $num

N or numeric value.

Throws

\InvalidArgumentException

If argument is not numeric or N class

Returns

boolean

notEqual()

notEqual(\Malenki\Bah\numeric|\Malenki\Bah\N $num) : boolean

Checks if current number is not equal to given argument.

This tests given argument, a numeric primitive PHP value type or \Malenki\Bah\N object with current one to see whether they are not equals.

Example:

$n = new N(5);
var_dump($n->neq(6)); // true
var_dump($n->neq(4)); // true
var_dump($n->neq(new N(5.1))); // true
var_dump($n->neq(new N(-5.0))); // true

Parameters

\Malenki\Bah\numeric|\Malenki\Bah\N $num

N or numeric value.

Throws

\InvalidArgumentException

If argument is not numeric or N class

Returns

boolean

eq()

eq(\Malenki\Bah\numeric|\Malenki\Bah\N $num) : boolean

Checks if current number is equal to given argument (Alias).

Parameters

\Malenki\Bah\numeric|\Malenki\Bah\N $num

N or numeric value.

Throws

\InvalidArgumentException

If argument is not numeric or N class

Returns

boolean

neq()

neq(\Malenki\Bah\numeric|\Malenki\Bah\N $num) : boolean

Checks if current number is not equal to given argument (Alias).

Parameters

\Malenki\Bah\numeric|\Malenki\Bah\N $num

N or numeric value.

Throws

\InvalidArgumentException

If argument is not numeric or N class

Returns

boolean

round()

round( $precision,  $mode)

Parameters

$precision
$mode

roundUp()

roundUp( $precision)

Parameters

$precision

roundDown()

roundDown( $precision)

Parameters

$precision

roundEven()

roundEven( $precision)

Parameters

$precision

roundOdd()

roundOdd( $precision)

Parameters

$precision

test()

test(mixed $what) : boolean

Tests current number against other value using string expression.

Using this method, you can test current number using string expression.

Example:

$n = new N(3);
var_dump($n->test('>= 1')); // true
var_dump($n->test('gt 1')); // true

Available tests are: <, >, <=, >=, =, ==, eq, !=, <>, no, neq, le, ge, lt, gt followed or not by one or many space and number to test with.

Parameters

mixed $what

String-like test expression

Throws

\InvalidArgumentException

If test expression is not string-like value.

\RuntimeException

If test expression is not valid.

Returns

boolean

plus()

plus(mixed $number) : \Malenki\Bah\N

Adds current number to given argument.

Create new \Malenki\Bah\N having the sum of given argument with current number

Parameters

mixed $number

Numeric-like value

Throws

\InvalidArgumentException

If argument is not N or numeric value.

Returns

\Malenki\Bah\N

minus()

minus(mixed $number) : \Malenki\Bah\N

Substract current number with other.

Creates new \Malenki\Bah\N having the substraction of given argument with current number

Parameters

mixed $number

N or numeric value

Throws

\InvalidArgumentException

If argument is not N or numeric value.

Returns

\Malenki\Bah\N

multiply()

multiply(mixed $number) : \Malenki\Bah\N

Creates new N by multipling the current to the given one

Parameters

mixed $number

N or numeric value

Throws

\InvalidArgumentException

If argument is not N or numeric value.

Returns

\Malenki\Bah\N

divide()

divide(mixed $number) : \Malenki\Bah\N

Divide current number with given argument.

Parameters

mixed $number

N or numeric value

Throws

\InvalidArgumentException

If given argument is zero

\InvalidArgumentException

If given argument is not N or numeric value.

Returns

\Malenki\Bah\N

greek()

greek(boolean $digamma) : \Malenki\Bah\S

Converts current number as ancient greek numerals.

It converts current number if and only if it is an positive integer. If digamma is false, use stigma instead.

Max number is 9999.

Example:

$n = new N(269);
echo $n->greek; // 'σξθ'

Parameters

boolean $digamma

True, use digamme, false, use stigma

Throws

\RuntimeException

If current number is not positive integer

\RuntimeException

If current number is greater than 9999

Returns

\Malenki\Bah\S

hindi()

hindi(\Malenki\Bah\bollean $use_sep) : \Malenki\Bah\S

Converts current number as hindi numerals.

The current number is converted to hindi numerals.

Example:

$n = new N(123456789);
echo $n->hindi; // '१२३४५६७८९'
$n = new N(123456789);
echo $n->hindi(true); // '१२,३४,५६,७८९'

Parameters

\Malenki\Bah\bollean $use_sep

If true, then output has separators

Returns

\Malenki\Bah\S

chinese()

chinese(boolean $use_simple_zero) : \Malenki\Bah\S

Converts current number into chinese numerals

The current number is converted into simplified chinese ideograms.

As argument, you can use a boolean to use alternative zero numeral. By default it does not use simple zero.

Example:

$n = new N(1234);
echo $n->chinese; // '一千二百三十四'
echo $n->mandarin; // '一千二百三十四'
echo $n->putonghua; // '一千二百三十四'
$n = new N(208);
echo $n->chinese(false); // '二百零八'
echo $n->chinese; // '二百零八'
echo $n->mandarin; // '二百零八'
echo $n->putonghua; // '二百零八'
echo $n->chinese(true); // '二百〇八'
echo $n->chinese_other_zero; // '二百〇八'
echo $n->mandarin_other_zero; // '二百〇八'
echo $n->putonghua_other_zero; // '二百〇八'

Note: Several magic getters are available, for each " alternatives, you can add _other_zero to have same result as N::chinese(true).

Parameters

boolean $use_simple_zero

use or not simple zero.

Throws

\RuntimeException

If at least one myriad does not exist for current number.

Returns

\Malenki\Bah\S

abjad()

abjad() : \Malenki\Bah\S

Convert to arabic string number (equiv of roman)

Returns

\Malenki\Bah\S

hebrew()

hebrew() : \Malenki\Bah\S

Convert to hebrew string number

Returns

\Malenki\Bah\S

base()

base(mixed $n) : \Malenki\Bah\S

Converts current number into another base.

This converts current number to another base. Alowed bases are into the range [2, 36].

$n = new N(2001);
echo $n->base(2); // '11111010001'

You can have negative result too:

$n = new N(-2001);
echo $n->base(2); // '-11111010001'

Parameters

mixed $n

Base as integer-like value.

Throws

\RuntimeException

If current number is not an integer.

\InvalidArgumentException

If given base number is not an Integer-like value.

Returns

\Malenki\Bah\S

times()

times(mixed $callback) : \Malenki\Bah\N

Repeats given callable param.

Runs N times given callable param. N is current number.

As argument, callable params as current index of iteration as \Malenki\Bah\N object.

If callable param returns content, then each returned result is stored into an \Malenki\Bah\A object.

Example:

$n = new N(7);

$func = function($i){
    if($i->odd){
        return true;
    }

    return false;
};

var_dump($n->times($func)->array); // array(false, true, false, true, false, true, false)

Note: Current number can be negative, but cannot be zero

Parameters

mixed $callback

A callable action

Throws

\InvalidArgumentException

If param is not callable

\RuntimeException

If number is not an integer

\RuntimeException

If number is zero

Returns

\Malenki\Bah\N

mustBeStringOrScalar()

mustBeStringOrScalar(mixed $arg, string $arg_name) : void

Checks whether given value is string-like or scalar type.

Value must be of string-like type (string or object having __toString() method) or a basic scalar type.

The aim of this method is only to raise \InvalidArgumentException if given value has not the good type.

Parameters

mixed $arg

The value to test.

string $arg_name

Optional name of the value, used into exception’s message.

Throws

\InvalidArgumentException

If value’s type is not valid

mustBeString()

mustBeString(mixed $arg, string $arg_name) : void

Checks whether given value is string-like type.

A string-like value is string or object having __toString() method.

The aim of this method is only to raise \InvalidArgumentException if given value has not the good type.

Parameters

mixed $arg

The value to test.

string $arg_name

Optional name of the value, used into exception’s message.

Throws

\InvalidArgumentException

If value’s type is not valid

mustBeInteger()

mustBeInteger(mixed $arg, string $arg_name) : void

Checks whether given value is integer-like type.

An integer-like value is integer or \Malenki\Bah\N object.

The aim of this method is only to raise \InvalidArgumentException if given value has not the good type.

Parameters

mixed $arg

The value to test.

string $arg_name

Optional name of the value, used into exception’s message.

Throws

\InvalidArgumentException

If value’s type is not valid

mustBeFloat()

mustBeFloat(mixed $arg, string $arg_name) : void

Checks whether given value is float-like type.

A float-like value is float or \Malenki\Bah\N object.

The aim of this method is only to raise \InvalidArgumentException if given value has not the good type.

Parameters

mixed $arg

The value to test.

string $arg_name

Optional name of the value, used into exception’s message.

Throws

\InvalidArgumentException

If value’s type is not valid

mustBeDouble()

mustBeDouble(mixed $arg, string $arg_name) : void

Checks whether given value is double-like type.

A double-like value is string or \Malenki\Bah\N object.

The aim of this method is only to raise \InvalidArgumentException if given value has not the good type.

Parameters

mixed $arg

The value to test.

string $arg_name

Optional name of the value, used into exception’s message.

Throws

\InvalidArgumentException

If value’s type is not valid

mustBeNumeric()

mustBeNumeric(mixed $arg, string $arg_name) : void

Checks whether given value is numeric-like type.

A numeric-like value is numeric (integer, float or double) or \Malenki\Bah\N object.

The aim of this method is only to raise \InvalidArgumentException if given value has not the good type.

Parameters

mixed $arg

The value to test.

string $arg_name

Optional name of the value, used into exception’s message.

Throws

\InvalidArgumentException

If value’s type is not valid

mustBeArray()

mustBeArray(mixed $arg, string $arg_name) : void

Checks whether given value is an array-like type.

A array-like value is an array or \Malenki\Bah\A object.

The aim of this method is only to raise \InvalidArgumentException if given value has not the good type.

Parameters

mixed $arg

The value to test.

string $arg_name

Optional name of the value, used into exception’s message.

Throws

\InvalidArgumentException

If value’s type is not valid

mustBeHash()

mustBeHash(mixed $arg, string $arg_name) : void

Checks whether given value is a hash-like type.

A hash-like value is an array having named-index or \Malenki\Bah\H object.

The aim of this method is only to raise \InvalidArgumentException if given value has not the good type.

Parameters

mixed $arg

The value to test.

string $arg_name

Optional name of the value, used into exception’s message.

Throws

\InvalidArgumentException

If value’s type is not valid

mustBeArrayOrHash()

mustBeArrayOrHash(mixed $arg, string $arg_name) : void

Checks whether given value is an array-like or hash-like type.

The aim of this method is only to raise \InvalidArgumentException if given value has not the good type.

Parameters

mixed $arg

The value to test.

string $arg_name

Optional name of the value, used into exception’s message.

Throws

\InvalidArgumentException

If value’s type is not valid

mustBeCallable()

mustBeCallable(mixed $arg, mixed $arg_name) : void

Checks whether the given argument is callable.

This is usefull to test is an argument can be call as a function. If this argument is not callable, then this raises an \InvalidArgumentException.

Parameters

mixed $arg

The value to test

mixed $arg_name

Optional name of the value, used into error message

Throws

\InvalidArgumentException

If arg is not callable

_string()

_string() : string

Casts current number to string primitive type

Export current number value to primitive string PHP type value.

Example;

$n = new N(M_PI);
var_dump($n->string); // string('3.1415926535898')

Returns

string

_str()

_str() : string

Casts current number to string primitive type (Alias)

Returns

string

_integer()

_integer() : integer

Casts current number to integer primitive type

Export current number value to primitive integer PHP type value.

Example;

$n = new N(M_PI);
var_dump($n->integer); // int(3)

Returns

integer

_int()

_int() : integer

Casts current number to integer primitive type (Alias)

Returns

integer

_float()

_float() : float

Casts current number to float primitive type

Export current number value to primitive float PHP type value.

Example;

$n = new N(M_PI);
var_dump($n->float); // float

Returns

float

_double()

_double() : double

Casts current number to double primitive type

Export current number value to primitive double PHP type value.

Example;

$n = new N(M_PI);
var_dump($n->double); // double

Returns

double

_incr()

_incr() : \Malenki\Bah\N

Increments current number.

This increments current number itself, this returns the same changed object, unlike other a lot of method in Bah lib.

Example:

$n = new N(1);
echo $n->incr;// '2'
echo $n; // '2'

Returns

\Malenki\Bah\N

_decr()

_decr() : \Malenki\Bah\N

Decrements current number.

This decrements current number itself, this returns the same changed object, unlike other a lot of method in Bah lib.

Example:

$n = new N(2);
echo $n->decr;// '1'
echo $n; // '1'

Returns

\Malenki\Bah\N

_n()

_n() : \Malenki\Bah\N

Gets next integer value.

If current number is an integer, this method returns next one.

Example:

$n = new N(1);
echo $n->n; // 2
echo $n->next; // 2 using alias

It is the runtime part of magic getter.

Throws

\RuntimeException

If current value is not an integer.

Returns

\Malenki\Bah\N

_p()

_p() : \Malenki\Bah\N

Gets previous integer value.

If current number is an integer, this method returns previous one.

Example:

$n = new N(1);
echo $n->p; // 0
echo $n->previous; // 0 using alias

It is the runtime part of magic getter.

Throws

\RuntimeException

If current value is not an integer.

Returns

\Malenki\Bah\N

_next()

_next() : \Malenki\Bah\N

Gets next value (Alias).

Throws

\RuntimeException

If current value is not an integer.

Returns

\Malenki\Bah\N

_previous()

_previous() : \Malenki\Bah\N

Gets previous value (Alias).

Throws

\RuntimeException

If current value is not an integer.

Returns

\Malenki\Bah\N

_negative()

_negative() : boolean

Tests if number is negative.

This tests whether current number is less than zero. Use only as magic getter.

Example:

$n = new N(0);
var_dump($n->negative); // false

$n = new N(5);
var_dump($n->negative); // false

$n = new N(-6);
var_dump($n->negative); // true

Returns

boolean

_zero()

_zero() : boolean

Tests if number is equal to zero.

This tests if current number is equals to zero.

Example:

$n = new N(0);
var_dump($n->zero); // true

Returns

boolean

_positive()

_positive() : boolean

Tests if number is positive.

This tests whether current number is greater than zero. Use only as magic getter.

Example:

$n = new N(0);
var_dump($n->positive); // false

$n = new N(5);
var_dump($n->positive); // true

$n = new N(-6);
var_dump($n->positive); // false

Returns

boolean

_abs()

_abs() : \Malenki\Bah\N

Returns absolute value.

Gets absolute value of the current number.

Example:

$n = new N(-7);
echo $n->abs; // '7'
$n = new N(7);
echo $n->abs; // '7'
$n = new N(0);
echo $n->abs; // '0'

Returns

\Malenki\Bah\N

_absolute()

_absolute() : \Malenki\Bah\N

Returns absolute valuei (Alias).

Returns

\Malenki\Bah\N

_opposite()

_opposite() : \Malenki\Bah\N

Gets the opposite number.

Get the opposite number of current number.

Example:

$n = new N(7);
echo $n->opposite; // '-7'
echo $n->opposite->opposite; // '7'
$n = new N(-7);
echo $n->opposite; // '7'
$n = new N(0);
echo $n->opposite; // '0'

Returns

\Malenki\Bah\N

_inverse()

_inverse() : \Malenki\Bah\N

Gets the inverse of current number.

Gets the inverse, the number 1 divided by current number. But this is only possible with number different of zero.

Example:

$n = new N(2);
echo $n->inverse; // '0.5'

Throws

\RuntimeException

If current number is zero

Returns

\Malenki\Bah\N

_prime()

_prime() : boolean

Checks if current number is prime number

Checks whether current number is prime number. Prime number can only by divided by itself and by one.

Example:

$n = new N(5);
var_dump($n->prime); // true
$n = new N(6);
var_dump($n->prime); // false

Throws

\RuntimeException

If current number is not an integer.

Returns

boolean

_divisors()

_divisors() : \Malenki\Bah\A

Gets divisors for the current integer numbers.

If current number is negative, divisors will be based on its positive version.

Throws

\RuntimeException

If current number is not an integer

Returns

\Malenki\Bah\A

Instance of A class

_square()

_square() : \Malenki\Bah\N

Computes the square of current number

Example:

$n = new N(4);
echo $n->square; // '16'

Throws

\InvalidArgumentException

If given power is not numeric-like value.

Returns

\Malenki\Bah\N

_cube()

_cube() : \Malenki\Bah\N

Computes the cube of current number

Examples:

$n = new N(2);
echo $n->cube; // '8'

Throws

\InvalidArgumentException

If given power is not numeric-like value.

Returns

\Malenki\Bah\N

_ln()

_ln()

_sqrt()

_sqrt() : \Malenki\Bah\N

Gets square roots of current number.

Gets the square root number of current number.

This is runtime part of some magic getter ways

Example:

$n = new N(9);
echo $n->sqrt; // '3'
echo $n->square_root; // '3'

Note: If you try to get square root of negative number, you will get NaN.

$n = new N(-9);
var_dump($n->sqrt->is_nan); // true

Returns

\Malenki\Bah\N

_cubeRoot()

_cubeRoot() : \Malenki\Bah\N

Gets cube roots of current number.

Gets the cube root number of current number.

This is runtime part of a magic getter.

Example:

$n = new N(8);
echo $n->cube_root; // '2'

Note: If you try to get cube root of negative number, you will get NaN.

$n = new N(-8);
var_dump($n->cube_root->is_nan); // true

Returns

\Malenki\Bah\N

_factorial()

_factorial() : \Malenki\Bah\N

Computes the factorial of current number.

Computes the factorial of current number, the product form 1 to current integer number.

$n = new N(1);
echo $n->factorial; // 1
echo $n->incr->factorial; // 2
echo $n->incr->factorial; // 6
echo $n->incr->factorial; // 24
echo $n->incr->factorial; // 120
echo $n->incr->factorial; // 720

This method is the runtime part of magic getter \Malenki\Bah\N::$factorial;

Throws

\RuntimeException

If current number is negative or is not an integer.

Returns

\Malenki\Bah\N

_fact()

_fact() : \Malenki\Bah\N

Get factorial number (Alias).

Throws

\RuntimeException

If current number is negative or is not an integer.

Returns

\Malenki\Bah\N

_triangular()

_triangular() : \Malenki\Bah\N

Gets triangular number using current number as one of triangle’s edge.

A triangular number is well defined by wikipedia’s article.

This method take current number as one side, and then computer the triangular number.

Example:

$n = new N(4);
echo $n->triangular; // '10'

Throws

\RuntimeException

If current number is negative

\RuntimeException

If current number is not an integer

Returns

\Malenki\Bah\N

_sign()

_sign() : \Malenki\Bah\N

Gets sign value.

Sign is get using -1 for negative number, 0 for null number and +1 for positive number.

Example:

$n = new N(3.14);
echo $n->sign; //'1'

$n = new N(-4);
echo $n->sign; //'-1'

$n = new N(0);
echo $n->sign; //'0'

Returns

\Malenki\Bah\N

_ceil()

_ceil()

_floor()

_floor()

_decimal()

_decimal() : \Malenki\Bah\N

Gets decimal part.

Gets decimal part of current number .

Example:

$n = new N(3.14);
echo $n->decimal; // '0.14'

Returns

\Malenki\Bah\N

_odd()

_odd() : boolean

Tests whether current number is odd.

Tests whether current integer number is odd or not. If current number is not an integer, then raises an \RuntimeException.

This is used as runtime part of magic getter S::$odd.

Example:

$n = new N(3);
$n->odd; // true
$n = new N(4);
$n->odd; // false
$n = new N(3.14);
$n->odd; // raises eception

Throws

\RuntimeException

If current number is not an integer

Returns

boolean

_even()

_even() : boolean

Tests whether current number is even.

Tests whether current integer number is even or not. If current number is not an integer, then raises an \RuntimeException.

This is used as runtime part of magic getter S::$even.

Example:

$n = new N(4);
$n->even; // true
$n = new N(5);
$n->even; // false
$n = new N(3.14);
$n->even; // raises eception

Throws

\RuntimeException

If current number is not an integer

Returns

boolean

_roman()

_roman() : \Malenki\Bah\S

Converts current number to roman number.

This converts current positive integer to roman numerals, returning \Malenki\Bah\S object.

Example:

$n = new N(1979);
echo $n->roman; // 'mcmlxxix'
echo $n->roman->upper; // 'MCMLXXIX'

Throws

\RuntimeException

If current number is not an positive integer.

Returns

\Malenki\Bah\S

_arabic()

_arabic(string $type) : \Malenki\Bah\S

Converts current number as arabic digit.

Arbic number can have their own shape, so many arab countries use arabic number in place of occidental numerals.

This converts current numbers into \Malenki\Bah\S object having arabic digits.

Example:

$n = new N(1979);
echo $n->arabic; // '١٩٧٩'

Parameters

string $type

Type of arabic digits: arabic (default), or perso_arabic or persian

Returns

\Malenki\Bah\S

_hex()

_hex() : \Malenki\Bah\S

Converts to hexadecimal number.

Returns current integer number converted to hexadecimal as \Malenki\Bah\S object.

Example:

$n = new N(2001);
echo $n->hex; // '7d1'

Negative numbers are allowed too:

$n = new N(-2001);
echo $n->hex; // '-7d1'

This is runtime part of its associated magic getter.

Throws

\RuntimeException

If current number is not an integer.

Returns

\Malenki\Bah\S

_oct()

_oct() : \Malenki\Bah\S

Converts to octal number.

Returns current integer number converted to octal as \Malenki\Bah\S object.

Example:

$n = new N(2001);
echo $n->oct; // '3721'

Negative numbers are allowed too:

$n = new N(-2001);
echo $n->oct; // '-3721'

This is runtime part of its associated magic getter.

Throws

\RuntimeException

If current number is not an integer.

Returns

\Malenki\Bah\S

_bin()

_bin() : \Malenki\Bah\S

Converts to binary number.

Returns current integer number converted to binary as \Malenki\Bah\S object.

Example:

$n = new N(2001);
echo $n->bin; // '11111010001'

Negative numbers are allowed too:

$n = new N(-2001);
echo $n->bin; // '-11111010001'

This is runtime part of its associated magic getter.

Throws

\RuntimeException

If current number is not an integer.

Returns

\Malenki\Bah\S

_h()

_h() : \Malenki\Bah\S

Converts to hexadecial number (Alias).

This is runtime part of its associated magic getter.

Example:

$n = new N(2001);
echo $n->h; // '7d1'
echo $n->hex; // '7d1'

Throws

\RuntimeException

If current number is not an integer.

Returns

\Malenki\Bah\S

_o()

_o() : \Malenki\Bah\S

Converts to octal number (Alias).

This is runtime part of its associated magic getter.

Example:

$n = new N(2001);
echo $n->o; // '3721'
echo $n->oct; // '3721'

Throws

\RuntimeException

If current number is not an integer.

Returns

\Malenki\Bah\S

_b()

_b() : \Malenki\Bah\S

Converts to binary number (Alias)

This is runtime part of its associated magic getter.

Example:

$n = new N(2001);
echo $n->b; // '11111010001'
echo $n->bin; // '11111010001'

Throws

\RuntimeException

If current number is not an integer.

\InvalidArgumentException

If given base number is not an Integer-like value.

Returns

\Malenki\Bah\S

_cos()

_cos()

_sin()

_sin()

_tan()

_tan()

_cosh()

_cosh()

_sinh()

_sinh()

_tanh()

_tanh()

_acos()

_acos()

_asin()

_asin()

_atan()

_atan()

_acosh()

_acosh()

_asinh()

_asinh()

_atanh()

_atanh()