# X \* y + z does not automatically use FMA instruction

**URL:** <https://discourse.julialang.org/t/x-y-z-does-not-automatically-use-fma-instruction/100640>\
**Category:** Performance\
**Tags:** fast-math\
**Created:** [June 21, 2023, 7:07am UTC](https://discourse.julialang.org/t/x-y-z-does-not-automatically-use-fma-instruction/100640 "2023-06-21T07:07:22Z")\
**Posts on this page:** 1\
**Showing post:** 19

<div class="post-metadata">

**Author:** ![arch.d.robison](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arch.d.robison/32/17699_2.png) [@arch.d.robison](https://discourse.julialang.org/u/arch.d.robison)\
**Post date:** [June 22, 2023, 3:23pm UTC](https://discourse.julialang.org/t/x-y-z-does-not-automatically-use-fma-instruction/100640/19 "2023-06-22T15:23:01Z")

</div>

Using FMA automatically can cause surprises. Consider the following:

```julia
function f(a,b,c)
    @assert a*b ≥ c
    return sqrt(a*b-c)
end

a = 1.0 + 0.5^27
b = 1.0 - 0.5^27
c = 1.0
f(a,b,c)

```

It works as expected. Now suppose the compiler automatically uses FMA inside f, like this:

```julia
function f(a,b,c)
    @assert a*b ≥ c
    return sqrt(fma(a,b,-c))
end

```

Now `f(a,b,c)` throws and exception, because `fma(a,b,-c)` is negative, despite the assertion `a*b ≥ c`.

---

_[View the full topic](https://discourse.julialang.org/t/x-y-z-does-not-automatically-use-fma-instruction/100640)._
