$hex
$hex :
Get hexadecimal form as S class
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!
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
mixed | $num | N or primitive numeric value |
If argument is not numeric-like
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
mixed | $num | N or numeric value |
If argument is not numeric-like value
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
mixed | $num | N or numeric value. |
If argument is not numeric-like value
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
mixed | $num | N or numeric value |
If argument is not numeric or N class
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'
integer|float|double|\Malenki\Bah\N | $mod | Divisor as an integer/float/double-like value |
If given number is not valid type
If given number is zero
modulo(integer|float|double|\Malenki\Bah\N $mod) : \Malenki\Bah\N
Computes modulo of current number (Alias)
integer|float|double|\Malenki\Bah\N | $mod | Divisor as an integer/float/double-like value |
If given number is not valid type
If given number is zero
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'
\Malenki\Bah\numeric|\Malenki\Bah\N | $num | Power |
If given power is not numeric-like value.
power(\Malenki\Bah\numeric|\Malenki\Bah\N $num) : \Malenki\Bah\N
Computes current number at given power (Alias).
\Malenki\Bah\numeric|\Malenki\Bah\N | $num | Power |
If given power is not numeric-like value.
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'
\Malenki\Bah\numeric|\Malenki\Bah\N | $num | Root |
If root level is 0.
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
\Malenki\Bah\numeric|\Malenki\Bah\N | $num | N or numeric value. |
If argument is not numeric or N class
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
\Malenki\Bah\numeric|\Malenki\Bah\N | $num | N or numeric value. |
If argument is not numeric or N class
eq(\Malenki\Bah\numeric|\Malenki\Bah\N $num) : boolean
Checks if current number is equal to given argument (Alias).
\Malenki\Bah\numeric|\Malenki\Bah\N | $num | N or numeric value. |
If argument is not numeric or N class
neq(\Malenki\Bah\numeric|\Malenki\Bah\N $num) : boolean
Checks if current number is not equal to given argument (Alias).
\Malenki\Bah\numeric|\Malenki\Bah\N | $num | N or numeric value. |
If argument is not numeric or N class
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.
mixed | $what | String-like test expression |
If test expression is not string-like value.
If test expression is not valid.
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
mixed | $number | Numeric-like value |
If argument is not N or numeric value.
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
mixed | $number | N or numeric value |
If argument is not N or numeric value.
multiply(mixed $number) : \Malenki\Bah\N
Creates new N by multipling the current to the given one
mixed | $number | N or numeric value |
If argument is not N or numeric value.
divide(mixed $number) : \Malenki\Bah\N
Divide current number with given argument.
mixed | $number | N or numeric value |
If given argument is zero
If given argument is not N or numeric value.
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; // 'σξθ'
boolean | $digamma | True, use digamme, false, use stigma |
If current number is not positive integer
If current number is greater than 9999
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); // '१२,३४,५६,७८९'
\Malenki\Bah\bollean | $use_sep | If true, then output has separators |
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)
.
boolean | $use_simple_zero | use or not simple zero. |
If at least one myriad does not exist for current number.
abjad() : \Malenki\Bah\S
Convert to arabic string number (equiv of roman)
hebrew() : \Malenki\Bah\S
Convert to hebrew string number
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'
mixed | $n | Base as integer-like value. |
If current number is not an integer.
If given base number is not an Integer-like value.
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
mixed | $callback | A callable action |
If param is not callable
If number is not an integer
If number is zero
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.
mixed | $arg | The value to test. |
string | $arg_name | Optional name of the value, used into exception’s message. |
If value’s type is not valid
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.
mixed | $arg | The value to test. |
string | $arg_name | Optional name of the value, used into exception’s message. |
If value’s type is not valid
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.
mixed | $arg | The value to test. |
string | $arg_name | Optional name of the value, used into exception’s message. |
If value’s type is not valid
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.
mixed | $arg | The value to test. |
string | $arg_name | Optional name of the value, used into exception’s message. |
If value’s type is not valid
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.
mixed | $arg | The value to test. |
string | $arg_name | Optional name of the value, used into exception’s message. |
If value’s type is not valid
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.
mixed | $arg | The value to test. |
string | $arg_name | Optional name of the value, used into exception’s message. |
If value’s type is not valid
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.
mixed | $arg | The value to test. |
string | $arg_name | Optional name of the value, used into exception’s message. |
If value’s type is not valid
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.
mixed | $arg | The value to test. |
string | $arg_name | Optional name of the value, used into exception’s message. |
If value’s type is not valid
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.
mixed | $arg | The value to test. |
string | $arg_name | Optional name of the value, used into exception’s message. |
If value’s type is not valid
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
.
mixed | $arg | The value to test |
mixed | $arg_name | Optional name of the value, used into error message |
If arg is not callable
_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'
_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'
_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.
If current value is not an integer.
_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.
If current value is not an integer.
_next() : \Malenki\Bah\N
Gets next value (Alias).
If current value is not an integer.
_previous() : \Malenki\Bah\N
Gets previous value (Alias).
If current value is not an integer.
_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
_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
_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'
_absolute() : \Malenki\Bah\N
Returns absolute valuei (Alias).
_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'
_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'
If current number is zero
_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
If current number is not an integer.
_divisors() : \Malenki\Bah\A
Gets divisors for the current integer numbers.
If current number is negative, divisors will be based on its positive version.
If current number is not an integer
Instance of A class
_square() : \Malenki\Bah\N
Computes the square of current number
Example:
$n = new N(4);
echo $n->square; // '16'
If given power is not numeric-like value.
_cube() : \Malenki\Bah\N
Computes the cube of current number
Examples:
$n = new N(2);
echo $n->cube; // '8'
If given power is not numeric-like value.
_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
_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
_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
;
If current number is negative or is not an integer.
_fact() : \Malenki\Bah\N
Get factorial number (Alias).
If current number is negative or is not an integer.
_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'
If current number is negative
If current number is not an integer
_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'
_decimal() : \Malenki\Bah\N
Gets decimal part.
Gets decimal part of current number .
Example:
$n = new N(3.14);
echo $n->decimal; // '0.14'
_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
If current number is not an integer
_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
If current number is not an integer
_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'
If current number is not an positive integer.
_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; // '١٩٧٩'
string | $type | Type of arabic digits: |
_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.
If current number is not an integer.
_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.
If current number is not an integer.
_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.
If current number is not an integer.
_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'
If current number is not an integer.
_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'
If current number is not an integer.
_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'
If current number is not an integer.
If given base number is not an Integer-like value.