Replacement for snprintf

Rumbu rumbu at
Wed Oct 30 20:29:34 UTC 2019

On Wednesday, 30 October 2019 at 19:28:44 UTC, berni44 wrote:
> On Wednesday, 30 October 2019 at 18:16:56 UTC, Rumbu wrote:
>> That means that snprintf must use the current rounding mode 
>> that can be read using FloatingPointControl.rounding from 
>> std.math.
> Is it really a "must"? We are not completely bound by the IEEE 
> standard and, if good reasons are available, might reject it. 
> For example, comparing two floats with <= produces either 
> "false" or "true" in D. According to IEEE there should be a 
> third result possible, namly "not comparable". Having said 
> this, it would be possible to implement it the way you claim, 
> but probably at some cost (=slower, more and less easy readable 
> lines of code). I'll think about it.

I don't know the inners of your code, but I suppose that before 
"printing" you end up with an integer value and a ten-based 

In this case rounding becomes a question of how do you interpret 
the remainder of a division by a power of ten.

Because I spent a lot of time figuring out how  to format 
correctly decimal numbers, here is some piece of code I use in 
order to format decimal numbers depending on the rounding mode, 
fully compliant with the standard.

Hope this helps.

More information about the Digitalmars-d mailing list