Math Functions

All 43 tested math functions compile and produce correct results, verified with both Float32 and Float64 (except exp(Float32) — one known codegen issue).

Julia 1.12 implements math functions in pure Julia (no foreigncall to libm), so they compile directly to WASM without runtime dependencies.

Supported Functions

CategoryFunctionsPath
Trigonometricsin, cos, tan, asin, acos, atanNative
Hyperbolicsinh, cosh, tanhNative
Exponentialexp, exp2, expm1Native
Logarithmiclog, log2, log10, log1pNative
Roundingfloor, ceil, round, truncNative
Roots/Powerssqrt, cbrt, hypot, fourthrootNative
Specialsincos, sinpi, cospi, tanpi, sinc, cosc, modfNative
Utilitycopysign, deg2rad, rad2deg, ldexp, mod2piNative
PowerFloat64^Float64, Float64^IntNative
Float mod/remmod(Float64), rem(Float64)Overlay

Example

using WasmTarget
bytes = compile(sin, (Float64,))
write("sin.wasm", bytes)

Optimization

Math functions benefit significantly from wasm-opt:

raw = compile(sin, (Float64,))
opt = compile(sin, (Float64,); optimize=true)
# Typical: ~80-90% size reduction