How to implement opCmp?

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 13 09:49:14 PDT 2017


On Tue, Jun 13, 2017 at 10:51:40AM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote:
[...]
> I think Andrei has a nice way to do opCmp for integers that's a simple
> subtraction and negation or something like that.
[...]

In theory, cmp(int x, int y) can be implemented simply as (x - y).
However, this fails when integer overflow occurs.  Does Andrei have a
nice way of doing this that isn't vulnerable to integer overflow?


T

-- 
You are only young once, but you can stay immature indefinitely. -- azephrahel


More information about the Digitalmars-d-learn mailing list