0

So every number in a computer is represented by binary numbers. I want to know how a computer does binary addition/subtraction of single-precision 32-bit floating-point numbers, especially when two numbers have different exponents.

user56220
  • 327
  • 1
  • 3
  • 6
  • 2
    Refer to http://en.wikipedia.org/wiki/Floating_point#Addition_and_subtraction Your question might be on-topic, but the Internet is awash with good material for your education and there's little point anyone reproducing that here. – High Performance Mark Sep 04 '14 at 15:12
  • But as far as I know, Wikipedia does not really deal with binary number case, which is what computers actually do.. And so with other stuffs. – user56220 Sep 04 '14 at 15:15
  • Binary, ternary, decimal, hexadecimal, whatever, the fundamentals are the same whatever base you use. It'll be a valuable learning exercise for you to translate the decimal explanation on Wikipedia into binary. If that's too challenging, use your favourite search engine, find a binary explanation. – High Performance Mark Sep 04 '14 at 15:19
  • 1
    Here is a very good explanation. I admit that I knew what to search for, so I don't blame you for not finding it, but this kind of essay is too much to expect as a SO answer: http://pages.cs.wisc.edu/~david/courses/cs552/S12/handouts/guardbits.pdf – Pascal Cuoq Sep 04 '14 at 15:21
  • @PascalCuoq I'm not sure an explanation of guard bits is the best thing to put under a complete beginner's nose. But we'll see – High Performance Mark Sep 04 '14 at 15:25
  • @HighPerformanceMark Well guard bits are “how a computer does binary addition/subtraction of […] floating-point numbers, especially when two numbers have different exponents”, but indeed the PDF I found assumes that the reader already knows what these bits are, and only shows that three of them are necessary. Someone asked about them and only got the same link: http://stackoverflow.com/questions/19146131/rounding-floating-point-numbers-after-addition-guard-sticky-and-round-bits – Pascal Cuoq Sep 04 '14 at 16:02
  • Your question is very broad. Entire books have been written just on the subject of floating point arithmetic. (http://www.amazon.com/Handbook-Floating-Point-Arithmetic-Jean-Michel-Muller/dp/081764704X/) Is there some specific detail that you want to know? – Solomon Slow Sep 06 '14 at 19:21
  • Possible duplicate of [Adding 32 bit floating point numbers.](http://stackoverflow.com/questions/7884343/adding-32-bit-floating-point-numbers?rq=1) – phuclv Mar 09 '15 at 08:47
  • you just scale the values so that their radix points align, similar to how addition and subtraction is done in decimal in paper – phuclv Apr 26 '19 at 15:22
  • Possible duplicate of [Adding 32 bit floating point numbers.](https://stackoverflow.com/questions/7884343/adding-32-bit-floating-point-numbers) – phuclv Apr 26 '19 at 15:22

0 Answers0