The modern and fun way to program.
std.math
std.math
is just an interface to the C++
math library <cmath>
plus a
couple of function to generate random numbers.
So, see also the original C++ docs on cplusplus.com).
NAN
Contains the floating-point Not A Number value.
Note that NAN == NAN
and std.cast::same(NAN, NAN)
return false
: use is_nan(x)
.
INF
Contains the floating-point Infinity value.
E
The Euler’s number stored in a float
.
PI
The PI constant stored in a float
.
rand ()
Generates and returns a random float
between 0
and 1
(1
excluded).
rand_int (min, max)
Generates and returns a random integer
between min
and max
(max
excluded),
or null
if either min
or max
is not an integer.
deg (r)
Converts the angle r
(float
or integer
) expressed in radians to degrees.
Returns the new float
, ornull, if
r` is an invalid parameter.
rad (d)
Converts the angle r
(float
or integer
) expressed in degrees to radians.
Returns the new float
, ornull, if
r` is an invalid parameter.
frexp (x)
Returns a tuple containing the values of significand
and exp
that make true the following equation:
x = significand * 2exp
hypot (a, b)
Returns the length of the hypotenuse given the catheti (i.e. legs) a
and b
(integer
s or float
s) or null if the parameters are invalid.
Each of the next functions accept as parameter one or more float
s (or integer
s) and return a float
, or null
if the parameters are invalid. Angles are expressed in radians (both input and output values).
Use deg()
and rad()
for angle conversions.
cos (x)
- compute cosinesin (x)
- compute sinetan (x)
- compute tangentacos (x)
- compute arc cosineasin (x)
- compute arc sineatan (x)
- compute arc tangentatan2 (x, y)
- compute arc tangent of y/xcosh (x)
- compute hyperbolic cosinesinh (x)
- compute hyperbolic sinetanh (x)
- compute hyperbolic tangentacosh (x)
- compute area hyperbolic cosineasinh (x)
- compute area hyperbolic sineatanh (x)
- compute area hyperbolic tangentpow(x, y)
- compute xysqrt (x)
- compute square root of x
cbrt (x)
- compute cubic root of x
ceil (x)
- round up x
floor (x)
- round down x
trunc (x)
- truncate x
round (x)
- round x
to nearest valueround_int (x)
- round x
to nearest integer value (round_int()
returns an integer).exp (x)
- compute exexp2 (x)
- compute 2xlog (x)
- compute natural logarithm of x
log2 (x)
- compute base-2 logarithm of x
log10 (x)
- compute base-10 logarithm of x