Skip to content

Commit 24f0a1c

Browse files
authored
Merge pull request #35 from stencillogic/33-subtraction-gives-wrong-result
33 subtraction gives wrong result
2 parents 891843d + e1bd277 commit 24f0a1c

File tree

5 files changed

+19
-28
lines changed

5 files changed

+19
-28
lines changed

.github/workflows/2-tests.yml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,3 @@ jobs:
2020
run: cargo test --workspace --release --verbose
2121
- name: Run no_std tests
2222
run: cargo test --workspace --release --verbose --no-default-features --features random,serde
23-
24-
build-and-test-x32:
25-
26-
runs-on: ubuntu-latest
27-
28-
env:
29-
DEP_GMP_LIMB_BITS: 32
30-
31-
steps:
32-
- uses: actions/checkout@v3
33-
- name: Install dependencies
34-
run: sudo dpkg --add-architecture i386 && sudo apt-get update && sudo apt-get install -y gcc-multilib g++-multilib
35-
- name: Add 32 bit toolchain
36-
run: rustup toolchain install stable-i686-unknown-linux-gnu && rustup default stable-i686-unknown-linux-gnu
37-
- name: Run tests
38-
run: cargo test --workspace --release --verbose
39-
- name: Run no_std tests
40-
run: cargo test --workspace --release --verbose --no-default-features --features random,serde

astro-float-macro/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,8 @@ fn traverse_expr(expr: &Expr, err: &mut Vec<usize>, cc: &mut Consts) -> Result<T
450450

451451
// Docs for the macro are in the astro-float crate.
452452

453-
///
454453
#[proc_macro]
454+
#[allow(missing_docs)]
455455
pub fn expr(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
456456
let pmi = syn::parse_macro_input!(input as MacroInput);
457457

astro-float-num/src/conv.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,12 @@ mod tests {
767767
fn test_conv_num() {
768768
let mut cc = Consts::new().unwrap();
769769

770+
/* let z = BigFloatNumber::from_f64(1024, -2.0).unwrap();
771+
let d = BigFloatNumber::from_f64(1024, 1.0e-64).unwrap();
772+
let r = z.sub(&d, 1024, RoundingMode::None).unwrap();
773+
print!("{:?}", r.conv_to_dec(RoundingMode::Down, &mut cc).unwrap());
774+
return; */
775+
770776
// basic tests
771777
let n = BigFloatNumber::from_f64(64, 0.031256789f64).unwrap();
772778

astro-float-num/src/mantissa/conv.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl Mantissa {
1919
/// Convert `self` to an array of decimal digits with divide and conquer algorithm.
2020
/// `l` is the number of decimal digits in the input ceiled to a power of 10.
2121
/// `p` is the current depth of `tenpowers` for the given `input`.
22-
/// `most_significant` true if `self` contains the most significant part.
22+
/// `most_significant` true if `self` contains the most significant part (ignores leading zeroes if ture).
2323
pub(crate) fn conv_to_dec(
2424
&mut self,
2525
l: usize,
@@ -71,16 +71,20 @@ impl Mantissa {
7171
let mut q = Mantissa::from_word_buf(q);
7272
let mut r = Mantissa::from_word_buf(r);
7373

74+
let l2 = l / 2;
75+
7476
if q.is_zero() {
75-
let part1 = Self::conv_to_dec(&mut r, l / 2, tenpowers, p - 1, most_significant)?;
77+
let part1 = Self::conv_to_dec(&mut r, l2, tenpowers, p - 1, most_significant)?;
7678

7779
Ok(part1)
7880
} else {
79-
let mut part1 = Self::conv_to_dec(&mut r, l / 2, tenpowers, p - 1, false)?;
80-
let mut part2 =
81-
Self::conv_to_dec(&mut q, l / 2, tenpowers, p - 1, most_significant)?;
81+
let mut part1 = Self::conv_to_dec(&mut r, l2, tenpowers, p - 1, false)?;
82+
let mut part2 = Self::conv_to_dec(&mut q, l2, tenpowers, p - 1, most_significant)?;
8283

83-
part2.try_reserve_exact(part1.len())?;
84+
part2.try_reserve_exact(l2)?;
85+
if part1.len() < l2 {
86+
part2.resize(part2.len() + l2 - part1.len(), 0);
87+
}
8488
part2.append(&mut part1);
8589

8690
Ok(part2)
@@ -134,7 +138,7 @@ impl Mantissa {
134138
debug_assert!(input[0] != 0);
135139

136140
let mut chunks = Vec::new();
137-
chunks.try_reserve_exact((input.len() + WORD_TENPOWER_LEN - 1) / WORD_TENPOWER_LEN)?;
141+
chunks.try_reserve_exact(input.len().div_ceil(WORD_TENPOWER_LEN))?;
138142

139143
let mut word: Word = 0;
140144
let mut i = 0;
@@ -321,7 +325,7 @@ mod tests {
321325
assert_eq!(ret, expected);
322326
};
323327

324-
/* let tst = [0x9999999999999999, 0x9999999999999999, 0x9999999999999999];
328+
/* let tst = [0, 15336237721486753792, 13000820969757097588, 12856862479722330362, 1520271299530698982, 744111004532756610, 13398299208874459061, 17516404478540231373, 3742450158296248731, 2601219928155938017, 8664737567992370843, 17634481686646146565, 12526671041338573227, 4683828805702906964, 8213244418837960360, 17723613685701911250, 13242562882371522762, 6031074778335529103];
325329
let mut input = WordBuf::new(tst.len()).unwrap();
326330
input.copy_from_slice(&tst);
327331
test_input(input);

astro-float-num/src/ops/series.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,6 @@ fn compute_cube<T: PolycoeffGen>(
425425
) -> Result<BigFloatNumber, Error> {
426426
if n > 1 {
427427
let mut acc = BigFloatNumber::new(p)?;
428-
let cache_dim_sz = cache_dim_sz;
429428
// no need to multityply the returned coefficient of the first cube by 1.
430429
let poly_val = compute_cube(p, n - 1, cache, cache_dim_sz, polycoeff_gen)?;
431430
acc = acc.add(&poly_val, p, RoundingMode::None)?;

0 commit comments

Comments
 (0)