Cross-platform C SDK logo

Cross-platform C SDK

Maths

❮ Back
Next ❯
This page has been automatically translated using the Google Translate API services. We are working on improving texts. Thank you for your understanding and patience.

Elementary mathematical functions and constants.


Functions

realbmath_cos (...)
realbmath_sin (...)
realbmath_tan (...)
realbmath_acos (...)
realbmath_asin (...)
realbmath_atan2 (...)
realbmath_norm_angle (...)
realbmath_sqrt (...)
realbmath_isqrt (...)
realbmath_log (...)
realbmath_log10 (...)
realbmath_exp (...)
realbmath_pow (...)
realbmath_abs (...)
realbmath_max (...)
realbmath_min (...)
realbmath_clamp (...)
realbmath_mod (...)
realbmath_modf (...)
uint32_tbmath_prec (...)
realbmath_round (...)
realbmath_round_step (...)
realbmath_floor (...)
realbmath_ceil (...)
voidbmath_rand_seed (...)
realbmath_rand (...)
uint32_tbmath_randi (...)
REnv*bmath_rand_env (...)
voidbmath_rand_destroy (...)
realbmath_rand_mt (...)
uint32_tbmath_rand_mti (...)

Types and Constants

realkE
realkLN2
realkLN10
realkPI
realkSQRT2
realkSQRT3
realkDEG2RAD
realkRAD2DEG
realkINFINITY

BMath offers a compact interface on the elementary mathematical functions of the C standard library. It also defines some of the most used constants, such as the number Pi, conversions between degrees and radians or the root of 2.

  • Use bmath_cosf to calculate the cosine of an angle ( wrapper over cstdlib cosf()).
  • Use bmath_sqrtf to calculate the square root (wrapper over cstdlib sqrtf()).

1. Random numbers

BMath includes a seed-based pseudo-random number generator. From the same seed, the sequence of numbers generated will always be the same. The sequences produced by two different seeds will be radically disparate. Hence they are called pseudo-random.

In the case of multi-threaded applications, this sequence may vary depending on the order of execution of the threads, since these functions are not re-entrant. You must use an "environment" of random numbers for each thread in question, in case you need to always ensure the same sequence (deterministic algorithms).


kE

const real32_t kBMATH_Ef = 2.718281828459045f;

const real64_t kBMATH_Ed = 2.718281828459045;

const real BMath::kE;

Euler's number.


kLN2

const real32_t kBMATH_LN2f = 0.6931471805599453f;

const real64_t kBMATH_LN2d = 0.6931471805599453;

const real BMath::kLN2;

The natural logarithm of 2.


kLN10

const real32_t kBMATH_LN10f = 2.302585092994046f;

const real64_t kBMATH_LN10d = 2.302585092994046;

const real BMath::kLN10;

The natural logarithm of 10.


kPI

const real32_t kBMATH_PIf = 3.141592653589793f;

const real64_t kBMATH_PId = 3.141592653589793;

const real BMath::kPI;

The number Pi.


kSQRT2

const real32_t kBMATH_SQRT2f = 1.414213562373095f;

const real64_t kBMATH_SQRT2d = 1.414213562373095;

const real BMath::kSQRT2;

Square root of 2.


kSQRT3

const real32_t kBMATH_SQRT3f = 1.732050807568878f;

const real64_t kBMATH_SQRT3d = 1.732050807568878;

const real BMath::kSQRT3;

Square root of 3.


kDEG2RAD

const real32_t kBMATH_DEG2RADf = 0.017453292519943f;

const real64_t kBMATH_DEG2RADd = 0.017453292519943;

const real BMath::kDEG2RAD;

Conversion from one degree to radians.


kRAD2DEG

const real32_t kBMATH_RAD2DEGf = 57.2957795130823f;

const real64_t kBMATH_RAD2DEGd = 57.2957795130823;

const real BMath::kRAD2DEG;

Conversion of a radian to degrees.


kINFINITY

const real32_t kBMATH_INFINITYf = ∞f;

const real64_t kBMATH_INFINITYd = ∞;

const real BMath::kINFINITY;

Infinite, represented by a very large value.


bmath_cos ()

Get the cosine of an angle.

real32_t
bmath_cosf(const real32_t angle);

real64_t
bmath_cosd(const real64_t angle);

real
BMath::cos(const real angle);
angle

Angle in radians.

Return

The cosine of the angle.


bmath_sin ()

Get the sine of an angle.

real32_t
bmath_sinf(const real32_t angle);

