<div dir="ltr">This proposal is very much in the spirit of the earlier proposal on adding new float/double functions; for instance see here: <a href="https://mail.haskell.org/pipermail/libraries/2014-April/022667.html">https://mail.haskell.org/pipermail/libraries/2014-April/022667.html</a><div><br></div><div>"fma" (a.k.a. fused-multiply-add) is one of those functions; which is the workhorse in many HPC applications. The idea is to multiply two floats and add a third with just one rounding, and thus preserving more precision. There are a multitude of applications for this operation in engineering data-analysis, and modern processors come with custom implementations and a lot of hardware to support it natively.</div><div><br></div><div>I created a ticket along these lines already: <a href="https://ghc.haskell.org/trac/ghc/ticket/10364">https://ghc.haskell.org/trac/ghc/ticket/10364</a></div><div><br></div><div>Edward suggested that the matter should further be discussed here.</div><div><br></div><div>I think the proposal is rather straightforward, and should be noncontroversial. To wit, we shall add a new method to the RealFloat class:</div><div><br></div><div>  class (RealFrac a, Floating a) => RealFloat a where</div><div>      ...</div><div>      fma :: a -> a -> a -> a</div><div><br></div><div>The intention is that</div><div><br></div><div>      fma x y z = x * y + z</div><div><br></div><div>except the multiplication and addition are done infinitely-precisely, and then rounded only once; as opposed to two roundings as one would get with the above implementation. Most modern architectures directly support this operation so we can map it easily; and in case the architecture does not have it available, we can get it via the C-math libraries, where it appears under the names fma (the double version), and fmaf (the float version.)</div><div><br></div><div>There should be no default definitions; as an incorrect (two-rounding version) would essentially beat the purpose of having fma in the first place.</div><div><br></div><div>While the name "fma" is well-established in the arithmetic/hardware community and in the C-library, we can also go with "fusedMultiplyAdd," if that is deemed more clear.</div><div><br></div><div>Discussion period: 2 weeks.</div></div>