base 1 bug in std.string.toString?
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Mon Aug 21 10:29:37 PDT 2006
nobody wrote:
> int main(char[][] args)
> {
> dout.writeLine(toString(1uL,1u));
> assert( toString(12uL,1u).length == 12 );
> }
>
> This produces:
>
> 1000000000000000000000000000000000000000000000000000000000000000000000
> Error: Assert Failure example(4)
>
> When I think it should produce
>
> 1
From the docs: (http://www.digitalmars.com/d/phobos/std_string.html)
------
char[] toString(long value, uint radix);
char[] toString(ulong value, uint radix);
Convert value to string in radix radix.
radix must be a value from 2 to 36. [...]
------
So you're just calling it with an invalid parameter value.
Hint: 1 wouldn't be a valid digit in base 1, just like 2 isn't one in
base 2, A isn't one in base 10, etc.
So the only valid digit would be 0, and since extra leading zeroes are
ignored, the only value that can possibly be represented in base 1 is 0
itself.
More information about the Digitalmars-d-bugs
mailing list