real64_t
bmath_sind(const real64_t angle);

real
BMath::sin(const real angle);
angle

Angle in radians.

Return

The sine of the angle.


bmath_tan ()

Get the tangent of an angle.

real32_t
bmath_tanf(const real32_t angle);

real64_t
bmath_tand(const real64_t angle);

real
BMath::tan(const real angle);
angle

Angle in radians.

Return

The angle tangent.


bmath_acos ()

Get the cosine arc, or inverse cosine, which is the angle whose cosine is the value.

real32_t
bmath_acosf(const real32_t cos);

real64_t
bmath_acosd(const real64_t cos);

real
BMath::acos(const real cos);
cos

Cosine (-1, 1).

Return

The angle (0, Pi).


bmath_asin ()

Get the sine arc, or inverse sine, which is the angle whose sine is the value.

real32_t
bmath_asinf(const real32_t sin);

real64_t
bmath_asind(const real64_t sin);

real
BMath::asin(const real sin);
sin

Sine (-1, 1).

Return

The angle (0, Pi).


bmath_atan2 ()

Get the tangent arc, or inverse tangent. Es is the angle measured from the X axis to the line containing the origin (0, 0) and the point with the coordinates (x, y).

real32_t
bmath_atan2f(const real32_t y,
             const real32_t x);

real64_t
bmath_atan2d(const real64_t y,
             const real64_t x);

real
BMath::atan2(const real y,
             const real x);
y

Y coordinate.

x

Coordinate X.

Return

The angle (-Pi, Pi).


bmath_norm_angle ()

Normalizes an angle, that is, it returns the same angle expressed in the range (-Pi, Pi).

real32_t
bmath_norm_anglef(const real32_t a);

real64_t
bmath_norm_angled(const real64_t a);

real
BMath::norm_angle(const real a);
a

The angle in radians.

Return

The angle (-Pi, Pi).


bmath_sqrt ()

Get the square root of a number.

real32_t
bmath_sqrtf(const real32_t value);

real64_t
bmath_sqrtd(const real64_t value);

real
BMath::sqrt(const real value);
value

The number.

Return

The square root.


bmath_isqrt ()

Get the inverse square root of a number (1/sqrt).

real32_t
bmath_isqrtf(const real32_t value);

real64_t
bmath_isqrtd(const real64_t value);

real
BMath::isqrt(const real value);
value

The number.

Return

The inverse square root.


bmath_log ()

Get the natural logarithm (base e) of a number.

real32_t
bmath_logf(const real32_t value);

real64_t
bmath_logd(const real64_t value);

real
BMath::log(const real value);
value

The number.

Return

The logarithm.


bmath_log10 ()

Get the logarithm in base 10 of a number.

real32_t
bmath_log10f(const real32_t value);

real64_t
bmath_log10d(const real64_t value);

real
BMath::log10(const real value);
value

The number.

Return

The logarithm.


bmath_exp ()

Get the number of Euler e (2.7182818) raised to a power.

real32_t
bmath_expf(const real32_t value);

real64_t
bmath_expd(const real64_t value);

real
BMath::exp(const real value);
value

The exponent.

Return

The exponential.


bmath_pow ()

Calculate a power, base raised to exponent.

real32_t
bmath_powf(const real32_t base,
           const real32_t exponent);

real64_t
bmath_powd(const real64_t base,
           const real64_t exponent);

real
BMath::pow(const real base,
           const real exponent);
base

Base.

exponent

Exponent.

Return

The result of the power.


bmath_abs ()

Get the absolute value of a number.

real32_t
bmath_absf(const real32_t value);

real64_t
bmath_absd(const real64_t value);

real
BMath::abs(const real value);
value

The number.

Return

The absolute value.


bmath_max ()

Get the maximum of two values.

real32_t
bmath_maxf(const real32_t value1,
           const real32_t value2);

real64_t
bmath_maxd(const real64_t value1,
           const real64_t value2);

real
BMath::max(const real value1,
           const real value2);
value1

First number.

value2

Second number.

Return

The maximum value.


bmath_min ()

Get the minimum of two values.

real32_t
bmath_minf(const real32_t value1,
           const real32_t value2);

real64_t
bmath_mind(const real64_t value1,
           const real64_t value2);

real
BMath::min(const real value1,
           const real value2);
value1

First number.

value2

Second number.

Return

The minimum value.


bmath_clamp ()

Restrict a value to a certain range.

