cromo La guida di Cromo
Scarica PDF EN

std.math

The functions of mathematics on the numbers with a point: roots, powers, exponentials and logarithms, the trigonometric functions and their inverses, and the roundings to a whole number. They work on f64; an f32 is converted.

cromo
import std.math

f64 diagonal = math.sqrt(2.0)                  // 1.4142135623730951
f64 angle = math.atan2(1.0, 1.0)               // pi / 4
f64 doubled = math.pow(2.0, 10.0)              // 1024
f64 whole = math.floor(-2.5)                   // -3
println("{:.3f}", math.sin(math.pi() / 6.0))   // 0.500

The guide: Numbers and operators.

Generata dalla documentazione nei sorgenti della libreria, che è in inglese.

#Funzioni

#pi

cromo
f64 pi()

The ratio of a circle to its diameter, 3.141592653589793.

#e

cromo
f64 e()

The base of the natural logarithms, 2.718281828459045.

#infinity

cromo
f64 infinity()

The infinity, larger than every number: -math.infinity() is the smallest.

#nan

cromo
f64 nan()

A value that is not a number, as the result of 0.0 / 0.0: it is different from every number and from itself, and isNaN recognizes it.

Where a function has no result it gives this one, and not what the processor makes by itself, whose sign changes from one processor to another.

#isNaN

cromo
bool isNaN(f64 x)

Whether x is not a number.

#isInfinite

cromo
bool isInfinite(f64 x)

Whether x is the infinity or its opposite.

#abs

cromo
f64 abs(f64 x)

x without its sign.

#trunc

cromo
f64 trunc(f64 x)

x without what is after the point: the whole number towards zero. trunc(-2.7) is -2.

#floor

cromo
f64 floor(f64 x)

The largest whole number that is not greater than x. floor(-2.5) is -3.

#ceil

cromo
f64 ceil(f64 x)

The smallest whole number that is not less than x. ceil(2.1) is 3.

#round

cromo
f64 round(f64 x)

The nearest whole number; a number halfway between two goes away from zero: round(2.5) is 3 and round(-2.5) is -3.

#mod

cromo
f64 mod(f64 x, f64 y)

The remainder of x / y, with the sign of x, as % of the integers: mod(7.5, 2.0) is 1.5. It is exact. Not a number when y is 0 or x is infinite.

#min

cromo
f64 min(f64 a, f64 b)

The smaller of two numbers. Not a number if one of them is not; -0.0 is smaller than 0.0.

#max

cromo
f64 max(f64 a, f64 b)

The larger of two numbers. Not a number if one of them is not; 0.0 is larger than -0.0.

#sqrt

cromo
f64 sqrt(f64 x)

The square root of x, rounded exactly. Not a number for a negative x.

#hypot

cromo
f64 hypot(f64 x, f64 y)

The square root of x * x + y * y, the length of the diagonal of a rectangle, without the squares going out of the range of the numbers.

#exp

cromo
f64 exp(f64 x)

e to the power x.

#log

cromo
f64 log(f64 x)

The natural logarithm of x, in base e. Not a number for a negative x, the opposite of the infinity for 0.

#log2

cromo
f64 log2(f64 x)

The logarithm of x in base 2: log2(8.0) is 3.

#log10

cromo
f64 log10(f64 x)

The logarithm of x in base 10: log10(1000.0) is 3.

#pow

cromo
f64 pow(f64 x, f64 y)

x to the power y. pow(x, 0.0) is 1 for every x; a negative x with a y that is not whole gives not a number.

#sin

cromo
f64 sin(f64 x)

The sine of x, an angle in radians.

#cos

cromo
f64 cos(f64 x)

The cosine of x, an angle in radians.

#tan

cromo
f64 tan(f64 x)

The tangent of x, an angle in radians.

#asin

cromo
f64 asin(f64 x)

The angle whose sine is x, from -pi / 2 to pi / 2. Not a number for |x| > 1.

#acos

cromo
f64 acos(f64 x)

The angle whose cosine is x, from 0 to pi. Not a number for |x| > 1.

#atan

cromo
f64 atan(f64 x)

The angle whose tangent is x, from -pi / 2 to pi / 2.

#atan2

cromo
f64 atan2(f64 y, f64 x)

The angle of the point (x, y) seen from the origin, from -pi to pi: the angle whose tangent is y / x, in the quadrant of the point. atan2(1.0, -1.0) is 3 pi / 4.