Float32

The Float32 module provides functions for working with 32-bit (single-precision) floating-point numbers. Use Float32 for graphics, audio processing, GPU computation, and memory-constrained applications where 64-bit precision is not required.

When to use Float32 vs Float

Kit's default Float type is 64-bit (double precision). Use Float32 when memory efficiency matters, when interfacing with graphics/audio APIs, or when working with SIMD operations that benefit from 32-bit floats.

Overview

Float32 follows the IEEE 754 single-precision format with approximately 7 decimal digits of precision. The range is approximately ±3.4 × 10^38.

Creation

Float32.from-float
Float -> Float32
Converts a 64-bit Float to Float32. Precision may be lost.
f = Float32.from-float 3.14159
println f
Float32.from-int
Int -> Float32
Converts an Int to Float32.

Arithmetic

Float32 supports the same arithmetic operations as Float: add, sub, mul, div, and neg.

Float32.sqrt
Float32 -> Float32
Square root of a Float32 value.
Float32.abs
Float32 -> Float32
Absolute value of a Float32.

Conversion

Float32.to-float
Float32 -> Float
Converts a Float32 to a 64-bit Float (lossless).
Float32.to-int
Float32 -> Int
Converts a Float32 to an Int by truncating toward zero.
Float32.to-string
Float32 -> String
Converts a Float32 to its string representation.