 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. Algorithm used is xoshiro256**, with seed obtained from host platform specific resources ('/dev/urandom' in Posix systems, GUID generator in Win32).

dword Random(dword n)

Returns random generated number smaller than n.

qword Random64()

Returns 64bit random number.

uint64 Random64(uint64 n)

Returns the 64bit random number smaller than n.

void Random64(uint64 *t, int n)

Sets n random 64bit numbers to t array.

double Randomf()

Returns the floating point number <0, 1).

void SeedRandom(dword seed)

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

void SeedRandom()

Seeds random using the host platform entropy. Good to "re-randomize" Random after seeding it with fixed value.

ZeroArray(x)

Fills C array x with zeros.

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 cxl on 06/15/2019. Do you want to contribute?. T++