std.math is the libm scalar functions over float64, added in 1.4.0. It binds 22 of libm’s functions straight across the foreign boundary, with no C shim of its own: every dusk binary already links -lm, so the symbols are there for the taking. Two constants, pi and e, come back as plain Dusk literals, and two predicates, is_nan and is_inf, are pure Dusk over IEEE 754 algebra with no foreign call. The module lives at lib/std/math.dusk.
@importstd.math
Imported names are flat: after @import std.math you call sin, sqrt, pi, and the rest with no prefix. See stdlib overview for how imports work in general.
Every function here takes and returns float64. There is no float32 overload and no integer variant; widen an integer to float64 before you call.
libm keeps pi and e as C macros rather than linkable symbols, so there is nothing to bind for them across the boundary. Each returns the value as a plain Dusk float64 literal instead. Call them like any other function: pi() and e().
Both predicates are pure Dusk over IEEE 754’s own algebra, no foreign call. NaN is the only float64 value that compares unequal to itself, so is_nan(x) is !(x == x). A finite value only satisfies x + x == x at 0.0, so is_inf(x) is x == x && x + x == x && x != 0.0: the first clause rules out NaN, the last excludes zero, and what remains is exactly the two infinities.
A raw float64’s text format is not pinned across platforms, so a sample checks a result with a bool comparison against a known value rather than printing the float. sqrt(16.0), floor(3.7), and the rest are exact here, so == is safe.
math_check.dusk
@paradigmprocedural
@importstd.math
funcmain() ->int32 {
// A raw float64's text form is not pinned across platforms, so we test
// against a known value with a bool comparison instead of printing it.
ifsqrt(16.0) ==4.0 {
println("sqrt ok") // sqrt ok
}
iffloor(3.7) ==3.0&&ceil(3.2) ==4.0 {
println("round ok") // round ok
}
iffabs(-2.5) ==2.5 {
println("abs ok") // abs ok
}
// is_nan and is_inf are pure Dusk over IEEE 754, no foreign call.