ParkMyCar / compact_str

A memory efficient string type that can store up to 24* bytes on the stack
MIT License
557 stars 41 forks source link

f64::to_compact_string differs from to_string #351

Closed turalcar closed 1 month ago

turalcar commented 6 months ago

&1f64.to_string() == "1" &1f64.to_compact_string() == "1.0" I don't have a strong preference either way but this makes post-migration regression testing quite a pain.

dragazo commented 4 months ago

Yeah, the difference is a bit of a pain point, though you can always do 1f64.to_string().into(). I prefer the way this crate does it (with ryu) since the result is always at most 24 bytes and so can always be inlined. But for this reason, in my projects I have a dedicated function that bypasses to_compact_string and directly uses ryu but strips the .0 suffix if it exists.

ParkMyCar commented 1 month ago

Thanks for the bug report! @dragazo is right, this is because we use ryu (see https://github.com/dtolnay/ryu/issues/48) which last I knew offered performance improvements over the implementation in the stdlib.

If having the same behavior as the stdlib is preferred I'm more than happy to switch implementations