dtolnay / ryu

Fast floating point to string conversion
Apache License 2.0
606 stars 27 forks source link

Is there an easy and fast way to get the position of the decimal point? #7

Closed golddranks closed 5 years ago

golddranks commented 5 years ago

Is there an easy and fast way to get the position of the decimal point, or possibly set the output precision in digits? I'd like to limit the number of output digits after the decimal point, and if information about the position of the decimal point would be available directly from the algorithm, it would be waste of cycles to scan it from the output buffer.

dtolnay commented 5 years ago

If you are concerned about cycles I would recommend building your own formatter around d2d which is the base2-to-base10 conversion in Ryū. It converts for example 1.0e-10f64 into mantissa=1u64 exponent=-10i32. Check out the two existing formatters, the default Ryū one here and the one we call pretty here.