Search code examples
cassemblyfloating-pointmultiplication

How does C multiply two float numbers?


If we have two integers numbers, 5 and 6, for example, we can just do

for(int i = 0; i < 5; i++)
   number += 6;

That is the same thing as

number = 5*6;

But, how does it works for float numbers? I searched in a lot of forums and couldn't find the answer. Does anybody know how C makes two floats be multiplied?


Solution

  • Nowadays, floating-point operations are performed as single instructions in the ALU's repertoire, and no software implementation is necessary.

    Anyway, you can easily imagine that a floating-point multiply is performed by

    • multiplying the mantissas, viewed as integers with proper scaling;

    • add the exponents;

    • combine the signs.

    Extra housekeeping needs to be done for special numbers, such as zero.