digitalmars.D.learn - Integer literals
- ric maicle (29/29) Jan 04 2016 I was rereading the Integer Literals section and trying out some code
- Adam D. Ruppe (3/7) Jan 04 2016 The x .. y syntax excludes y. So 0..3 covers 0, 1, 2. It excludes
- ric maicle (10/16) Jan 04 2016 I copied part of the table here:
- Steven Schveighoffer (5/22) Jan 04 2016 Yes, that is a typo.
I was rereading the Integer Literals section and trying out some code when I came across a couple of error messages on integer overflows. I have reproduced the code below for reference. void main() { // The maximum long value is ...807 // The following line produces an error message: // Error: signed integer overflow auto a = 9_223_372_036_854_775_808; // The maximum ulong value is ...615 // The following line produces an error message: // Error: integer overflow auto g = 18_446_744_073_709_551_616U; } I just wanted to point out that the second error message might be consistent if it says 'Error: unsigned integer overflow' in comparison to the first error message. Also, I noticed under the Integer Literal section of the D reference document (http://dlang.org/spec/lex.html) that the range of uint 0U .. 4_294_967_296U in the table Decimal Literal Types has a typo. Shouldn't the range end with 4_294_967_295U? Here's a snippet: import std.stdio; void main() { writeln(typeof(4_294_967_295U).stringof); writeln(typeof(4_294_967_296U).stringof); }
Jan 04 2016
On Monday, 4 January 2016 at 14:54:29 UTC, ric maicle wrote:0U .. 4_294_967_296U in the table Decimal Literal Types has a typo. Shouldn't the range end with 4_294_967_295U?The x .. y syntax excludes y. So 0..3 covers 0, 1, 2. It excludes 3.
Jan 04 2016
On Monday, 04 January, 2016 10:58 PM, Adam D. Ruppe wrote:On Monday, 4 January 2016 at 14:54:29 UTC, ric maicle wrote:I copied part of the table here: 0 .. 2_147_483_647 2_147_483_648 .. 9_223_372_036_854_775_807 0L .. 9_223_372_036_854_775_807L 0U .. 4_294_967_296U 4_294_967_296U .. 18_446_744_073_709_551_615U 0UL .. 18_446_744_073_709_551_615UL If the range is x to y-1 shouldn't the rest of the other ending ranges also be one greater than the maximum value of their types?0U .. 4_294_967_296U in the table Decimal Literal Types has a typo. Shouldn't the range end with 4_294_967_295U?The x .. y syntax excludes y. So 0..3 covers 0, 1, 2. It excludes 3.
Jan 04 2016
On 1/4/16 10:33 AM, ric maicle wrote:On Monday, 04 January, 2016 10:58 PM, Adam D. Ruppe wrote:Yes, that is a typo. https://github.com/D-Programming-Language/dlang.org/pull/1181 Thanks -SteveOn Monday, 4 January 2016 at 14:54:29 UTC, ric maicle wrote:I copied part of the table here: 0 .. 2_147_483_647 2_147_483_648 .. 9_223_372_036_854_775_807 0L .. 9_223_372_036_854_775_807L 0U .. 4_294_967_296U 4_294_967_296U .. 18_446_744_073_709_551_615U 0UL .. 18_446_744_073_709_551_615UL If the range is x to y-1 shouldn't the rest of the other ending ranges also be one greater than the maximum value of their types?0U .. 4_294_967_296U in the table Decimal Literal Types has a typo. Shouldn't the range end with 4_294_967_295U?The x .. y syntax excludes y. So 0..3 covers 0, 1, 2. It excludes 3.
Jan 04 2016