FMA">

Multiplication by an Arbitrary Precision Constant with an FMA

Posted by Beetle B. on Fri 19 April 2019

Suppose you need to multiply by a constant that is not exactly representable. Think \(\pi\) and the like. We’d like to multiply and round correctly.

Consider the simple algorithm. Let \(x\) be the floating point number and \(C\) the constant. Compute:

  • \(C_{h}=\RN(C)\)
  • \(C_{l}=\RN(C-C_{h})\)
  • \(u_{1}=\RN(C_{1}x)\)
  • \(u_{2}=\RN(C_{h}x+u_{1})\)

Return \(u_{2}\).

This will not always return the correct \(\RN(Cx)\) for all \(x\). But it works most of the time and there is a simple way to check if it didn’t work.

I did not read all the details of this method of checking.