Search code examples
mathfloating-pointlinear-algebralapackdouble-precision

Is integer multiplication implemented using double precision floating point exact up until 2^53?


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 doubles, when multiplied, yield a double containing the exact integer result?


Solution

  • Your analysis is correct:

    • All integers between -253 and 253 are exactly representable in double precision.
    • The IEEE754 standard requires calculations to be performed exactly, and then rounded to the nearest representable number.

    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.