ProtoObject and comparison for equality and ordering

H. S. Teoh hsteoh at quickfur.ath.cx
Wed May 15 05:30:56 UTC 2019


On Tue, May 14, 2019 at 09:02:49PM -0400, Andrei Alexandrescu via Digitalmars-d wrote:
[...]
> Well there would be in some instances. People often implement
> comparisons as a - b currently, where a and b are int expressions.
[...]

FYI, the result of that is actually incorrect in some cases.  (Consider
what happens when there is overflow involved, such as int.max
- int.min, and remember the type of the result.) So, not exactly the
kind of code we should recommend, let alone bend over backwards to
support.

Int comparisons should be left as built-in operators <, =, >, etc.,
which then get translated to the correct hardware instructions that
don't suffer from the overflow bug.


T

-- 
This is not a sentence.


More information about the Digitalmars-d mailing list