digitalmars.D.learn - What is the postfix for min long value?
- tcak (12/12) Oct 06 2015 While writing max ulong value, I added the "u" postfix. So
- =?UTF-8?Q?Ali_=c3=87ehreli?= (14/21) Oct 06 2015 I would expect the following to work:
- anonymous (2/11) Oct 06 2015 https://issues.dlang.org/show_bug.cgi?id=8929
- Jonathan M Davis via Digitalmars-d-learn (22/34) Oct 06 2015 L is the prefix to use, but it looks like there's a compiler bug here,
- Zaydek (5/5) May 30 2017 Jonathan,
- Zaydek (2/14) May 30 2017 See above ^^ :D
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.
Oct 06 2015
On 10/06/2015 08:16 AM, tcak wrote:While writing max ulong value, I added the "u" postfix.Better to use U to be consistent with L (see below).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 );I would expect the following to work: writeln( -9_223_372_036_854_775_808L); But it doesn't compile: Error: signed integer overflow It looks like a compiler bug to me. If so, a very embarrassing one. :) (You can use UL and LU as well.)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.They go by "suffix". The officital documentation: http://dlang.org/lex.html#integerliteral My short mention of them start at the section "The L suffix": http://ddili.org/ders/d.en/literals.html#ix_literals.literal (They were missing in my index section. Adding now...) Ali
Oct 06 2015
On Tuesday 06 October 2015 17:39, Ali Çehreli wrote:I would expect the following to work: writeln( -9_223_372_036_854_775_808L); But it doesn't compile: Error: signed integer overflow It looks like a compiler bug to me. If so, a very embarrassing one. :)https://issues.dlang.org/show_bug.cgi?id=8929
Oct 06 2015
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
Oct 06 2015
Jonathan, I saw this answered in another post: http://forum.dlang.org/post/gtaublmskqrhnbhoesex forum.dlang.org I.e., you can do long(-9223372036854775808UL) :) Or long l = -9223372036854775808UL;
May 30 2017
On Tuesday, 6 October 2015 at 15:16:13 UTC, tcak 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.See above ^^ :D
May 30 2017