Re: Negating a short?

2024-11-06 Thread Matheus via Digitalmars-d-learn
On Wednesday, 6 November 2024 at 00:00:48 UTC, Dennis wrote: On Tuesday, 5 November 2024 at 20:29:08 UTC, Andy Valencia ... You can also use an assignment operator, which allows overflow without explicit cast: ```D s *= -1; ``` ... Hi Dennis, Shouldn't these two act the same? void main(){

Re: Negating a short?

2024-11-06 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 6 November 2024 at 16:38:40 UTC, Salih Dincer wrote: In response to Andy and Matheus, I think implementing your own type might be a solution: Oh, am I too hasty? There was already an s in the test environment, so I thought 2 overloads were unnecessary. I don't have a programmer

Re: Negating a short?

2024-11-06 Thread Salih Dincer via Digitalmars-d-learn
On Tuesday, 5 November 2024 at 17:32:00 UTC, Andy Valencia wrote: integral promotion not done for -val ```d I ended up with this, but is negating a short really this problematic, or did I miss something? static if (!__traits(isUnsigned, T)) { if (val < 0) { static if

Re: Negating a short?

2024-11-06 Thread Dennis via Digitalmars-d-learn
On Wednesday, 6 November 2024 at 11:51:41 UTC, Matheus wrote: Shouldn't these two act the same? That would make sense, but you wouldn't make a special case just for that specific expression, and it's hard to find a good rule that generalizes to all expressions.

Re: Negating a short?

2024-11-06 Thread Matheus via Digitalmars-d-learn
On Wednesday, 6 November 2024 at 16:48:54 UTC, Salih Dincer wrote: On Wednesday, 6 November 2024 at 16:38:40 UTC, Salih Dincer wrote: In response to Andy and Matheus, I think implementing your own type might be a solution: ... Thanks for the info and the code. Matheus.

Re: Negating a short?

2024-11-06 Thread Matheus via Digitalmars-d-learn
On Wednesday, 6 November 2024 at 16:27:22 UTC, Dennis wrote: On Wednesday, 6 November 2024 at 11:51:41 UTC, Matheus wrote: Shouldn't these two act the same? That would make sense, but you wouldn't make a special case just for that specific expression, and it's hard to find a good rule that g

Re: Negating a short?

2024-11-06 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 6 November 2024 at 16:25:40 UTC, Salih Dincer wrote: In response to Andy and Matheus, I think implementing your own type might be a solution: Even in my own type, single overload was enough. So I have to correct my mistake: ```d void main() { Short foo = { -21 }; s *= -1;