Remove U128 and bump version to 0.4
This commit is contained in:
parent
706bed1a79
commit
d9de1e1271
|
@ -4,7 +4,7 @@ homepage = "http://parity.io"
|
|||
repository = "https://github.com/paritytech/parity-common"
|
||||
license = "MIT/Apache-2.0"
|
||||
name = "uint"
|
||||
version = "0.3.1"
|
||||
version = "0.4.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
|
||||
[dependencies]
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
# Big unsigned integer types
|
||||
|
||||
Implementation of a various large-but-fixed sized unsigned integer types.
|
||||
Macros to implement large-but-fixed sized unsigned integer types.
|
||||
The functions here are designed to be fast.
|
||||
|
||||
The crate exports two commonly used types: `U256` and `U512`. Other sizes can be constructed with `construct_uint!(NAME, SIZE_IN_WORDS)`, e.g. `construct_uint!(U128, 2);`.
|
||||
The crate builds and exports two commonly used types: `U256` and `U512`. Other sizes can be constructed with `construct_uint!(NAME, SIZE_IN_WORDS)`, e.g. `construct_uint!(U128, 2);`.
|
||||
|
||||
Run tests with `cargo test --features=std,impl_quickcheck_arbitrary`.
|
||||
Run tests with `cargo test --features=std,impl_quickcheck_arbitrary --release`.
|
|
@ -16,15 +16,9 @@
|
|||
|
||||
extern crate core;
|
||||
extern crate test;
|
||||
#[macro_use]
|
||||
extern crate crunchy;
|
||||
#[macro_use]
|
||||
extern crate uint;
|
||||
|
||||
use uint::{U256, U512};
|
||||
// NOTE: constructing the type inside the benchmark crate is much faster so the
|
||||
// numbers for `U128` are better than they'd normally be.
|
||||
construct_uint!(U128, 2);
|
||||
|
||||
use test::{Bencher, black_box};
|
||||
|
||||
|
@ -127,11 +121,13 @@ fn u256_full_mul(b: &mut Bencher) {
|
|||
|
||||
|
||||
#[bench]
|
||||
// NOTE: uses native `u128` and does not measure this crates performance,
|
||||
// but might be interesting as a comparison.
|
||||
fn u128_mul(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let n = black_box(10000);
|
||||
(1..n).fold(U128([12345u64, 0u64]), |old, new| {
|
||||
old.overflowing_mul(U128::from(new | 1)).0
|
||||
(1..n).fold(12345u128, |old, new| {
|
||||
old.overflowing_mul(u128::from(new | 1u32)).0
|
||||
})
|
||||
});
|
||||
}
|
||||
|
|
|
@ -12,8 +12,6 @@ use core::u64::MAX;
|
|||
use core::str::FromStr;
|
||||
use uint::{U256, U512, FromDecStrErr};
|
||||
|
||||
construct_uint!(U128, 2);
|
||||
|
||||
#[test]
|
||||
fn uint256_checked_ops() {
|
||||
let z = U256::from(0);
|
||||
|
@ -360,14 +358,6 @@ fn should_format_and_debug_correctly() {
|
|||
test(0x1000, "1000", "4096");
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn display_u128() {
|
||||
let expected = "340282366920938463463374607431768211455";
|
||||
let value = U128::MAX;
|
||||
assert_eq!(format!("{}", value), expected);
|
||||
assert_eq!(format!("{:?}", value), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn display_u256() {
|
||||
let expected = "115792089237316195423570985008687907853269984665640564039457584007913129639935";
|
||||
|
@ -419,42 +409,6 @@ fn uint256_overflowing_mul() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uint128_add() {
|
||||
assert_eq!(
|
||||
U128::from_str("fffffffffffffffff").unwrap() + U128::from_str("fffffffffffffffff").unwrap(),
|
||||
U128::from_str("1ffffffffffffffffe").unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uint128_add_overflow() {
|
||||
assert_eq!(
|
||||
U128::from_str("ffffffffffffffffffffffffffffffff").unwrap()
|
||||
.overflowing_add(
|
||||
U128::from_str("ffffffffffffffffffffffffffffffff").unwrap()
|
||||
),
|
||||
(U128::from_str("fffffffffffffffffffffffffffffffe").unwrap(), true)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
#[cfg(debug_assertions)]
|
||||
#[allow(unused_must_use)]
|
||||
fn uint128_add_overflow_panic() {
|
||||
U128::from_str("ffffffffffffffffffffffffffffffff").unwrap()
|
||||
+
|
||||
U128::from_str("ffffffffffffffffffffffffffffffff").unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uint128_mul() {
|
||||
assert_eq!(
|
||||
U128::from_str("fffffffff").unwrap() * U128::from_str("fffffffff").unwrap(),
|
||||
U128::from_str("ffffffffe000000001").unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uint512_mul() {
|
||||
assert_eq!(
|
||||
|
@ -1196,13 +1150,11 @@ pub mod laws {
|
|||
}
|
||||
|
||||
construct_uint!(U64, 1);
|
||||
construct_uint!(U128, 2);
|
||||
construct_uint!(U256, 4);
|
||||
construct_uint!(U512, 8);
|
||||
construct_uint!(U1024, 16);
|
||||
|
||||
uint_laws!(u64, U64);
|
||||
uint_laws!(u128, U128);
|
||||
uint_laws!(u256, U256);
|
||||
uint_laws!(u512, U512);
|
||||
uint_laws!(u1024, U1024);
|
||||
|
|
Loading…
Reference in New Issue