dxFeed .Net API  5.8.0
dxFeed .Net API library intended to provide market data access for DX clients
Static Public Member Functions | Private Member Functions | Static Private Member Functions | Static Private Attributes
com.dxfeed.util.MathUtil Class Reference

A collection of non-trivial mathematical utility methods. More...

Static Public Member Functions

static double RoundDecimal (double x)
 Rounds a specified double number to a decimal number with at most 14 significant digits and at most 14 digits after decimal point. When x is integer, NaN or infinity, then x is returned (this method does not round big integers to powers of 10). More...
 
static int Div (int a, int b)
 Returns quotient according to number theory - i.e. when remainder is zero or positive. More...
 
static long Div (long a, long b)
 Returns quotient according to number theory - i.e. when remainder is zero or positive. More...
 
static int Rem (int a, int b)
 Returns remainder according to number theory - i.e. when remainder is zero or positive. More...
 
static long Rem (long a, long b)
 Returns remainder according to number theory - i.e. when remainder is zero or positive. More...
 

Private Member Functions

 MathUtil ()
 

Static Private Member Functions

static MathUtil ()
 

Static Private Attributes

static readonly int MAX_DECIMAL_DIGITS = 14
 
static readonly long [] POW10 = new long[MAX_DECIMAL_DIGITS + 1]
 

Detailed Description

A collection of non-trivial mathematical utility methods.

Constructor & Destructor Documentation

◆ MathUtil() [1/2]

com.dxfeed.util.MathUtil.MathUtil ( )
inlineprivate

◆ MathUtil() [2/2]

static com.dxfeed.util.MathUtil.MathUtil ( )
inlinestaticprivate

Member Function Documentation

◆ Div() [1/2]

static int com.dxfeed.util.MathUtil.Div ( int  a,
int  b 
)
inlinestatic

Returns quotient according to number theory - i.e. when remainder is zero or positive.

Parameters
adividend
bdivisor
Returns
quotient according to number theory

◆ Div() [2/2]

static long com.dxfeed.util.MathUtil.Div ( long  a,
long  b 
)
inlinestatic

Returns quotient according to number theory - i.e. when remainder is zero or positive.

Parameters
adividend
bdivisor
Returns
quotient according to number theory

◆ Rem() [1/2]

static int com.dxfeed.util.MathUtil.Rem ( int  a,
int  b 
)
inlinestatic

Returns remainder according to number theory - i.e. when remainder is zero or positive.

Parameters
adividend
bdivisor
Returns
remainder according to number theory

◆ Rem() [2/2]

static long com.dxfeed.util.MathUtil.Rem ( long  a,
long  b 
)
inlinestatic

Returns remainder according to number theory - i.e. when remainder is zero or positive.

Parameters
adividend
bdivisor
Returns
remainder according to number theory

◆ RoundDecimal()

static double com.dxfeed.util.MathUtil.RoundDecimal ( double  x)
inlinestatic

Rounds a specified double number to a decimal number with at most 14 significant digits and at most 14 digits after decimal point. When x is integer, NaN or infinity, then x is returned (this method does not round big integers to powers of 10).

For example, suppose you have 1 dollar and 10 cents and you pay 20 cent. You should keep 90 cents.However, the following expression is false in Java:

1.1 - 0.2 == 0.9

because both 1.1 and 0.2 do not have precise representations in double. To make this comparison work, you have to use roundDecimal method:

roundDecimal(1.1 - 0.2) == 0.9

As a general rule, you should use roundDecimal after any operation (addition, subtraction, multiplication, division) on two decimal numbers if you know that the result is a decimal with at most 14 significant digits and at most 14 digits after decimal point.

Parameters
x
Returns

Field Documentation

◆ MAX_DECIMAL_DIGITS

readonly int com.dxfeed.util.MathUtil.MAX_DECIMAL_DIGITS = 14
staticprivate

◆ POW10

readonly long [] com.dxfeed.util.MathUtil.POW10 = new long[MAX_DECIMAL_DIGITS + 1]
staticprivate

The documentation for this class was generated from the following file: