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//!
34//! `FixedUInt<T, N, P>` is `N` limbs of a primitive `T` (`u8`/`u16`/`u32`/`u64`)
35//! with a compile-time `Personality` (`Nct` or `Ct`) that selects between
36//! value-dependent and constant-time impl bodies at every operator.
37//!
38//! Basic usage:
39//! ```
40//! use fixed_bigint::FixedUInt;
41//!
42//! let a : FixedUInt<u8,2> = 200u8.into();
43//! assert_eq!( a + a , 400u16.into() );
44//! assert_eq!( a * &100u8.into(), 20000u16.into() )
45//! ```
46//!
47//! With the `num-traits` feature (default), `FixedUInt` also implements
48//! `num_integer::Integer` and the `num_traits::PrimInt` bundle:
49//! ```
50//! # #[cfg(feature = "num-traits")] {
51//! use fixed_bigint::FixedUInt;
52//! use num_integer::Integer;
53//!
54//! let a : FixedUInt<u8,2> = 400u16.into();
55//! assert_eq!( a.is_multiple_of( &(8u8.into()) ) , true );
56//! assert_eq!( a.gcd( &(300u16.into() )) , 100u8.into() );
57//! assert_eq!( a.lcm( &(440u16.into() )) , 4400u16.into() );
58//! # }
59//! ```
60
61/// Fixed-size big integer implementation
62pub mod fixeduint;
63
64/// Machine word and doubleword
65mod machineword;
66
67pub use crate::fixeduint::{FixedUInt, NonZeroFixedUInt};
68pub use crate::machineword::MachineWord;