Re: Wrong result with enum

2021-11-11 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 11 November 2021 at 14:52:45 UTC, Stanislav Blinov wrote: On Thursday, 11 November 2021 at 09:11:37 UTC, Salih Dincer wrote: Unless explicitly set, default type is int. 110 is greater than int.max. 11 ```d enum w = 100_000; size_t b = w * w; // size_t b =

Re: Wrong result with enum

2021-11-11 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 11 November 2021 at 09:11:37 UTC, Salih Dincer wrote: Unless explicitly set, default type is int. 110 is greater than int.max. 11 ```d enum w = 100_000; size_t b = w * w; // size_t b = 10 * 10; // ??? assert(b == 10_000_000_000); // Assert Failure ```

Re: Wrong result with enum

2021-11-11 Thread Patrick Schluter via Digitalmars-d-learn
On Thursday, 11 November 2021 at 05:37:05 UTC, Salih Dincer wrote: is this a issue, do you need to case? ```d enum tLimit = 10_000; // (1) true result enum wLimit = 100_000; // (2) wrong result void main() { size_t subTest1 = tLimit; assert(subTest1 == tLimit);/* no error */

Re: Wrong result with enum

2021-11-11 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 11 November 2021 at 05:37:05 UTC, Salih Dincer wrote: is this a issue, do you need to case? ```d enum tLimit = 10_000; // (1) true result enum wLimit = 100_000; // (2) wrong result That's an `int` literal. Try enum wLimit = 100_000L; the L suffix makes a `long` literal.

Re: Wrong result with enum

2021-11-11 Thread Patrick Schluter via Digitalmars-d-learn
On Thursday, 11 November 2021 at 12:05:19 UTC, Tejas wrote: On Thursday, 11 November 2021 at 09:11:37 UTC, Salih Dincer wrote: On Thursday, 11 November 2021 at 06:34:16 UTC, Stanislav Blinov wrote: On Thursday, 11 November 2021 at 05:37:05 UTC, Salih Dincer wrote: is this a issue, do you need

Re: Wrong result with enum

2021-11-11 Thread Tejas via Digitalmars-d-learn
On Thursday, 11 November 2021 at 09:11:37 UTC, Salih Dincer wrote: On Thursday, 11 November 2021 at 06:34:16 UTC, Stanislav Blinov wrote: On Thursday, 11 November 2021 at 05:37:05 UTC, Salih Dincer wrote: is this a issue, do you need to case? ```d enum tLimit = 10_000; // (1) true result

Re: Wrong result with enum

2021-11-11 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 11 November 2021 at 06:34:16 UTC, Stanislav Blinov wrote: On Thursday, 11 November 2021 at 05:37:05 UTC, Salih Dincer wrote: is this a issue, do you need to case? ```d enum tLimit = 10_000; // (1) true result enum wLimit = 100_000; // (2) wrong result ```

Re: Wrong result with enum

2021-11-10 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 11 November 2021 at 05:37:05 UTC, Salih Dincer wrote: is this a issue, do you need to case? ```d enum tLimit = 10_000; // (1) true result enum wLimit = 100_000; // (2) wrong result ``` https://dlang.org/spec/enum.html#named_enums Unless explicitly set, default type is int.

Re: Wrong result with enum

2021-11-10 Thread zjh via Digitalmars-d-learn
On Thursday, 11 November 2021 at 05:37:05 UTC, Salih Dincer wrote: is this a issue, do you need to case? out of bound.

Wrong result with enum

2021-11-10 Thread Salih Dincer via Digitalmars-d-learn
is this a issue, do you need to case? ```d enum tLimit = 10_000; // (1) true result enum wLimit = 100_000; // (2) wrong result void main() { size_t subTest1 = tLimit; assert(subTest1 == tLimit);/* no error */ size_t subTest2 = wLimit; assert(subTest2 == wLimit);/* no