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
//! This crate provides some extra simple types.
//!
//! u128 and i128
//! =============
//!
//! Support signed and unsigned 128-bit integers. Also standard primitive operations are supported.
//!
//! These are mainly needed where explicit 128-bit integer types are required. If the purpose is to
//! operate on "very large integers", the [bigint](https://crates.io/crates/num-bigint) library may
//! be more suitable.
//!
//! ```rust
//! extern crate extprim;
//!
//! use std::str::FromStr;
//! use extprim::i128::i128;
//!
//! fn main() {
//!     let a = i128::from_str("100000000000000000000000000000000000000").unwrap();
//!             // convert string to u128 or i128
//!     let b = i128::new(10).pow(38);
//!             // 64-bit integers can be directly new'ed
//!     assert_eq!(a, b);
//!     let c = i128::from_parts(5421010862427522170, 687399551400673280);
//!             // represent using the higher- and lower-64-bit parts
//!     let d = c - a;
//!             // standard operators like +, -, *, /, %, etc. work as expected.
//!     assert_eq!(d, i128::zero());
//! }
//! ```
//!
//! Literal macros
//! ==============
//!
//! The extra primitive types can be created via the literal macros using the `extprim_literals` compiler plugin in
//! nightly, or with [syntex](https://crates.io/crates/syntex) in stable. Please check the [documentation of
//! `extprim_literals`](../../extprim_literals/index.html) for details.
//!
//! ```ignore
//! #![feature(plugin)]
//! #![plugin(extprim_literals)]
//!
//! extern crate extprim;
//!
//! fn main() {
//!     let a = u128!(0xffeeddcc_bbaa9988_77665544_33221100);
//!     let b = u128!(73);
//!     let result = a / b;
//!     let expected = u128!(4_660_183_619_323_730_626_856_278_982_251_165_334);
//!     assert_eq!(a / b, expected);
//! }
//! ```

#![cfg_attr(extprim_channel="unstable", feature(asm, test, specialization, float_extras))]
// feature requirement:
//  - asm: to provide a fast implementation of u64_long_mul in x86_64
//  - test: benchmarking
//  - specialization: to allow ToExtraPrimitive inherit from ToPrimitive, while ensuring conversion
//                    between the 128-bit types remain correct
//  - float_extras: to use `ldexp`, to have a more efficient conversion from u128 to f64.

#[cfg(extprim_channel="unstable")]
extern crate test;

extern crate core;
extern crate rand;
#[macro_use]
extern crate lazy_static;
extern crate num_traits;

mod error;
#[macro_use]
mod forward;
pub mod traits;
pub mod u128;
pub mod i128;
mod compiler_rt;