Prerequisite – IEEE Standard 754 Floating Point Numbers
Here, we have discussed an algorithm to multiply two floating point numbers, x and y.
- Convert these numbers in scientific notation, so that we can explicitly represent hidden 1.
- Let ‘a’ be the exponent of x and ‘b’ be the exponent of y.
- Assume resulting exponent c = a+b. It can be adjusted after the next step.
- Multiply mantissa of x to mantissa of y. Call this result m.
- If m does not have a single 1 left of radix point, then adjust radix point so it does, and adjust exponent c to compensate.
- Add sign bits, mod 2, to get sign of resulting multiplication.
- Convert back to one byte floating point representation, truncating bits if needed.
Negative values are simple to take care of in floating point multiplication. Treat sign bit as 1 bit unsigned binary, add mod 2. This is the same as XORing the sign bit.
Suppose you want to multiply following two numbers:
Now, these are steps according to above algorithm:
- Given, A = 1.11 x 2^0 and B = 1.01 x 2^2
- So, exponent c = a + b = 0 + 2 = 2 is the resulting exponent.
- Now, multiply 1.11 by 1.01, so result will be 10.0011
- We need to normalize 10.0011 to 1.00011 and adjust exponent 1 by 3 appropriately.
- Resulting sign bit 0 (XOR) 0 = 0, means positive.
- Now, truncate and normalite it 1.00011 x 2^3 to 1.000 x 2^3.
Therefore, resultant number is,
Similarly, we can multiply other floating point numbers.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- IEEE Standard 754 Floating Point Numbers
- Introduction of Floating Point Representation
- Floating Point Representation - Basics
- Curzon Numbers
- How to increment letters like numbers in PHP ?
- Find the Nth Hogben Numbers
- Maximise the sum of two Numbers using at most one swap between them
- Group all co-prime numbers from 1 to N
- Panarithmic numbers within a given range
- Representation of Negative Binary Numbers
- Arithmetic Operations of Binary Numbers
- Arithmetic Operations of Octal Numbers
- Longest subsequence of even numbers in an Array
- Check whether two numbers are in golden ratio
- Arithmetic Operations of Hexadecimal Numbers
- Sum of numbers in the Kth level of a Fibonacci triangle
- Remove all the fibonacci numbers from the given array
- Find two Fibonacci numbers whose sum can be represented as N
- Check if an Array is a permutation of numbers from 1 to N
- How the negative numbers are stored in memory?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.