Skip to content

Trailing zero inconsistently added to result #709

@janekfleper

Description

@janekfleper

Depending on the precision of the resulting decimal there is sometimes a trailing zero added. This happens every 9 decimal digits. 👀
A minimal example to reproduce the issue is:

let ten = Decimal::new(10, 0);

println!("\nDecimal numbers from 1 to 1e-28:");
for n in 0..=28 {
    println!("n = {:2}, 10^-n = {}", n, ten.powi(-n as i64));
}

The output of the example code is:

Decimal numbers from 1 to 1e-28:
n =  0, 10^-n = 1
n =  1, 10^-n = 0.10
n =  2, 10^-n = 0.01
n =  3, 10^-n = 0.001
n =  4, 10^-n = 0.0001
n =  5, 10^-n = 0.00001
n =  6, 10^-n = 0.000001
n =  7, 10^-n = 0.0000001
n =  8, 10^-n = 0.00000001
n =  9, 10^-n = 0.000000001
n = 10, 10^-n = 0.00000000010
n = 11, 10^-n = 0.00000000001
n = 12, 10^-n = 0.000000000001
n = 13, 10^-n = 0.0000000000001
n = 14, 10^-n = 0.00000000000001
n = 15, 10^-n = 0.000000000000001
n = 16, 10^-n = 0.0000000000000001
n = 17, 10^-n = 0.00000000000000001
n = 18, 10^-n = 0.000000000000000001
n = 19, 10^-n = 0.00000000000000000010
n = 20, 10^-n = 0.00000000000000000001
n = 21, 10^-n = 0.000000000000000000001
n = 22, 10^-n = 0.0000000000000000000001
n = 23, 10^-n = 0.00000000000000000000001
n = 24, 10^-n = 0.000000000000000000000001
n = 25, 10^-n = 0.0000000000000000000000001
n = 26, 10^-n = 0.00000000000000000000000001
n = 27, 10^-n = 0.000000000000000000000000001
n = 28, 10^-n = 0.0000000000000000000000000001

I initially encountered this issue when using the decimal type in Typst, see typst/typst#6065 for a few more examples.
The Typst compiler uses the latest version 1.36.0, see cargo.toml.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions