Search on this site

 Math utility

A number of mathematical functions and constants.

 Constant List

M_E

e            2.71828182845904523536

M_LOG2E

log2e            1.44269504088896340736

M_LOG10E

log10e            0.434294481903251827651

M_LN2

ln2            0.693147180559945309417

M_LN10

ln10            2.30258509299404568402

M_PI

Pi            3.14159265358979323846

M_PI_2

Pi / 2            1.57079632679489661923

M_PI_4

Pi / 4            0.785398163397448309616

M_1_PI

1 / Pi            0.318309886183790671538

M_2_PI

2 / Pi            0.636619772367581343076

M_1_SQRTPI

1 / sqrt(Pi)        0.564189583547756286948

M_2_SQRTPI

2 / sqrt(Pi)        1.12837916709551257390

M_SQRT2

1.41421356237309504880

M_SQRT_2

0.707106781186547524401

M_2PI

2Pi

 Function List

dword Random()

Returns the next random generated number. MT safe and efficient variant of Merssene twister MT19937 by Takuji Nishimura and Makoto Matsumoto is used to get random numbers, with the seed obtained from host platform specific resources ('/dev/urandom' in Posix systems, GUID generator in Win32).

void SeedRandom(dword *seed,int len)

Seeds random with buffer.

void SeedRandom(dword seed = 0)

Seeds random with single value seed. This is good to get always the same sequence of numbers (for the same seed).

ZeroArray(x)

Fills C array x with zeros.

dword Random(dword n)

Returns the next random generated number smaller than n.

qword Random64()

Returns the 64bit random number.

qword Random64(qword n)

Returns the 64bit random number smaller than n.

double Randomf()

Returns the floating point number 0..1.

double sqr (double a)

Returns the square of a.

double argsinh (double s)

Returns the hyperbolic arcsin of s.

double argcosh (double c)

Returns the hyperbolic arcsin of c.

double argtanh (double t)

Returns the hyperbolic arctan of t.

int iscale(int x, int y, int z)

Returns x * y / z.

int iscalefloor(int x, int y, int z)

Returns x * y / z, rounded towards negative infinity.

int iscaleceil(int x, int y, int z)

Returns x * y / z, rounded towards positive infinity.

int idivfloor(int x, int y)

Returns x / y, truncated towards negative infinity.

int idivceil(int x, int y)

Returns x / y, truncated towards positive infinity.

int itimesfloor(int x, int y)

Moves x to nearest lower multiple of y.

int itimesceil(int x, int y)

Moves x to nearest higher multiple of y.

int fround(double x)

Converts double x to nearest integer. Checks integer limits.

int ffloor(double x)

Converts double x to integer rounding towards negative infinity. Checks integer limits.

int fceil(double x)

Converts double x to integer rounding towards +infinity. Checks integer limits.

int64 fround64(double x)

Converts double x to nearest integer. Checks integer limits.

int64 ffloor64(double x)

Converts double x to integer rounding towards negative infinity. Checks integer limits.

int64 fceil64(double x)

Converts double x to integer rounding towards +infinity. Checks integer limits.

double modulo(double x, double y)

Returns the floating-point remainder of x/y.

The remainder of a division operation is the result of subtracting the integral quotient multiplied by the denominator from the numerator:

remainder = numerator - quotient * denominator.

int ilog10 (double d)

d.

double ipow10 (int i)

i.

double normalize (double d, int& exponent)

d exponent.

double roundr (double d, int digits)

d digits.

double floorr (double d, int digits)

d digits.

double ceilr (double d, int digits)

d digits.

String AsString(double x, int nDigits)

Returns the string representation of x with nDigits precision.

 Last edit by klugier on 06/12/2016. Do you want to contribute?. T++