I was reading a book (CSAPP) . In the book it is written that-
floating point addition satisfies the following monotonicity property :
ifa>=b
then(x + a) >= (x+b)
for any valuea
,b
andx
other thanNaN
. This property of real (and integer) addition is not obeyed by unsigned or two's complement addition.
How floating point obeys it?
Why unsigned or two's complement addition doesn't obeys it?
Unsigned integers in C basically form a ring, i.e. they eventually wrap. For example, continuously adding 1 to an unsigned integer will continuously increase it until it wraps to zero, which means adding one yields a result at least less than one, so monotonicity is not satisfied.
Signed integers do overflow which is more complicated but in C it also is undefined behaviour, so we should exclude that.
For floating point numbers in C, according to IEEE745, the addition of two positive numbers (which implies none of them is NaN as NaN is not known to be positive or negative) yields a result greater or equal than the the larger of the two addends: Either by forming a result that indeed is larger, or by yielding one of the addends because the other one gets absorbed, or by yielding infinity. The important point is to note that the addition satisfies monotonicity but not necessarily strict monotonicity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With