1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright 2025-2026 Gabriel Bjørnager Jensen.
//
// SPDX: MIT OR Apache-2.0
//! MultiType is a crate for generalising
//!
//! MultiType provides traits such as [`Unsigned`]
//! and [`FloatingPoint`] to abstract over a set of
//! equivalent primitive types. These traits are
//! intended to provide one-to-one copies of the
//! primary interfaces that the primitive types
//! define.
//!
//! # Overview
//!
//! The complete list of abstraction traits is:
//!
//! * [`Integral`]
//! * [`Signed`]
//! * [`Unsigned`]
//! * [`FloatingPoint`]
//! * [`StdFloatingPoint`]
//!
//!
//! # Examples
//!
//! A generic Fibonacci sequence:
//!
//! ```rust
//! use multitype::Unsigned;
//!
//! fn f<T: Unsigned + From<u8>>(x: T) -> T {
//! let mut y = T::from(0_u8);
//! let mut y_m1 = T::from(0_u8);
//! let mut y_m2 = T::from(1_u8);
//!
//! let mut i = T::from(0_u8);
//! while i < x {
//! y = y_m1 + y_m2;
//!
//! y_m2 = y_m1;
//! y_m1 = y;
//!
//! i += T::from(1_u8);
//! }
//!
//! y
//! }
//!
//! assert_eq!(f(0_u8), 0);
//! assert_eq!(f(1_u8), 1);
//!
//! assert_eq!(f(2_u16), 1);
//! assert_eq!(f(3_u16), 2);
//!
//! assert_eq!(f(4_u32), 3);
//! assert_eq!(f(5_u32), 5);
//!
//! assert_eq!(f(6_u64), 8);
//! assert_eq!(f(7_u64), 13);
//!
//! assert_eq!(f(8_u128), 21);
//! assert_eq!(f(9_u128), 34);
//! ```
//!
//! # Feature gates
//!
//! Default features:
//! * `alloc`
//! * `std`
//!
//! Dependency features:
//!
//! Unstable features:
//! * `f128`: Enables support for [`f128`]
//! * `f16`: Enables support for [`f16`]
//! * `unstable_docs`: Enables unstable documentation features
//!
//! Unstable gates can be expected to be removed as
//! their facilities stabilise.
//!
//! # MSRV policy
//!
//! The goal of MultiType is to provide generic
//! traits that bind as much of the standard
//! interfaces as possible. Items that are added
//! after the MSRV will be backported.
//!
//! # Copyright and licence
//!
//! Copyright © 2025-2026 Gabriel Bjørnager
//! Jensen.
//!
//! MultiType is distributed under either an MIT
//! licence (see `LICENCE-MIT`) or version 2.0 of
//! the Apache License (see `LICENCE-APACHE`), at
//! your option.
extern crate self as multitype;
extern crate alloc;
extern crate std;
pub use FloatingPoint;
pub use Integral;
pub use Signed;
pub use Unsigned;
pub use StdFloatingPoint;
use CarryingMulAdd;
use OneLessThanNextPowerOfTwo;