PHP Class Litipk\BigNumbers\Decimal

Author: Andreu Correa Casablanca ([email protected])
ファイルを表示 Open project: litipk/php-bignumbers Class Usage Examples

Protected Properties

Property Type Description
$value string Internal numeric value

Public Methods

Method Description
__toString ( ) : string
abs ( ) : Decimal Returns the absolute value (always a positive number)
add ( Decimal $b, integer $scale = null ) : Decimal Adds two Decimal objects
additiveInverse ( ) : Decimal Returns the element's additive inverse.
arccos ( integer $scale = null ) : Decimal Calculates the arccosine of this with the highest possible accuracy
arccot ( integer $scale = null ) : Decimal Calculates the arccotangente of this with the highest possible accuracy
arccsc ( integer $scale = null ) : Decimal Calculates the arccosecant of this with the highest possible accuracy
arcsec ( integer $scale = null ) : Decimal Calculates the arcsecant of this with the highest possible accuracy
arcsin ( integer $scale = null ) : Decimal Calculates the arcsine of this with the highest possible accuracy
arctan ( integer $scale = null ) : Decimal Calculates the arctangente of this with the highest possible accuracy
asFloat ( ) : float Return value as a float
asInteger ( ) : float Return value as a integer
ceil ( integer $scale ) : Decimal "Ceils" the Decimal to have at most $scale digits after the point
comp ( Decimal $b, integer $scale = null ) : integer $this > $b : returns 1 , $this < $b : returns -1 , $this == $b : returns 0
cos ( integer $scale = null ) : Decimal Calculates the cosine of this method with the highest possible accuracy Note that accuracy is limited by the accuracy of predefined PI;
cosec ( integer $scale = null ) : Decimal Calculates the cosecant of this with the highest possible accuracy Note that accuracy is limited by the accuracy of predefined PI;
cotan ( integer $scale = null ) : Decimal Calculates the cotangent of this method with the highest possible accuracy Note that accuracy is limited by the accuracy of predefined PI;
create ( mixed $value, integer $scale = null, boolean $removeZeros = false ) : Decimal Decimal "constructor".
div ( Decimal $b, integer $scale = null ) : Decimal Divides the object by $b .
equals ( Decimal $b, integer $scale = null ) : boolean Equality comparison between this object and $b
exp ( integer $scale = null ) : Decimal Returns exp($this), said in other words: e^$this .
floor ( integer $scale ) : Decimal "Floors" the Decimal to have at most $scale digits after the point
fromDecimal ( Decimal $decValue, integer $scale = null ) : Decimal Constructs a new Decimal object based on a previous one, but changing it's $scale property.
fromFloat ( float $fltValue, integer $scale = null, boolean $removeZeros = false ) : Decimal
fromInteger ( integer $intValue ) : Decimal
fromString ( string $strValue, integer $scale = null, boolean $removeZeros = false ) : Decimal
getNegativeInfinite ( ) : Decimal Returns a "Negative Infinite" object
getPositiveInfinite ( ) : Decimal Returns a "Positive Infinite" object
hasSameSign ( Decimal $b ) : boolean Indicates if the passed parameter has the same sign as the method's bound object.
innerValue ( ) : number Return the inner representation of the class use with caution
isInfinite ( ) : boolean
isInteger ( ) : boolean
isNegative ( ) : boolean
isPositive ( ) : boolean
isZero ( integer $scale = null ) : boolean
log10 ( integer $scale = null ) : Decimal Returns the object's logarithm in base 10
mod ( Decimal $d, integer $scale = null ) Calculate modulo with a decimal
mul ( Decimal $b, integer $scale = null ) : Decimal Multiplies two BigNumber objects
pow ( Decimal $b, integer $scale = null ) : Decimal Powers this value to $b
round ( integer $scale ) : Decimal "Rounds" the Decimal to have at most $scale digits after the point
sec ( integer $scale = null ) : Decimal Calculates the secant of this with the highest possible accuracy Note that accuracy is limited by the accuracy of predefined PI;
sin ( integer $scale = null ) : Decimal Calculates the sine of this method with the highest possible accuracy Note that accuracy is limited by the accuracy of predefined PI;
sqrt ( integer $scale = null ) : Decimal Returns the square root of this object
sub ( Decimal $b, integer $scale = null ) : Decimal Subtracts two BigNumber objects
tan ( integer $scale = null ) : Decimal Calculates the tangent of this method with the highest possible accuracy Note that accuracy is limited by the accuracy of predefined PI;

