Expand description
§i48: A 48-bit Signed Integer Type
The i48 crate provides a 48-bit signed integer type for Rust, filling the gap between
i32 and i64. This type may be useful in certain scenarios where 48-bit precision
is required but 64 bits would be excessive.
§Features
- Efficient 48-bit signed integer representation
- Seamless conversion to and from
i64 - Support for basic arithmetic operations with overflow checking
- Bitwise operations
- Conversions from various byte representations (little-endian, big-endian, native)
- Implements common traits like
Debug,Display,PartialEq,Eq,PartialOrd,Ord, andHash
This crate came about as a twin project to the [i24](https://crates.io/crates/i24) crate, one that supports 48-bit signed integers.
The i48 struct also has pyo3 bindings for use in Python. Enable the pyo3 feature to use the pyo3 bindings.
§Usage
Add this to your Cargo.toml:
[dependencies]
i48 = "1.2.0"Then, in your Rust code:
use i48::i48;
let a: i48 = 1000.into();
let b: i48 = 2000.into();
let c = a + b;
assert_eq!(c.to_i64(), 3000);§Safety and Limitations
While i48 strives to behave similarly to Rust’s built-in integer types, there are some
important considerations:
- The valid range for
i48is [−140,737,488,355,328; 140,737,488,355,327]. - Overflow behavior in arithmetic operations matches that of
i64. - Bitwise operations are performed on the 48-bit representation.
Always use checked arithmetic operations when dealing with untrusted input or when overflow/underflow is a concern.
§Features
- pyo3: Enables the pyo3 bindings for the
i48type.
§Contributing
Contributions are welcome! Please feel free to submit a Pull Request. This really needs more testing and verification.
§License
This project is licensed under MIT - see the LICENSE file for details.
Structs§
- i48
- An experimental 48-bit signed integer type.
Enums§
- I48Error
- Represents errors that can occur when working with the
i48type.