I ask because I am computing matrix multiplications where all the matrix values are integers.
I'd like to use LAPACK so that I get fast code that is correct. Will two large integers (whose product is less than 2^53
), stored as double
s, when multiplied, yield a double
containing the exact integer result?
Yes! A double's data is split into its sign, exponent, and fraction:
Wikipedia has an article explaining the ranges of representable numbers
Your analysis is correct:
Hence a product of two values that equals an integer in that range will therefore be represented exactly.
Reference: What every computer scientist should know about floating-point arithmetic. The key section is the discussion of the IEEE standard as pertaining to operations. That contains the statement of the second bullet point above. You already knew the first bullet point and it's the second point that completes the argument.