Standard library
Standard modules are bundled with Hyle. Imports never fetch code over the network. Use a namespace, optionally rename it, or import a single function:
use "@hyle/maths";use "@hyle/stats" as statistics;use "@hyle/maths/cos" as cosine;Call namespaced functions with ::: maths::cos(angle). These names are not
reserved keywords. Aliases must be unique and cannot be shadowed by local bindings.
The same imports work in .hyleworld recipes.
| Module | Functions and constants |
|---|---|
maths |
pi, tau, e; sqrt, cbrt, exp, exp2, log, log2, log10, expm1, log1p; sin, cos, tan, arcsin, arccos, arctan, arctan2; sinh, cosh, tanh; floor, ceil, trunc, round, abs, sign; radians, degrees, minimum, maximum, power, hypot, remainder, clip, isfinite, isnan, isinf, isclose |
linalg |
dot, cross, norm, distance, normalize, normalize_or_zero |
stats |
sum, prod, min, max, mean, average, var, std, argmin, argmax |
random |
key, uniform, integers, normal, bernoulli |
Maths scalar functions take Float arguments. Vector/statistics functions operate
on nonempty fixed Float arrays; they do not reduce the whole simulation.
cross requires length three. normalize rejects zero vectors;
normalize_or_zero returns zero. argmin/argmax return the first tied index.
average(values, weights) requires matching arrays and nonzero total weight.
var(values, ddof) and std(values, ddof) require an explicit Int correction
between zero and one less than the array length. round uses ties-to-even.
remainder(x,y) uses x - floor(x/y)*y.
isclose(a,b,rtol,atol) uses nonnegative finite tolerances and scales relative
error by abs(b); equal infinities compare true, NaNs compare false.
Random calls are explicit and repeatable:
use "@hyle/random";use "@hyle/maths";use models {Water};
let seed = random::key(42, [3, 7, 0], 0, 1);let density = random::uniform(seed, 0, 0.8, 1.0);place Water at [3, 7, 0] { set target.density = density;}key(seed, identity, tick, stream) takes Int values; identity can also be a fixed
Int array. Sampling takes (key,index,...): uniform(key,index,low,high),
integers(key,index,low,high), normal(key,index,loc,scale), and
bernoulli(key,index,probability). Upper bounds are exclusive for nondegenerate
uniform and integer intervals. Integer interval widths cannot exceed 2^32.
Float uniform samples use a 24-bit grid before scaling, including with CPU-64.
Negative normal scale and probabilities outside [0,1] fail.
Target availability
Section titled “Target availability”CPU-32 and CPU-64 support the catalog. GPU-32 currently excludes expm1 and
log1p. GPU-64 supports basic math, vectors/statistics, random operations, and
sin, cos, exp, log; the remaining advanced scalar functions are rejected
when planning the simulation. GPU-64 requires a compatible native device and is
unavailable in the browser. There is no silent change of precision.
World construction currently uses CPU-64, regardless of the later simulation
solver. Standard calls are allowed in world recipes and simulation expressions.
They cannot currently be evaluated in compile-time .hyle constants/defaults;
use literals there or assign computed initial values in the world recipe.
Different execution profiles can produce slightly different numerical results.