Problem 1: std.math.abs signature matches any type which supports the comparison operator. That means that you cannot write your own abs for a custom numeric type as long as your type has a comparison operator.
Problem 2: even if a custom numeric type supports comparison operator, std.math.abs is declared as pure @safe nothrow @nogc, forcing a potential numeric implementation to decorate his opCmp overload with the same attributes.
Real case: according to IEEE-754/2008, the comparison operator *must* signal an invalid operation exception if it encounters a NaN value or *must* set a global error flag. For a standard compliant numeric type, the comparison operator cannot be decorated with nothrow @nocg (since it's throwing exceptions) and cannot be pure (since it's setting global error flags).
Proposal 1:
Rethink abs signature to limit usage to standard numeric types, where comparison is guaranteed to be pure @safe nothrow @nogc
Proposal 2:
Drop fabs. This is probably coming from C where overloads are not available. There is no need to have two names for a function doing the exact same thing. abs must catch any signed type, including floating point.
Comment #1 by robert.schadek — 2024-12-01T16:32:02Z