Skip to content

buffers in float_to_decimal_common seem to be a bit excessive #41234

Closed
@bzbarsky

Description

@bzbarsky

float_to_decimal_common in src/libcore/fmt/float.rs does this:

let mut buf = [0; 1024];
let mut parts = [flt2dec::Part::Zero(0); 16];

and then passes buf and parts to flt2dec::to_exact_fixed_str or flt2dec::to_shortest_str

Looking at the docs for those functions at https://ticki.github.io/redocs/std/num/flt2dec/fn.to_exact_fixed_str.html and https://ticki.github.io/redocs/std/num/flt2dec/fn.to_shortest_str.html the "parts" array needs to have length at least 5, right? And the "buf" array needs to be at least 800+ for the to_exact_fixed_str case but only 17 (MAX_SIG_DIGITS) for the to_shortest_str case, afaict. Changing the to_shortest_str case to not use the huge buffer would probably help out https://users.rust-lang.org/t/excessive-stack-usage-for-formatting/8023 too.

Also, it's not clear to me that the "buf" scratch buffer needs to be zero-initialized. Does it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions