Re: std.algorithm.cmp doesn't seem to support numeric types?

2019-10-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 16 October 2019 at 21:34:35 UTC, Dennis wrote: Except that e.g. -2 - int.max underflows to int.max suggesting that int.max < -2. Eh yeah, it would be something you should check in opCmp. But this is how it is actually implemented on the processor itself, just the cpu happens to

Re: std.algorithm.cmp doesn't seem to support numeric types?

2019-10-16 Thread Ali Çehreli via Digitalmars-d-learn
On 10/16/2019 02:34 PM, Dennis wrote: > Except that e.g. -2 - int.max underflows to int.max suggesting that > int.max < -2. Timon had corrected me on that point a while back, so I had added the following warning at

Re: std.algorithm.cmp doesn't seem to support numeric types?

2019-10-16 Thread Dennis via Digitalmars-d-learn
On Wednesday, 16 October 2019 at 20:07:10 UTC, Adam D. Ruppe wrote: Notice that the docs say "a negative value" rather than -1 specifically. That's because the implementation for integers an be as simple as return a - b; // if b > a, you get a negative value Except that e.g. -2 - int.max

Re: std.algorithm.cmp doesn't seem to support numeric types?

2019-10-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 16 October 2019 at 19:25:18 UTC, DNoob wrote: I'm just learning D, so it's very possible that I'm missing a more appropriate function that exists elsewhere, but basically I found today that while I could easily write a cmp function that worked for everything, the one in

Re: std.algorithm.cmp doesn't seem to support numeric types?

2019-10-16 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 16 October 2019 at 19:25:18 UTC, DNoob wrote: I'm just learning D, so it's very possible that I'm missing a more appropriate function that exists elsewhere, but basically I found today that while I could easily write a cmp function that worked for everything, the one in

std.algorithm.cmp doesn't seem to support numeric types?

2019-10-16 Thread DNoob via Digitalmars-d-learn
I'm just learning D, so it's very possible that I'm missing a more appropriate function that exists elsewhere, but basically I found today that while I could easily write a cmp function that worked for everything, the one in std.algorithm doesn't seem to: import std.stdio, std.algorithm;