Protected Methods

Method Description
paramsValidation ( mixed $value, integer $scale ) Validates basic constructor's arguments

Private Methods

Method Description
__clone ( ) Private clone method
__construct ( string $value, integer $scale ) Private constructor
compute2NRoot ( string $base, integer $index, integer $out_scale ) : string Auxiliar method. Computes $base^((1/2)^$index)
computeSquareIndex ( string $exponent_remaining, integer $actual_index, integer $exp_scale, integer $inner_scale ) : string Auxiliar method. It helps us to decompose the exponent into many summands.
countSignificativeDigits ( Decimal $val, Decimal $abs ) : integer Counts the number of significative digits of $val.
factorialSerie ( Decimal $x, Decimal $firstTerm, callable $generalTerm, $scale ) : Decimal Internal method used to compute sin, cos and exp
innerLog10 ( string $value, integer $in_scale, integer $out_scale ) : string Calculates the logarithm (in base 10) of $value
innerPowWithLittleExponent ( string $base, string $exponent, integer $exp_scale, integer $out_scale ) : string Returns $base^$exponent
innerRound ( string $value, integer $scale ) : string "Rounds" the decimal string to have at most $scale digits after the point
innerTruncate ( $scale, $ceil = true )
normalizeSign ( $sign ) : string
powerSerie ( Decimal $x, Decimal $firstTerm, $scale ) : Decimal Internal method used to compute arcsine and arcosine
removeTrailingZeros ( $strValue, &$scale )
simplePowerSerie ( Decimal $x, Decimal $firstTerm, $scale ) : Decimal Internal method used to compute arctan and arccotan

Method Details

__toString() public method

public __toString ( ) : string
return string

abs() public method

Returns the absolute value (always a positive number)
public abs ( ) : Decimal
return Decimal

add() public method

Adds two Decimal objects
public add ( Decimal $b, integer $scale = null ) : Decimal
$b Decimal
$scale integer
return Decimal

additiveInverse() public method

Returns the element's additive inverse.
public additiveInverse ( ) : Decimal
return Decimal

arccos() public method

Calculates the arccosine of this with the highest possible accuracy
public arccos ( integer $scale = null ) : Decimal
$scale integer
return Decimal

arccot() public method

Calculates the arccotangente of this with the highest possible accuracy
public arccot ( integer $scale = null ) : Decimal
$scale integer
return Decimal

arccsc() public method

Calculates the arccosecant of this with the highest possible accuracy
public arccsc ( integer $scale = null ) : Decimal
$scale integer
return Decimal

arcsec() public method

Calculates the arcsecant of this with the highest possible accuracy
public arcsec ( integer $scale = null ) : Decimal
$scale integer
return Decimal

arcsin() public method

Calculates the arcsine of this with the highest possible accuracy
public arcsin ( integer $scale = null ) : Decimal
$scale integer
return Decimal

arctan() public method

Calculates the arctangente of this with the highest possible accuracy
public arctan ( integer $scale = null ) : Decimal
$scale integer
return Decimal

asFloat() public method

Return value as a float
public asFloat ( ) : float
return float

asInteger() public method

Return value as a integer
public asInteger ( ) : float
return float

ceil() public method

"Ceils" the Decimal to have at most $scale digits after the point
public ceil ( integer $scale ) : Decimal
$scale integer
return Decimal

comp() public method

$this > $b : returns 1 , $this < $b : returns -1 , $this == $b : returns 0
public comp ( Decimal $b, integer $scale = null ) : integer
$b Decimal
$scale integer
return integer

cos() public method

Calculates the cosine of this method with the highest possible accuracy Note that accuracy is limited by the accuracy of predefined PI;
public cos ( integer $scale = null ) : Decimal
$scale integer
return Decimal cos($this)

cosec() public method

Calculates the cosecant of this with the highest possible accuracy Note that accuracy is limited by the accuracy of predefined PI;
public cosec ( integer $scale = null ) : Decimal
$scale integer
return Decimal

cotan() public method

Calculates the cotangent of this method with the highest possible accuracy Note that accuracy is limited by the accuracy of predefined PI;
public cotan ( integer $scale = null ) : Decimal
$scale integer
return Decimal cotan($this)

create() public static method

Decimal "constructor".
public static create ( mixed $value, integer $scale = null, boolean $removeZeros = false ) : Decimal
$value mixed
$scale integer
$removeZeros boolean If true then removes trailing zeros from the number representation
return Decimal

