Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "ramp"
description = "A high-performance multiple-precision arithmetic library"
version = "0.3.3"
version = "0.3.4"
authors = ["James Miller <[email protected]>"]
build = "build.rs"
license = "Apache-2.0"
Expand Down Expand Up @@ -33,5 +33,5 @@ gcc = "0.3"

[dev-dependencies]
rust-gmp = "0.2"
quickcheck = "0.2"
quickcheck_macros = "0.2"
quickcheck = "0.4"
quickcheck_macros = "0.4"
23 changes: 12 additions & 11 deletions src/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3344,7 +3344,8 @@ macro_rules! impl_from_prim (
let vabs = val.abs();
let mask : BaseInt = !0;
let vlow = vabs & (mask as $t);
let vhigh = vabs >> Limb::BITS;
// This won't actually wrap, since $t is bigger than BaseInt
let vhigh = vabs.wrapping_shr(Limb::BITS as u32);

let low_limb = Limb(vlow as BaseInt);
let high_limb = Limb(vhigh as BaseInt);
Expand Down Expand Up @@ -3372,7 +3373,6 @@ macro_rules! impl_from_prim (
};
(unsigned $($t:ty),*) => {
$(impl ::std::convert::From<$t> for Int {
#[allow(exceeding_bitshifts)] // False positives for the larger-than BaseInt case
fn from(val: $t) -> Int {
if val == 0 {
return Int::zero();
Expand All @@ -3381,7 +3381,8 @@ macro_rules! impl_from_prim (
if std::mem::size_of::<$t>() > std::mem::size_of::<BaseInt>() {
let mask : BaseInt = !0;
let vlow = val & (mask as $t);
let vhigh = val >> Limb::BITS;
// This won't actually wrap, since $t is bigger than BaseInt
let vhigh = val.wrapping_shr(Limb::BITS as u32);

let low_limb = Limb(vlow as BaseInt);
let high_limb = Limb(vhigh as BaseInt);
Expand Down Expand Up @@ -3474,7 +3475,6 @@ impl FromStr for Int {
macro_rules! impl_from_for_prim (
(signed $($t:ty),*) => (
$(impl<'a> ::std::convert::From<&'a Int> for $t {
#[allow(exceeding_bitshifts)] // False positives for the larger-than BaseInt case
fn from(i: &'a Int) -> $t {
let sign = i.sign() as $t;
if sign == 0 {
Expand All @@ -3486,8 +3486,9 @@ macro_rules! impl_from_for_prim (
let lower = i.to_single_limb().0 as $t;
let higher = unsafe { (*i.ptr.offset(1)).0 } as $t;

// Combine the two
let n : $t = lower | (higher << Limb::BITS);
// Combine the two. This won't actually wrap, since $t is
// bigger than BaseInt
let n : $t = lower | higher.wrapping_shl(Limb::BITS as u32);

// Apply the sign
return n.wrapping_mul(sign);
Expand All @@ -3502,7 +3503,6 @@ macro_rules! impl_from_for_prim (
);
(unsigned $($t:ty),*) => (
$(impl<'a> ::std::convert::From<&'a Int> for $t {
#[allow(exceeding_bitshifts)] // False positives for the larger-than BaseInt case
fn from(i: &'a Int) -> $t {
// This does the conversion ignoring the sign

Expand All @@ -3515,8 +3515,9 @@ macro_rules! impl_from_for_prim (
let lower = i.to_single_limb().0 as $t;
let higher = unsafe { (*i.ptr.offset(1)).0 } as $t;

// Combine the two
let n : $t = lower | (higher << Limb::BITS);
// Combine the two. This won't actually wrap, since $t is
// bigger than BaseInt
let n : $t = lower | higher.wrapping_shl(Limb::BITS as u32);

return n;
}
Expand Down Expand Up @@ -4382,11 +4383,11 @@ mod test {

assert!(x1 == x2);

let mut hasher = std::hash::SipHasher::new();
let mut hasher = std::collections::hash_map::DefaultHasher::new();
x1.hash(&mut hasher);
let x1_hash = hasher.finish();

let mut hasher = std::hash::SipHasher::new();
let mut hasher = std::collections::hash_map::DefaultHasher::new();
x2.hash(&mut hasher);
let x2_hash = hasher.finish();

Expand Down