Re: New integer promotion rules

2021-01-01 Thread Paul via Digitalmars-d-learn
On Thursday, 18 January 2018 at 16:31:02 UTC, ag0aep6g wrote: I'm interpreting that to mean that it will become an error for some time, but later it will be allowed again with the new behavior. And then you can throw away `-transition=intpromote`. Seeing as it's almost 3 years later, I'd like

Re: New integer promotion rules

2018-01-18 Thread rumbu via Digitalmars-d-learn
On Thursday, 18 January 2018 at 18:00:51 UTC, rumbu wrote: On Thursday, 18 January 2018 at 17:54:59 UTC, rumbu wrote: On Thursday, 18 January 2018 at 12:51:48 UTC, Dominikus Dittes target = isNegative ? cast(Unsigned!T)(-c) : cast(Unsigned!T)c; That would have been better even before the

Re: New integer promotion rules

2018-01-18 Thread rumbu via Digitalmars-d-learn
On Thursday, 18 January 2018 at 17:54:59 UTC, rumbu wrote: On Thursday, 18 January 2018 at 12:51:48 UTC, Dominikus Dittes target = isNegative ? cast(Unsigned!T)(-c) : cast(Unsigned!T)c; That would have been better even before the change, because the operator '-' used on unsigned types is

Re: New integer promotion rules

2018-01-18 Thread rumbu via Digitalmars-d-learn
On Thursday, 18 January 2018 at 12:51:48 UTC, Dominikus Dittes Scherkl wrote: On Thursday, 18 January 2018 at 06:05:08 UTC, rumbu wrote: On Thursday, 18 January 2018 at 02:30:17 UTC, Rubn wrote: On Wednesday, 17 January 2018 at 22:30:11 UTC, rumbu wrote: code like "m = n < 0 ? -n : n" doesn't

Re: New integer promotion rules

2018-01-18 Thread ag0aep6g via Digitalmars-d-learn
On 01/18/2018 05:22 PM, Steven Schveighoffer wrote: Sure, but what does the statement "Once deprecated this will become an error" mean? Will I have to use the -transition=intpromote switch forever to avoid an error? As you quoted before: "Once deprecated this will become an error, and then

Re: New integer promotion rules

2018-01-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/18/18 11:14 AM, ag0aep6g wrote: On 01/18/2018 03:30 PM, Steven Schveighoffer wrote: Is there going to be a point where casts aren't needed? Otherwise, this is pretty ugly. You don't need casts when you use `-transition=intpromote`. Sure, but what does the statement "Once deprecated

Re: New integer promotion rules

2018-01-18 Thread ag0aep6g via Digitalmars-d-learn
On 01/18/2018 03:30 PM, Steven Schveighoffer wrote: Is there going to be a point where casts aren't needed? Otherwise, this is pretty ugly. You don't need casts when you use `-transition=intpromote`.

Re: New integer promotion rules

2018-01-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/17/18 2:40 PM, rumbu wrote: This started in the last DMD version (2.078): byte b = -10; ulong u = b < 0 ? -b : b; //Deprecation: integral promotion not done for `-b`, use '-transition=intpromote' switch or `-cast(int)(b) Why do I need a to promote a byte to int to obtain an ulong? Even

Re: New integer promotion rules

2018-01-18 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Thursday, 18 January 2018 at 06:05:08 UTC, rumbu wrote: On Thursday, 18 January 2018 at 02:30:17 UTC, Rubn wrote: On Wednesday, 17 January 2018 at 22:30:11 UTC, rumbu wrote: code like "m = n < 0 ? -n : n" doesn't worth a wrapper That code is worth a wrapper, it's called "abs"... m =

Re: New integer promotion rules

2018-01-17 Thread rumbu via Digitalmars-d-learn
On Thursday, 18 January 2018 at 02:30:17 UTC, Rubn wrote: On Wednesday, 17 January 2018 at 22:30:11 UTC, rumbu wrote: code like "m = n < 0 ? -n : n" doesn't worth a wrapper That code is worth a wrapper, it's called "abs"... m = abs(n); Well, since I'm in the learn forum and you seem to

