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

Ali Çehreli acehreli at yahoo.com
Wed Oct 16 23:50:40 UTC 2019


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

 
http://ddili.org/ders/d.en/operator_overloading.html#ix_operator_overloading.opCmp

"Warning: Using subtraction for the implementation of opCmp is a bug if 
valid values of a member can cause overflow."

However, note how I say "overflow" instead of "underflow". The reason 
is, underflow is a different concept that applies only to floating point 
values[1]. Apparently, "integer underflow" has become common usage as 
well[2].

Ali

[1] https://en.wikipedia.org/wiki/Arithmetic_underflow

[2] https://en.wikipedia.org/wiki/Integer_overflow



More information about the Digitalmars-d-learn mailing list