Formatting -0.0 as 0.0

Steven Schveighoffer schveiguy at gmail.com
Fri Oct 15 14:09:32 UTC 2021


On 10/15/21 8:37 AM, Bastiaan Veelo wrote:

> What I would like best is if there were a format specifier flag that 
> does this conversion automatically, like "%> 4.3f". Does it make sense 
> to add this? Is there a better way?

The only way I can think of that isn't really intrusive (like your 
`posZero` thing) is to define your own `writef`/`format` wrappers (what 
I'd do is check any doubles, and replace them when necessary).

Another thing to do is to catch it at the source. That is, when you 
store a value somewhere where it might be printed, if it's `-0.0`, 
change it to `0.0`.

Note that if ldc is optimizing out an addition with 0, and that actually 
changes the observable results, that technically is an invalid optimization.

-Steve


More information about the Digitalmars-d mailing list