[Math] How do we do arithmetic with negative floating point numbers

arithmeticfloating point

I'm studying floating point arithmetic and understand everything in the positive domain but can't seem to wrap my head around how negative floating point numbers are dealt with.

I understand that the sign bit in the 754 IEEE floating point number is the MSB of the bit representation of the number but how will a negative operand interact in terms of subtraction and in multiplication/division?

I apologize in advance if this is a trivial question or if there are resources online for this but I haven't been able to find anything that explains dealing with negative operands in a comprehensive manner.

Thank you.

Best Answer

Floating-point numbers on computers are problematic only because of the effects of their limited numbers of binary digits of precision and the limited range of exponents, leading to roundoff errors, underflow, overflow, and other such problems.

All of these problems occur when you are just using positive numbers with the operations of addition, subtraction, multiplication, and division.

In general, however, changing the sign of one of the operands in an operation on floating-point numbers has exactly the effect that it logically should have. Adding $-x$ to another number is exactly the same as subtracting $x.$ Subtracting $-x$ is exactly the same as adding $x.$ Multiplying $-x$ by $-y$ will give the same result as multiplying $x$ and $y.$ (It is possible that both results will be an overflow, but that's not a problem caused by the sign bit!)

One odd thing about negative floating-point numbers is that it's possible (at least in principle) to have a representation of negative zero that's distinct from positive zero. But I believe you have to get into some kind of exceptional case (underflow, operations with infinities, or the like) in order for this to be an issue.

If you can actually get your hands on one of the official IEEE specifications for floating-point arithmetic, I believe you will find everything there is to say about negative numbers spelled out in excruciatingly boring detail.

Related Question