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#![cfg_attr(
17 feature = "nightly",
18 feature(
19 const_trait_impl,
20 const_ops,
21 const_cmp,
22 const_convert,
23 const_default,
24 const_clone,
25 generic_const_exprs,
26 const_unsigned_bigint_helpers,
27 widening_mul
28 )
29)]
30#![cfg_attr(feature = "nightly", allow(incomplete_features))]
31
32//! A fixed-size big integer implementation, unsigned only.
33//! [FixedUInt] implements a [num_traits::PrimInt] trait, mimicking built-in `u8`, `u16` and `u32` types.
34//! [num_integer::Integer] is also implemented.
35//!
36//! Simple usage example:
37//! ```
38//! use fixed_bigint::FixedUInt;
39//!
40//! let a : FixedUInt<u8,2> = 200u8.into();
41//! assert_eq!( a + a , 400u16.into() );
42//! assert_eq!( a * &100u8.into(), 20000u16.into() )
43//! ```
44//!
45//! Use Integer trait:
46//! ```
47//! use fixed_bigint::FixedUInt;
48//! use num_integer::Integer;
49//!
50//! let a : FixedUInt<u8,2> = 400u16.into();
51//! assert_eq!( a.is_multiple_of( &(8u8.into()) ) , true );
52//! assert_eq!( a.gcd( &(300u16.into() )) , 100u8.into() );
53//! assert_eq!( a.lcm( &(440u16.into() )) , 4400u16.into() );
54//! ```
55
56/// Re-export num_traits crate
57pub use num_traits;
58
59/// Re-export num_integer crate
60pub use num_integer;
61
62/// Fixed-size big integer implementation
63pub mod fixeduint;
64
65/// Bits that should be in num_traits
66pub mod patch_num_traits;
67
68/// Constant versions of num_traits
69pub mod const_numtraits;
70
71/// Fused multiply-accumulate row operations
72pub mod mul_acc_ops;
73
74/// Machine word and doubleword
75mod machineword;
76
77pub use crate::fixeduint::FixedUInt;
78pub use crate::machineword::MachineWord;
79pub use crate::mul_acc_ops::MulAccOps;