real32_t
bmath_clampf(const real32_t value,
             const real32_t min,
             const real32_t max);

real64_t
bmath_clampd(const real64_t value,
             const real64_t min,
             const real64_t max);

real
BMath::clamp(const real value,
             const real min,
             const real max);
value

The number.

min

Minimum value of the range.

max

Maximum value of the range.

Return

The limited value.


bmath_mod ()

Get the module of divide num/den.

real32_t
bmath_modf(const real32_t num,
           const real32_t den);

real64_t
bmath_modd(const real64_t num,
           const real64_t den);

real
BMath::mod(const real num,
           const real den);
num

Numerator.

den

Denominator.

Return

The module.


bmath_modf ()

Get the integer and fraction part of a real number.

real32_t
bmath_modff(const real32_t value,
            real32_t *intpart);

real64_t
bmath_modfd(const real64_t value,
            real64_t *intpart);

real
BMath::modf(const real value,
            real *intpart);
value

The number.

intpart

Get the integer part.

Return

The fractional part [0,1).


bmath_prec ()

Get the number of decimals (precision) of a real number.

uint32_t
bmath_precf(const real32_t value);

uint32_t
bmath_precd(const real64_t value);

uint32_t
BMath::prec(const real value);
value

The number.

Return

The number of decimal places.


bmath_round ()

Rounds a number to the nearest integer (above or below).

real32_t
bmath_roundf(const real32_t value);

real64_t
bmath_roundd(const real64_t value);

real
BMath::round(const real value);
value

The number.

Return

The nearest whole.


bmath_round_step ()

Round a number to the nearest fraction.

real32_t
bmath_round_stepf(const real32_t value,
                  const real32_t step);

real64_t
bmath_round_stepd(const real64_t value,
                  const real64_t step);

real
BMath::round_step(const real value,
                  const real step);
value

The number.

step

The fraction.

Return

The nearest number.


bmath_floor ()

Rounds a number to the integer below.

real32_t
bmath_floorf(const real32_t value);

real64_t
bmath_floord(const real64_t value);

real
BMath::floor(const real value);
value

The number.

Return

The largest integer number, less than or equal to the number.


bmath_ceil ()

Round a number to the integer above.

real32_t
bmath_ceilf(const real32_t value);

real64_t
bmath_ceild(const real64_t value);

real
BMath::ceil(const real value);
value

The number.

Return

The smallest integer number, greater than or equal to the number.


bmath_rand_seed ()

Establish a new seed of random numbers.

void
bmath_rand_seed(const uint32_t seed);
seed

The new seed.

Remarks

Each time the seed changes, a new sequence of random numbers begins. For the same seed, we will get the same sequence, so they are pseudo-random numbers. Similar seeds (eg. 4, 5 ) produce radically different sequences. Use bmath_rand_env in multi-threaded applications.


bmath_rand ()

Gets a random real number, within an interval.

real32_t
bmath_randf(const real32_t from,
            const real32_t to);

real64_t
bmath_randd(const real64_t from,
            const real64_t to);

real
BMath::rand(const real from,
            const real to);
from

The lower limit of the interval.

to

The upper limit of the interval.

Return

The random number.


bmath_randi ()

Gets a random number, within an interval.

uint32_t
bmath_randi(const uint32_t from,
            const uint32_t to);
from

The lower limit of the interval.

to

The upper limit of the interval.

Return

The random number.


bmath_rand_env ()

Create thread-safe environment for random numbers.

REnv*
bmath_rand_env(const uint32_t seed);
seed

The seed.

Return

The environment.


bmath_rand_destroy ()

Destroy an environment of random numbers.

void
bmath_rand_destroy(REnv **env);
env

The environment. Will be set to NULL after destruction.


bmath_rand_mt ()

Gets a random real number, within an interval.

real32_t
bmath_rand_mtf(REnv *env,
               const real32_t from,
               const real32_t to);

real64_t
bmath_rand_mtd(REnv *env,
               const real64_t from,
               const real64_t to);

real
BMath::rand_mt(REnv *env,
               const real from,
               const real to);
env

The random number environment.

from

The lower limit of the interval.

to

The upper limit of the interval.

Return

The random number.


bmath_rand_mti ()

Gets a random number, within an interval.

uint32_t
bmath_rand_mti(REnv *env,
               const uint32_t from,
               const uint32_t to);
env

The random number environment.

from

The lower limit of the interval.

to

The upper limit of the interval.

Return

The random number.

❮ Back
Next ❯