-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minor spelling and add deprecation notice to LIMB_BITS
.
#180
Conversation
65659ee
to
dab0e28
Compare
Hello, Ah I just found the development guide. |
This is excellent, thanks for the careful overview of the code. A few of the unit tests need to be patched and this will be good to go. I'll post the diff now. |
@raldone01 This should be sufficient: diff --git a/lexical-benchmark/algorithm/bigint.rs b/lexical-benchmark/algorithm/bigint.rs
index 9d20944..31394f9 100644
--- a/lexical-benchmark/algorithm/bigint.rs
+++ b/lexical-benchmark/algorithm/bigint.rs
@@ -15,7 +15,7 @@ fn standard_pow(big: &mut bigint::Bigint, exp: u32) {
fn small_pow(big: &mut bigint::Bigint, mut exp: u32) {
let shift = exp as usize;
// Mul pow5
- let small_step = if bigint::LIMB_BITS == 32 {
+ let small_step = if bigint::Limb::BITS == 32 {
u32_power_limit(5)
} else {
u64_power_limit(5)
@@ -189,7 +189,7 @@ fn karatsuba_mul_algo(big: &mut bigint::Bigint, y: &[bigint::Limb]) {
#[inline(always)]
fn new_limb(rng: &mut Rng) -> bigint::Limb {
- if bigint::LIMB_BITS == 32 {
+ if bigint::Limb::BITS == 32 {
rng.u32(..) as bigint::Limb
} else {
rng.u64(..) as bigint::Limb
diff --git a/lexical-parse-float/src/slow.rs b/lexical-parse-float/src/slow.rs
index f2b777c..30e4d52 100644
--- a/lexical-parse-float/src/slow.rs
+++ b/lexical-parse-float/src/slow.rs
@@ -649,7 +649,7 @@ pub fn byte_comp<F: RawFloat, const FORMAT: u128>(
// After this, the numerator will be non-normalized, and the
// denominator will be normalized. We need to add one to the
// quotient,since we're calculating the ceiling of the divmod.
- let (q, r) = shift.ceil_divmod(Limb::BITS);
+ let (q, r) = shift.ceil_divmod(Limb::BITS as usize);
let r = -r;
if r != 0 {
num.shl_bits(r as usize).unwrap();
diff --git a/lexical-parse-float/tests/bigfloat_tests.rs b/lexical-parse-float/tests/bigfloat_tests.rs
index 02f20ee..888afcf 100644
--- a/lexical-parse-float/tests/bigfloat_tests.rs
+++ b/lexical-parse-float/tests/bigfloat_tests.rs
@@ -2,7 +2,7 @@
mod stackvec;
-use lexical_parse_float::bigint::{Bigfloat, LIMB_BITS};
+use lexical_parse_float::bigint::{Bigfloat, Limb};
use lexical_parse_float::float::ExtendedFloat80;
use stackvec::vec_from_u32;
@@ -35,11 +35,11 @@ fn simple_test() {
assert_eq!(&*x.data, &[0, 19531250]);
assert_eq!(x.exp, 10);
- assert_eq!(x.leading_zeros(), LIMB_BITS as u32 - 25);
+ assert_eq!(x.leading_zeros(), Limb::BITS as u32 - 25);
// y has a 0 for 32-bit limbs, no 0s for 64-bit limbs.
x *= &y;
- let expected = if LIMB_BITS == 32 {
+ let expected = if Limb::BITS == 32 {
vec_from_u32(&[0, 0, 0, 9765625])
} else {
vec_from_u32(&[0, 0, 0, 0, 9765625])
@@ -52,12 +52,12 @@ fn simple_test() {
fn leading_zeros_test() {
assert_eq!(Bigfloat::new().leading_zeros(), 0);
- assert_eq!(Bigfloat::from_u32(0xFF).leading_zeros(), LIMB_BITS as u32 - 8);
+ assert_eq!(Bigfloat::from_u32(0xFF).leading_zeros(), Limb::BITS as u32 - 8);
assert_eq!(Bigfloat::from_u64(0xFF00000000).leading_zeros(), 24);
- assert_eq!(Bigfloat::from_u32(0xF).leading_zeros(), LIMB_BITS as u32 - 4);
+ assert_eq!(Bigfloat::from_u32(0xF).leading_zeros(), Limb::BITS as u32 - 4);
assert_eq!(Bigfloat::from_u64(0xF00000000).leading_zeros(), 28);
- assert_eq!(Bigfloat::from_u32(0xF0).leading_zeros(), LIMB_BITS as u32 - 8);
+ assert_eq!(Bigfloat::from_u32(0xF0).leading_zeros(), Limb::BITS as u32 - 8);
assert_eq!(Bigfloat::from_u64(0xF000000000).leading_zeros(), 24);
}
diff --git a/lexical-parse-float/tests/stackvec_tests.rs b/lexical-parse-float/tests/stackvec_tests.rs
index 40fff90..2460a78 100644
--- a/lexical-parse-float/tests/stackvec_tests.rs
+++ b/lexical-parse-float/tests/stackvec_tests.rs
@@ -2,7 +2,7 @@ mod stackvec;
use core::cmp;
-use lexical_parse_float::bigint::{self, Limb, StackVec, LIMB_BITS};
+use lexical_parse_float::bigint::{self, Limb, StackVec};
use stackvec::vec_from_u32;
const SIZE: usize = 50;
@@ -34,7 +34,7 @@ fn simple_test() {
assert_eq!(x.len(), 2);
assert_eq!(x.is_empty(), false);
assert_eq!(x.hi16(), (0x8000, true));
- if LIMB_BITS == 32 {
+ if Limb::BITS == 32 {
assert_eq!(x.hi32(), (0x80000002, true));
assert_eq!(x.hi64(), (0x8000000280000000, false));
} else {
@@ -128,7 +128,7 @@ fn math_test() {
x.mul_small(3);
assert_eq!(&*x, &[0, 6, 27]);
x.mul_small(Limb::MAX);
- let expected: VecType = if LIMB_BITS == 32 {
+ let expected: VecType = if Limb::BITS == 32 {
vec_from_u32(&[0, 4294967290, 4294967274, 26])
} else {
vec_from_u32(&[0, 0, 4294967290, 4294967295, 4294967274, 4294967295, 26])
@@ -419,7 +419,7 @@ fn shl_bits_test() {
fn shl_limbs_test() {
let mut x = VecType::from_u32(0xD2210408);
bigint::shl_limbs(&mut x, 2);
- let expected: VecType = if LIMB_BITS == 32 {
+ let expected: VecType = if Limb::BITS == 32 {
vec_from_u32(&[0, 0, 0xD2210408])
} else {
vec_from_u32(&[0, 0, 0, 0, 0xD2210408])
Thanks for this excellent contribution. |
I am just fixing the tests locally. When trying to install the cargo stuff from the development guide the
|
The following tests fail on my machine, even on the master branch:
Should I open an issue? |
That's fine, it seems As long as |
That's already an open issue, I'm fixing those currently. I've been super swamped with the holidays and a large number of complications at work so I'm behind schedule. I'll have a quick fix and a high-performant fix soon enough. |
dab0e28
to
5430dba
Compare
The tests should be fine now. |
I'll fix the lint, don't worry about that. |
Thanks. |
Wait I fixed the |
5430dba
to
cc76e85
Compare
Wait the settings json is not quite correct. |
Let me know when all changes have been made and it should be good to merge. Once again thank you for this excellent contribution. |
Update the vscode settings so that rust analyzer and `cargo +nightly fmt -- --check` agree. Minor spelling.
cc76e85
to
1986bc4
Compare
OK now the settings are correct. There was an explicit warning not to use This pr should be done now. |
Yay! It's merged. 🚀 I rewrote some of the Python scripts that generate the lookup tables in rust and hooked them into the Would you be interested in these changes too? |
Absolutely. If the changes make the table generation easier to maintain and produce the same output, contributions are greatly appreciated :D. |
This better documents the development requirements and also the algorithm assessment logic. Related to #180.
This better documents the development requirements and also the algorithm assessment logic. Related to #180.
While reading through the source code I found some minor spelling mistakes.
Also I noticed the deprecation notice for
BITS
on theInteger
trait inlexical-util
.So I added it to
bigint
aswell.Also the
LIMB_BITS
is no longer duplicated under acfg
.mem::size_of
is const since1.25
so it should be fine?I just noticed that the readme says: rustc
1.63+
is supported.If you want I can just apply the deprecation notices for
::BITS
.I have provided two commits.
The first one just adds the deprecation notice and the second one does the deprecation.
Off topic question:
Do you happen to know any way to tell whether a string to float conversion was exact or not?
Converting to a string to float and back to a string again to check for equality seems like a bad idea.