Skip to content
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

Subtraction gives wrong result #33

Open
dzamkov opened this issue Aug 30, 2024 · 1 comment
Open

Subtraction gives wrong result #33

dzamkov opened this issue Aug 30, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@dzamkov
Copy link

dzamkov commented Aug 30, 2024

I'm using astro_float to validate function approximations in my code. I noticed that one of my tests fails with a massive discrepancy in computed results. Here's a minimal example which reproduces the issue:

use astro_float::ctx::Context;
use astro_float::{expr, Consts, RoundingMode};

fn main() {
    let mut ctx = Context::new(
        1024,
        RoundingMode::Down,
        Consts::new().expect("constants cache initialized"),
        -10000,
        10000,
    );
    let z = &astro_float::BigFloat::from(-2.0);
    let d = &astro_float::BigFloat::from(1.0e-64);
    println!("{}", expr!(z - d, ctx));
}

Output:

-2.00000000000000000000000000000000999999999999999965305738833546928712902976607280783480372213247877639491996226104668964320054101346916438695416432929769423252076208907803604252402073697828855693148231154054883518256247043609619140625e-32

Note the exponent: e-32. The exponent should be e+0. Interestingly, this gives the correct result when using a precision of 64, 128, 256 and 512, but it fails with 1024.

@stencillogic stencillogic added the bug Something isn't working label Aug 30, 2024
@stencillogic
Copy link
Owner

Seems like a bug in decimal representation of the result. Thanks for reporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants