Crates.io | fixed-bigint |
lib.rs | fixed-bigint |
version | 0.1.11 |
source | src |
created_at | 2021-04-07 03:20:35.951237 |
updated_at | 2024-10-06 02:39:39.36392 |
description | Fixed-size big integer implementation for Rust |
homepage | https://github.com/kaidokert/fixed-bigint-rs |
repository | https://github.com/kaidokert/fixed-bigint-rs |
max_upload_size | |
id | 380197 |
size | 154,068 |
Unsigned BigInt implementation, backed by a fixed-size array.
Important: Requires at least Rust 1.51 stable, as it uses min_const_generics
FixedUInt<u8,4>
,FixedUInt<u16,2>
or FixedUInt<u32,1>
all create a 32-bit unsigned integer, that behaves mostly the same as builtin u32
.
FixedUInt<u32, 64>
creates a 2048-bit value, that uses native 32-bit math. If running on 8-bit CPU, FixedUInt<u8, 2048>
would work the same, just very much slower.
The crate is written for no_std
and no_alloc
environments with option for panic-free operation, i.e. embedded MCUs. At least for now, focus is on correctness first and then generated code size, performance comes last. The aim is not to bring in 64-bit math dependencies on 32-bit CPU, to save code space.
The arithmetic operands ( +, -, .add() ) panic on overflow, just like native integer types. Panic-free alternatives like overlowing_add
and wrapping_add
are supported.
In addition to basic arithmetic, two main traits are implemented: num_traits::PrimInt and num_integer::Integer.
TODO list:
unchecked_math
operands, unchecked_mul, unchecked_div etc.Note: This crate is mostly written as an exercise for learning the Rust type system and understanding how well it works on microcontrollers, its fitness for any particular purpose or quality has precisely zero guarantees.
If you are looking for production quality implementation with no_std
, fixed-size bigint, suitable for crypto, please check out crypto-bigint crate.
See CONTRIBUTING.md
for details.
Apache 2.0; see LICENSE
for details.
This project is not an official Google project. It is not supported by Google and Google specifically disclaims all warranties as to its quality, merchantability, or fitness for a particular purpose.