-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathlib.rs
89 lines (82 loc) · 2.91 KB
/
lib.rs
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
//! 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
//! #[macro_use] extern crate extprim_literals;
//! 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());
//!
//! const e: i128 = i128!(100000000000000000000000000000000000000);
//! // use the literal macros
//! assert_eq!(a, e);
//! }
//! ```
//!
//! 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, const_fn, i128_type))]
// 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
// - const_fn: Create 128-bit constants
// - i128_type: Conversion between built-in 128-bit integer types.
#![cfg_attr(not(feature="use-std"), no_std)]
#[cfg(extprim_channel="unstable")] extern crate test;
#[cfg(feature = "serde")]
#[macro_use]
extern crate serde;
#[cfg(feature="use-std")] extern crate core;
#[cfg(not(feature="use-std"))] extern crate core as std;
#[cfg(feature="rand")] extern crate rand;
extern crate num_traits;
#[macro_use] mod forward;
#[cfg_attr(test, macro_use)] mod format_buffer;
mod error;
pub mod traits;
pub mod u128;
pub mod i128;
mod compiler_rt;