div() public method

Warning: div with $scale == 0 is not the same as integer division because it rounds the last digit in order to minimize the error.
public div ( Decimal $b, integer $scale = null ) : Decimal
$b Decimal
$scale integer
return Decimal

equals() public method

Equality comparison between this object and $b
public equals ( Decimal $b, integer $scale = null ) : boolean
$b Decimal
$scale integer
return boolean

exp() public method

Returns exp($this), said in other words: e^$this .
public exp ( integer $scale = null ) : Decimal
$scale integer
return Decimal

floor() public method

"Floors" the Decimal to have at most $scale digits after the point
public floor ( integer $scale ) : Decimal
$scale integer
return Decimal

fromDecimal() public static method

Constructs a new Decimal object based on a previous one, but changing it's $scale property.
public static fromDecimal ( Decimal $decValue, integer $scale = null ) : Decimal
$decValue Decimal
$scale integer
return Decimal

fromFloat() public static method

public static fromFloat ( float $fltValue, integer $scale = null, boolean $removeZeros = false ) : Decimal
$fltValue float
$scale integer
$removeZeros boolean If true then removes trailing zeros from the number representation
return Decimal

fromInteger() public static method

public static fromInteger ( integer $intValue ) : Decimal
$intValue integer
return Decimal

fromString() public static method

public static fromString ( string $strValue, integer $scale = null, boolean $removeZeros = false ) : Decimal
$strValue string
$scale integer
$removeZeros boolean If true then removes trailing zeros from the number representation
return Decimal

getNegativeInfinite() public static method

Returns a "Negative Infinite" object
public static getNegativeInfinite ( ) : Decimal
return Decimal

getPositiveInfinite() public static method

Returns a "Positive Infinite" object
public static getPositiveInfinite ( ) : Decimal
return Decimal

hasSameSign() public method

Indicates if the passed parameter has the same sign as the method's bound object.
public hasSameSign ( Decimal $b ) : boolean
$b Decimal
return boolean

innerValue() public method

Return the inner representation of the class use with caution
public innerValue ( ) : number
return number

isInfinite() public method

public isInfinite ( ) : boolean
return boolean

isInteger() public method

public isInteger ( ) : boolean
return boolean

isNegative() public method

public isNegative ( ) : boolean
return boolean

isPositive() public method

public isPositive ( ) : boolean
return boolean

isZero() public method

public isZero ( integer $scale = null ) : boolean
$scale integer
return boolean

log10() public method

Returns the object's logarithm in base 10
public log10 ( integer $scale = null ) : Decimal
$scale integer
return Decimal

mod() public method

Calculate modulo with a decimal
public mod ( Decimal $d, integer $scale = null )
$d Decimal
$scale integer

mul() public method

Multiplies two BigNumber objects
public mul ( Decimal $b, integer $scale = null ) : Decimal
$b Decimal
$scale integer
return Decimal

paramsValidation() protected static method

Validates basic constructor's arguments
protected static paramsValidation ( mixed $value, integer $scale )
$value mixed
$scale integer

pow() public method

Powers this value to $b
public pow ( Decimal $b, integer $scale = null ) : Decimal
$b Decimal exponent
$scale integer
return Decimal

round() public method

"Rounds" the Decimal to have at most $scale digits after the point
public round ( integer $scale ) : Decimal
$scale integer
return Decimal

sec() public method

Calculates the secant of this with the highest possible accuracy Note that accuracy is limited by the accuracy of predefined PI;
public sec ( integer $scale = null ) : Decimal
$scale integer
return Decimal

sin() public method

Calculates the sine of this method with the highest possible accuracy Note that accuracy is limited by the accuracy of predefined PI;
public sin ( integer $scale = null ) : Decimal
$scale integer
return Decimal sin($this)

sqrt() public method

Returns the square root of this object
public sqrt ( integer $scale = null ) : Decimal
$scale integer
return Decimal

sub() public method

Subtracts two BigNumber objects
public sub ( Decimal $b, integer $scale = null ) : Decimal
$b Decimal
$scale integer
return Decimal

tan() public method

Calculates the tangent of this method with the highest possible accuracy Note that accuracy is limited by the accuracy of predefined PI;
public tan ( integer $scale = null ) : Decimal
$scale integer
return Decimal tan($this)

Property Details

$value protected_oe property

Internal numeric value
protected string $value
return string