abs and minimum values
johan_forsberg_86 at hotmail.com
Fri Oct 29 08:33:07 UTC 2021
On Thursday, 28 October 2021 at 21:23:15 UTC, kyle wrote:
> void main()
> import std.math : abs, sgn;
> alias n_type = short; //or int, long, byte, whatever
> assert(n_type.min == abs(n_type.min));
> assert(sgn(abs(n_type.min)) == -1);
> I stumbled into this fun today. I understand why abs yields a
> negative value here with overflow and no promotion. I just want
> to know if it should. Should abs ever return a negative number?
Depends on how you view it. Imo abs should never be able to
return a negative value since it should be the distance/length
from 0 and alternaticely root of x^2 .
More information about the Digitalmars-d-learn