Fixed-point arithmetic library for Zig. Note that we use TI notation. The integer bits (m) do not include the sign bit.
const fixed = @import("fixed");
const Q15_16 = fixed.Q(15, 16); // backed by i32
const x = Q15_16.fromFloat(f64, 3.14159);
const y = Q15_16.fromInt(2);
const z = x.add(y);Q(int_bits, frac_bits)- Fixed-point type constructorfromRaw(raw)- Construct from raw storage valuefromFloat(T, x)- Convert from floatfromInt(x)- Convert from integerfromQ(q)- Convert from another fixed-point typetoFloat(T)- Convert to floattoInt()- Convert to integertoRaw()- Get raw storage valueadd(other),sub(other),mul(other),div(other)- Arithmetic operationsnegate(),abs()- Unary operationsorder(other)- Comparisonformat(writer)- String formattingparse(input)- Parse from string
Currently no support for unsigned types
zig build
zig build testMIT