float
Floats of either format, f32 or f64: square roots, transcendental functions, roundings, and tests, each computed
in its argument’s format and giving a Value of that format.
Operations follow ECMAScript numeric special cases, with Saka’s canonical zero and nan. Angles use radians.
The transcendental functions, from exp to atan2, give the same result on every host. They are not correctly
rounded: each is the correctly rounded Value of its format or one next to it, counting the one zero once, and
atan2 at most two Values away.
A function runs once for each combination of the Values of its ! arguments.
Write these names after float::, as in float::sqrt.
sqrt
def sqrt[set T: floating](value! T)! shape(T)Square root, rounded once into its argument’s format; negative inputs produce nan.
exp
def exp[set T: floating](value! T)! shape(T)Natural exponential, e raised to the input power.
ln
def ln[set T: floating](value! T)! shape(T)Natural logarithm; zero produces negative infinity and negative inputs produce nan.
log2
def log2[set T: floating](value! T)! shape(T)Base-two logarithm; zero produces negative infinity and negative inputs produce nan.
log10
def log10[set T: floating](value! T)! shape(T)Base-ten logarithm; zero produces negative infinity and negative inputs produce nan.
sin
def sin[set T: floating](value! T)! shape(T)Sine of an angle in radians.
cos
def cos[set T: floating](value! T)! shape(T)Cosine of an angle in radians.
tan
def tan[set T: floating](value! T)! shape(T)Tangent of an angle in radians.
asin
def asin[set T: floating](value! T)! shape(T)Inverse sine in radians; inputs outside [-1, 1] produce nan.
acos
def acos[set T: floating](value! T)! shape(T)Inverse cosine in radians; inputs outside [-1, 1] produce nan.
atan
def atan[set T: floating](value! T)! shape(T)Inverse tangent in radians.
pow
def pow[set T: floating](base! T, exponent! T)! shape(T)Raises base to exponent, using ECMAScript exponentiation special cases: a nan exponent, and 1 or -1 to an
infinite one, produce nan.
atan2
def atan2[set T: floating](y! T, x! T)! shape(T)Angle in radians of the point (x, y), with the quadrant selected from both signs.
floor
def floor[set T: floating](value! T)! shape(T)Rounds toward negative infinity; preserves infinities and nan. Its Set runs from the floor of its argument’s least
Value to that of its greatest: float::floor of f64:{0.5..2.5} is f64:{0..2}.
ceil
def ceil[set T: floating](value! T)! shape(T)Rounds toward positive infinity; preserves infinities and nan. Its Set runs from the ceiling of its argument’s
least Value to that of its greatest.
round
def round[set T: floating](value! T)! shape(T)Rounds to the nearest integer, choosing the even integer at a tie, so both 1.5 and 2.5 round to 2; preserves
infinities and nan. Its Set runs from the rounding of its argument’s least Value to that of its greatest.
trunc
def trunc[set T: floating](value! T)! shape(T)Discards the fractional part toward zero; preserves infinities and nan. Its Set runs from the truncation of its
argument’s least Value to that of its greatest.
is_finite
def is_finite[set T: floating](value! T)! boolTrue for floats other than infinities and nan.
is_integral
def is_integral[set T: floating](value! T)! boolTrue for finite integral floats, of any size.
format
def format[set T: floating](value! T)! strReturns the fewest digits that read back as the same Value of its argument’s format, as ECMAScript spells a number,
without locale rules: an f32 nearest 0.1 gives "0.1". Special values use nan, inf, -inf, and 0.
format_fixed
def format_fixed[set T: floating](value! T, digits! int:{0..100})! strFormats the exact Value with 0–100 digits after the decimal point using ECMAScript fixed formatting, so the f32
nearest 0.1 with 10 digits gives "0.1000000015". This rounding follows decimal string formatting, not
float::round’s ties to even.
format_scientific
def format_scientific[set T: floating](value! T, digits! int:{0..100})! strFormats the exact Value with 0–100 digits after the decimal point in scientific notation.
format_precision
def format_precision[set T: floating](value! T, digits! int:{1..100})! strFormats the exact Value with 1–100 significant digits using ECMAScript precision formatting.