| Thread overview | |||||
|---|---|---|---|---|---|
|
August 21, 2006 base 1 bug in std.string.toString? | ||||
|---|---|---|---|---|
| ||||
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
| ||||
August 21, 2006 Re: base 1 bug in std.string.toString? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to nobody | 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. | |||
August 21, 2006 Re: base 1 bug in std.string.toString? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to nobody | nobody schrieb:
> int main(char[][] args)
> {
> dout.writeLine(toString(1uL,1u));
> assert( toString(12uL,1u).length == 12 );
> }
I only want to comment that the missing return statement can also be the source of the assertion. Either
void main(){
...
}
or
int main( char[][] args ){
...
return 0;
}
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply