fixed_bigint/
lib.rs

1// Copyright 2021 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#![no_std]
16
17//! A fixed-size big integer implementation, unsigned only.
18//! [FixedUInt] implements a [num_traits::PrimInt] trait, mimicking built-in `u8`, `u16` and `u32` types.
19//! [num_integer::Integer] is also implemented.
20//!
21//! Simple usage example:
22//! ```
23//! use fixed_bigint::FixedUInt;
24//!
25//! let a : FixedUInt<u8,2> = 200u8.into();
26//! assert_eq!( a + a , 400u16.into() );
27//! assert_eq!( a * &100u8.into(), 20000u16.into() )
28//! ```
29//!
30//! Use Integer trait:
31//! ```
32//! use fixed_bigint::FixedUInt;
33//! use num_integer::Integer;
34//!
35//! let a : FixedUInt<u8,2> = 400u16.into();
36//! assert_eq!( a.is_multiple_of( &(8u8.into()) ) , true );
37//! assert_eq!( a.gcd( &(300u16.into() )) , 100u8.into() );
38//! assert_eq!( a.lcm( &(440u16.into() )) , 4400u16.into() );
39//! ```
40
41/// Re-export num_traits crate
42pub use num_traits;
43
44/// Re-export num_integer crate
45pub use num_integer;
46
47/// Fixed-size big integer implementation
48pub mod fixeduint;
49
50/// Bits that should be in num_traits
51pub mod patch_num_traits;
52
53/// Machine word and doubleword
54mod machineword;
55
56pub use crate::fixeduint::FixedUInt;
57pub use crate::machineword::MachineWord;