PHP Class Litipk\BigNumbers\Decimal

Author: Andreu Correa Casablanca ([email protected])
Afficher le fichier Open project: litipk/php-bignumbers Class Usage Examples

Protected Properties

Свойство Type Description
$value string Internal numeric value

Méthodes publiques

Méthode 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;

Méthodes protégées

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

Private Methods

Méthode 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 méthode

public __toString ( ) : string
Résultat string

abs() public méthode

Returns the absolute value (always a positive number)
public abs ( ) : Decimal
Résultat Decimal

add() public méthode

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

additiveInverse() public méthode

Returns the element's additive inverse.
public additiveInverse ( ) : Decimal
Résultat Decimal

arccos() public méthode

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

arccot() public méthode

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

arccsc() public méthode

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

arcsec() public méthode

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

arcsin() public méthode

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

arctan() public méthode

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

asFloat() public méthode

Return value as a float
public asFloat ( ) : float
Résultat float

asInteger() public méthode

Return value as a integer
public asInteger ( ) : float
Résultat float

ceil() public méthode

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

comp() public méthode

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

cos() public méthode

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
Résultat Decimal cos($this)

cosec() public méthode

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
Résultat Decimal

cotan() public méthode

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
Résultat Decimal cotan($this)

create() public static méthode

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
Résultat Decimal

div() public méthode

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
Résultat Decimal

equals() public méthode

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

exp() public méthode

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

floor() public méthode

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

fromDecimal() public static méthode

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
Résultat Decimal

fromFloat() public static méthode

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
Résultat Decimal

fromInteger() public static méthode

public static fromInteger ( integer $intValue ) : Decimal
$intValue integer
Résultat Decimal

fromString() public static méthode

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
Résultat Decimal

getNegativeInfinite() public static méthode

Returns a "Negative Infinite" object
public static getNegativeInfinite ( ) : Decimal
Résultat Decimal

getPositiveInfinite() public static méthode

Returns a "Positive Infinite" object
public static getPositiveInfinite ( ) : Decimal
Résultat Decimal

hasSameSign() public méthode

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

innerValue() public méthode

Return the inner representation of the class use with caution
public innerValue ( ) : number
Résultat number

isInfinite() public méthode

public isInfinite ( ) : boolean
Résultat boolean

isInteger() public méthode

public isInteger ( ) : boolean
Résultat boolean

isNegative() public méthode

public isNegative ( ) : boolean
Résultat boolean

isPositive() public méthode

public isPositive ( ) : boolean
Résultat boolean

isZero() public méthode

public isZero ( integer $scale = null ) : boolean
$scale integer
Résultat boolean

log10() public méthode

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

mod() public méthode

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

mul() public méthode

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

paramsValidation() protected static méthode

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

pow() public méthode

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

round() public méthode

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

sec() public méthode

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
Résultat Decimal

sin() public méthode

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
Résultat Decimal sin($this)

sqrt() public méthode

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

sub() public méthode

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

tan() public méthode

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
Résultat Decimal tan($this)

Property Details

$value protected_oe property

Internal numeric value
protected string $value
Résultat string