# Inaccurate Matrix Multiplication

**URL:** https://discourse.julialang.org/t/inaccurate-matrix-multiplication/76903
**Category:** General Usage
**Tags:** linearalgebra
**Created:** [February 22, 2022, 11:04am UTC](https://discourse.julialang.org/t/inaccurate-matrix-multiplication/76903 "2022-02-22T11:04:45Z")
**Posts on this page:** 1
**Showing post:** 26

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [February 22, 2022, 3:55pm UTC](https://discourse.julialang.org/t/inaccurate-matrix-multiplication/76903/26 "2022-02-22T15:55:41Z")

</div>

> [@Palli](#):
>
> Is there a way to fix BLAS to avoid FMA when dangerous?

I don’t think that the conclusion here is that FMA is “dangerous”. Sometimes it will give more accurate results than non-fused operations, sometimes (probably less often) it will happen to give less accurate results, but in all cases the results are within the tolerance you would expect from floating-point calculations.

> [@Palli](#):
>
> ```julia
> julia> fma(4.738285026766486e28, 4.0686784105686624e29, -(4.738285026766486e28 * 4.0686784105686624e29))
> 8.475399346267984e41
> 
> ```

I think you are being confused here by the concept of relative error. Is `8.5e41` a “big” error? You have to ask **big compared to what?** In this case, the summands are ±1.9e58, and **8.5e41 / 1.9e58 ≈ 4.4e-17** , so it’s pretty small _compared to the inputs_.

Compared to the exact _output_ of `0.0`, of course, the relative forward error is infinite (you have no correct significant digits), but that would be true of _any_ nonzero answer, and is to be expected because the sum is ill-conditioned (a sum of nonzero inputs with an exact cancellation has an infinite relative condition number).

See also my answer here: ["sum([1.0, 1e100, 1.0, -1e100])" fails - #10 by stevengj](https://discourse.julialang.org/t/sum-1-0-1e100-1-0-1e100-fails/76502/10)

---

_[View the full topic](https://discourse.julialang.org/t/inaccurate-matrix-multiplication/76903)._
