24 releases (14 stable)

Uses old Rust 2015

1.7.1 May 30, 2020
1.7.0 Apr 21, 2019
1.6.0 May 13, 2018
1.5.1 Jan 14, 2018
0.5.1 Mar 21, 2015

#632 in Algorithms

Download history 825/week @ 2024-06-10 877/week @ 2024-06-17 1110/week @ 2024-06-24 951/week @ 2024-07-01 831/week @ 2024-07-08 1003/week @ 2024-07-15 706/week @ 2024-07-22 991/week @ 2024-07-29 970/week @ 2024-08-05 1240/week @ 2024-08-12 1504/week @ 2024-08-19 1082/week @ 2024-08-26 1195/week @ 2024-09-02 997/week @ 2024-09-09 690/week @ 2024-09-16 1302/week @ 2024-09-23

4,298 downloads per month
Used in 58 crates (7 directly)

MIT/Apache

190KB
3.5K SLoC

extprim

Travis (Linux and OS X) Build status AppVeyor (Windows) Build status Coverage Status MIT / Apache 2.0

Thanks to RFC 1504 “int128”, you can use i128 and u128 directly on nightly Rust starting from 1.16. Using the built-in types are preferred.

Extra primitive types for stable Rust. Currently includes:

  • u128 (unsigned 128-bit integers)
  • i128 (signed 128-bit integers)

Documentation

You may also find other primitive types in other crates:

Usage

# Cargo.toml
[dependencies]
extprim = "1"

If you want to use the u128!() and i128!() macros, please include the extprim_literals plugin.

# Cargo.toml
[dependencies]
extprim = "1"
extprim_literals = "2"

Example

#[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);
}

Dependencies

~1–2MB
~35K SLoC