News Score: Score the News, Sort the News, Rewrite the Headlines

Why Does Integer Addition Approximate Float Multiplication?

Here is a rough approximation of float multiplication (source): float rough_float_multiply(float a, float b) { constexpr uint32_t bias = 0x3f76d000; return bit_cast<float>(bit_cast<uint32_t>(a) + bit_cast<uint32_t>(b) - bias); } We’re casting the floats to ints, adding them, adjusting the exponent, and returning as float. If you think about it for a second you will realize that since the float contains the exponent, this won’t be too wrong: You can multiply two numbers by adding their exponents....

Read more at probablydance.com

© News Score  score the news, sort the news, rewrite the headlines