Skip to content

Wiki NumInt

Danijel Galić edited this page Jan 23, 2024 · 1 revision
final class \FireHub\Core\Support\LowLevel\NumInt()

Important

This class is marked as final.

### Integer number low-level proxy class

An int is a number of the set Z = {..., -2, -1, 0, 1, 2, ...}. Int can be specified in decimal (base 10), hexadecimal (base 16), octal (base 8) or binary (base 2) notation. The negation operator can be used to denote a negative int.

This class was created by Danijel Galić <danijel.galic@outlook.com>
Copyright: 2024 FireHub Web Application Framework
License: <https://opensource.org/licenses/OSL-3.0> OSL Open Source License version 3
Version: GIT: $Id$ Blob checksum.

Fully Qualified Class Name:  \FireHub\Core\Support\LowLevel\NumInt
Source code:  view source code
Blame:  view blame
History:  view history

Methods

Type Name Title
public static divide ### Integer division
inherited public static absolute ### Absolute value
inherited public static ceil ### Round fractions up
inherited public static floor ### Round fractions down
inherited public static round ### Rounds a float
inherited public static log ### Natural logarithm
inherited public static log1p ### Returns log(1 + number), computed in a way that is accurate even when the value of number is close to zero
inherited public static log10 ### Base-10 logarithm
inherited public static max ### Find highest value
inherited public static min ### Find lowest value
inherited public static power ### Exponential expression
inherited public static format ### Format a number with grouped thousands
public static NumInt::divide(int $dividend, int $divisor):int

### Integer division

Source code:  view source code
Blame:  view blame

Parameters

  • int $dividend - Number to be divided.
  • int $divisor - non-zero-int Number which divides the $dividend.

Throws

Returns

  • int - The integer quotient of the division of $dividend by $divisor.
final public static Num::absolute(float|int $number):int|float

Important

This method is marked as final.

### Absolute value

Returns the absolute value of $number.

Source code:  view source code
Blame:  view blame

Parameters

  • float or int $number - The numeric value to process.

Returns

  • int or float - ($number is int ? int : float) The absolute value of number.
final public static Num::ceil(float|int $number):int

Important

This method is marked as final.

### Round fractions up

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

Source code:  view source code
Blame:  view blame

Parameters

  • float or int $number - The value to round up.

Returns

  • int - Rounded number up to the next highest integer.
final public static Num::floor(float|int $number):int

Important

This method is marked as final.

### Round fractions down

Returns the next lowest integer value (as float) by rounding down $number if necessary.

Source code:  view source code
Blame:  view blame

Parameters

  • float or int $number - The value to round down.

Returns

  • int - Rounded number up to the next lowest integer.
final public static Num::round(float|int $number, int $precision, \FireHub\Core\Support\Enums\Number\Round $round = Round::HALF_UP):float|int

Important

This method is marked as final.

### Rounds a float

Returns the rounded value of $number to specified $precision (number of digits after the decimal point). $precision can also be negative or zero (default).

Source code:  view source code
Blame:  view blame

Parameters

  • float or int $number - The value to round.
  • int $precision - [optional] Number of decimal digits to round to. If the precision is positive, num is rounded to precision significant digits after the decimal point. If the precision is negative, num is rounded to precision significant digits before the decimal point, i.e., to the nearest multiple of pow(10, -$precision), e.g. for a precision of -1 num is rounded to tens, for a precision of -2 to hundreds, etc.
  • \FireHub\Core\Support\Enums\Number\Round $round = Round::HALF_UP - [optional] Specify the mode in which rounding occurs.

Returns

  • float or int - ($precision is positive-int ? float : int) Rounded number float.
final public static Num::log(float|int $number, \FireHub\Core\Support\Enums\Number\LogBase|float $base = LogBase::E):float

Important

This method is marked as final.

### Natural logarithm

Source code:  view source code
Blame:  view blame

Parameters

  • float or int $number - The value to calculate the logarithm for.
  • \FireHub\Core\Support\Enums\Number\LogBase or float $base = LogBase::E - [optional] The optional logarithmic base to use (defaults to 'e' and so to the natural logarithm).

Returns

  • float - The logarithm of $number to $base, if given, or the natural logarithm.
final public static Num::log1p(float|int $number):float

Important

This method is marked as final.

### Returns log(1 + number), computed in a way that is accurate even when the value of number is close to zero

Source code:  view source code
Blame:  view blame

Parameters

  • float or int $number - The argument to process.

Returns

  • float - log(1 + num).
final public static Num::log10(float|int $number):float

Important

This method is marked as final.

### Base-10 logarithm

Source code:  view source code
Blame:  view blame

Parameters

  • float or int $number - The argument to process.

Returns

  • float - The base-10 logarithm of num.
final public static Num::max(\FireHub\Core\Support\LowLevel\TInt $value, \FireHub\Core\Support\LowLevel\TInt ...$values):int|float

Important

This method is marked as final.

### Find highest value

Source code:  view source code
Blame:  view blame

Templates

  • TInt of int|float

Parameters

Returns

  • int or float - TInt Value considered "highest" according to standard comparisons.
final public static Num::min(\FireHub\Core\Support\LowLevel\TInt $value, \FireHub\Core\Support\LowLevel\TInt ...$values):int|float

Important

This method is marked as final.

### Find lowest value

Source code:  view source code
Blame:  view blame

Templates

  • TInt of int|float

Parameters

Returns

  • int or float - TInt Value considered "lowest" according to standard comparisons.
final public static Num::power(float|int $base, float|int $exponent):float|int

Important

This method is marked as final.

Note

It is possible to use the ** operator instead.

### Exponential expression

Source code:  view source code
Blame:  view blame

Parameters

  • float or int $base - The base to use.
  • float or int $exponent - The exponent.

Returns

  • float or int - Base raised to the power of exponent. If both arguments are non-negative integers and the result can be represented as an integer, the result will be returned with an int type, otherwise it will be returned as a float.
final public static Num::format(int|float $number, int $decimals, string $decimal_separator = &#039;.&#039;, string $thousands_separator = &#039;,&#039;):string

Important

This method is marked as final.

### Format a number with grouped thousands

Formats a number with grouped thousands and optionally decimal digits using the rounding half up rule.

Source code:  view source code
Blame:  view blame

Parameters

  • int or float $number - The number being formatted.
  • int $decimals - non-negative-int Sets the number of decimal digits. If 0, the decimal_separator is omitted from the return value.
  • string $decimal_separator = '.' - Sets the separator for the decimal point.
  • string $thousands_separator = ',' - Sets the separator for thousands.

Returns

  • string - A formatted version of number.
Clone this wiki locally