Re: New integer promotion rules

2018-01-17 Thread Rubn via Digitalmars-d-learn
On Wednesday, 17 January 2018 at 22:30:11 UTC, rumbu wrote: code like "m = n < 0 ? -n : n" doesn't worth a wrapper That code is worth a wrapper, it's called "abs"... m = abs(n);

Re: New integer promotion rules

2018-01-17 Thread ag0aep6g via Digitalmars-d-learn
On 01/17/2018 11:30 PM, rumbu wrote: 1. Why do I need explicitely to promote my byte to int in order to assign it to an ulong? 2.077: ulong u = -b; 2.088: ulong u = -cast(int)b; Those two snippets are not equivalent. When b = byte.min, the 2.077 snippet gives u = 18446744073709551488, while

Re: New integer promotion rules

2018-01-17 Thread Ali Çehreli via Digitalmars-d-learn
On 01/17/2018 02:30 PM, rumbu wrote: > 1. Why do I need explicitely to promote my byte to int in order to > assign it to an ulong? > 2.077: ulong u = -b; 2.088: ulong u = -cast(int)b; You're not assigning your byte to ulong; you're assigning the expression -b to ulong. -b is discovered to have

Re: New integer promotion rules

2018-01-17 Thread rumbu via Digitalmars-d-learn
On Wednesday, 17 January 2018 at 21:12:07 UTC, Rubn wrote: On Wednesday, 17 January 2018 at 20:30:07 UTC, rumbu wrote: And here is why is bothering me: auto max = isNegative ? cast(Unsigned!T)(-T.min) : cast(Unsigned!T)T.max); The generic code above (which worked for all signed integral

Re: New integer promotion rules

2018-01-17 Thread Rubn via Digitalmars-d-learn
On Wednesday, 17 January 2018 at 20:30:07 UTC, rumbu wrote: And here is why is bothering me: auto max = isNegative ? cast(Unsigned!T)(-T.min) : cast(Unsigned!T)T.max); The generic code above (which worked for all signed integral types T in 2.077) must be rewritten like this in 2.078:

Re: New integer promotion rules

2018-01-17 Thread ag0aep6g via Digitalmars-d-learn
On 01/17/2018 09:30 PM, rumbu wrote: And here is why is bothering me: auto max = isNegative ? cast(Unsigned!T)(-T.min) : cast(Unsigned!T)T.max); The generic code above (which worked for all signed integral types T in 2.077) must be rewritten like this in 2.078: static if (T.sizeof >= 4)   

Re: New integer promotion rules

2018-01-17 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 17 January 2018 at 20:30:07 UTC, rumbu wrote: And here is why is bothering me: auto max = isNegative ? cast(Unsigned!T)(-T.min) : cast(Unsigned!T)T.max); The generic code above (which worked for all signed integral types T in 2.077) must be rewritten like this in 2.078:

Re: New integer promotion rules

2018-01-17 Thread rumbu via Digitalmars-d-learn
And here is why is bothering me: auto max = isNegative ? cast(Unsigned!T)(-T.min) : cast(Unsigned!T)T.max); The generic code above (which worked for all signed integral types T in 2.077) must be rewritten like this in 2.078: static if (T.sizeof >= 4) auto max = isNegative ?

Re: New integer promotion rules

2018-01-17 Thread rumbu via Digitalmars-d-learn
On Wednesday, 17 January 2018 at 19:54:50 UTC, ag0aep6g wrote: On 01/17/2018 08:40 PM, rumbu wrote: This started in the last DMD version (2.078): byte b = -10; ulong u = b < 0 ? -b : b; //Deprecation: integral promotion not done for `-b`, use '-transition=intpromote' switch or `-cast(int)(b)

Re: New integer promotion rules

2018-01-17 Thread ag0aep6g via Digitalmars-d-learn
On 01/17/2018 08:40 PM, rumbu wrote: This started in the last DMD version (2.078): byte b = -10; ulong u = b < 0 ? -b : b; //Deprecation: integral promotion not done for `-b`, use '-transition=intpromote' switch or `-cast(int)(b) Why do I need a to promote a byte to int to obtain an ulong?