writefln question

Nick Nick_member at pathlink.com
Sat Mar 18 01:05:17 PST 2006


In article <ops6k3babk23k2f5 at nrage.netwin.co.nz>, Regan Heath says...
>
>FYI, you can use:
>   writefln("number = %.8x", cast(ulong)9);
>
>to get the result you want. This is how I typically pad my hex numbers.

That's exactly what he does already :-)

This is a bug in format.d. Starting at line 839, it reads:
839   if (vnumber < 10)
840   {

This should really compare against base, not 10.

841     if (vnumber == 0 && precision == 0 && flags & FLprecision &&
842        !(fc == 'o' && flags & FLhash))
843     {
844       putstr(null);
845       return;
846     }

Ok.

847     if (vnumber < base)
848     {   vchar = '0' + vnumber;
849         goto L2;
850     }

The compare against base is redundant (if the above test is fixed), and wrong.
It should instead check if precision is 0.

851   }   

Nick





More information about the Digitalmars-d-learn mailing list