On Sat, Nov 24, 2018 at 11:07 AM Daniela Engert via Boost < boost@lists.boost.org> wrote:
Am 24.11.2018 um 19:48 schrieb Emil Dotchevski via Boost:
The problem with signed/unsigned mismatch is not just in the comparison, but also in the operations. If unsigned x=2, the expression x-3 may not
be
meaningfully represented by an unsigned integer.
Au contraire, mon ami! Unsigned arithmetic is defined in C++ as an abelian ring modulo a value depending on the width of the given unsigned type. In fact, unsigned types are the only useful types if you need well-defined mathematical properties (like I do when it comes to digital signal processing).
Yes, I am aware that unsigned types have defined standard behavior when
wrapping around while with signed ints this is implementation-defined (btw
in signal processing sometimes you want saturation -- which is a valid
implementation for signed operations -- instead of wrapping).
But that's not what I mean. I mean that if you have unsigned x=2 and int y,
the expression x-3