i24 v2 – 24-bit Signed Integer for Rust

123 points JackG049 64 comments

https://preview.redd.it/niamjyc4prxe1.png?width=256&format=png&auto=webp&s=71b5bbebbcdce40f0351e4a0db407e0c8921eb0e

Version 2.0 of i24, a 24-bit signed integer type for Rust is now available on crates.io. It is designed for use cases such as audio signal processing and embedded systems, where 24-bit precision has practical relevance.

About

i24 fills the gap between i16 and i32, offering:

  • Efficient 24-bit signed integer representation
  • Seamless conversion to and from i32
  • Basic arithmetic and bitwise operations
  • Support for both little-endian and big-endian byte conversions
  • Optional serde and pyo3 feature flags

Acknowledgements

Thanks to Vrtgs for major contributions including no_std support, trait improvements, and internal API cleanups. Thanks also to Oderjunkie for adding saturating_from_i32. Also thanks to everyone who commented on the initial post and gave feedback, it is all very much appreciated :)

Benchmarks

i24 mostly matches the performance of i32, with small differences across certain operations. Full details and benchmark methodology are available in the benchmark report.

Usage Example

use i24::i24;

fn main() {
    let a = i24::from_i32(1000);
    let b = i24::from_i32(2000);
    let c = a + b;
    assert_eq!(c.to_i32(), 3000);

}

Documentation and further examples are available on docs.rs and GitHub.