On Tuesday, October 06, 2015 15:16:12 tcak via Digitalmars-d-learn wrote:
> While writing max ulong value, I added the "u" postfix. So
> compiler accepted it as ulong value (That's my interpretation if
> correct on compiler's side).
>
> writeln( 18_446_744_073_709_551_615u );
>
> But when I try to print out minimum value of long, compiler says
> Error: signed integer overflow
>
> writeln( -9_223_372_036_854_775_808 );
>
> In case that is the wrong value, I checked it with writeln(
> long.min ); already.
>
> Do I need to put a postfix for that number? I checked
> documentation by searching "dlang integer" etc, but couldn't have
> found any information/anything about postfix at all.

L is the prefix to use, but it looks like there's a compiler bug here,
because

long l = -9_223_372_036_854_775_807L;

compiles

and

long l = -9_223_372_036_854_775_808L;

doesn't, even though that's the same as long.min.

long l = -9_223_372_036_854_775_807UL;

compiles and does the right thing, though that's a pretty silly thing to
have to do.

Actually, digging through bugzilla, it looks like it's already been
reported:

https://issues.dlang.org/show_bug.cgi?id=8929

Though since C has the same problem, it's treated as an enhancement rather
than a bug (which seems wrong to me). Apparently, the problem stems from the
compiler processing the literal and _then_ applying the sign, and long.max
is 9_223_372_036_854_775_807L. Apparently, -2L^^63 will work though.

All in all, it's probably not a big deal, since you should probably just
being using long.min anyway, but this doesn't seem like particularly good
behavior to me.

- Jonathan M Davis

Reply via email to