akubera / bigdecimal-rs

Arbitrary precision decimal crate for Rust
Other
284 stars 71 forks source link

Inconsistent use of 'e' vs 'E' in formatting numbers #131

Open gnp opened 3 months ago

gnp commented 3 months ago

Examples (the non-parenthetical representation is a string used to construct the BigDecimal):

    "large_float": 1.7976931348623157e308 (BigDecimal: 17976931348623157e+292)
    "small_float": 4.9406564584124654e-324 (BigDecimal: 4.9406564584124654E-324)

I looked through the source for the formatting and it appears "e" is the majority case but existing test cases check for "E" in a couple places.

akubera commented 3 months ago

The distinction should be here in this if statement: https://github.com/akubera/bigdecimal-rs/blob/369dfaed970d91a9d0a27ba554c9579d595ebffb/src/impl_fmt.rs#L109

(All of the formatting code should be in that impl_fmt.rs file)

The upper E is properly written in scientific notation (with decimal point after first digit) vs the lower e is for "integer" exponents (for large exponents), where no decimal point is added. This isn't documented anywhere, just my ad-hoc convention.

Is this causing issues with something?

akubera commented 3 months ago

I'll note you can force one or the other via formatting {:e} for {:E} for consistent scientific notation.