Replacement for snprintf
Rumbu
rumbu at rumbu.ro
Wed Oct 30 18:16:56 UTC 2019
On Wednesday, 30 October 2019 at 13:44:52 UTC, berni44 wrote:
> In PR 7222 [1] Robert Schadek suggested replacing the call to
> snprinf in std.format with an own method written in D. During
> the last days I took a deeper look into this and meanwhile I've
> got a function that works for floats (and probably also
> doubles, but I havn't tested that yet and it should also work
> with reals if ucent would be available; without ucent I need a
> workaround for real or fall back to BigInt).
>
> [...]
According to ieee754-2008:
"5.12.2 External decimal character sequences representing finite
numbers
[...]
For binary formats, all conversions of H significant digits or
fewer round correctly according to the applicable rounding
direction;"
Where H is 9 for single, 17 for double. IEE754 doesn't specify a
H for reals.
That means that snprintf must use the current rounding mode that
can be read using FloatingPointControl.rounding from std.math.
More information about the Digitalmars-d
mailing list