# Why is \`muladd\` not consistent even though it has the effect?

**URL:** <https://discourse.julialang.org/t/why-is-muladd-not-consistent-even-though-it-has-the-effect/140455>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 1, 2026, 12:27am UTC](https://discourse.julialang.org/t/why-is-muladd-not-consistent-even-though-it-has-the-effect/140455 "2026-11-01T00:27:37Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [November 2, 2026, 7:13pm UTC](https://discourse.julialang.org/t/why-is-muladd-not-consistent-even-though-it-has-the-effect/140455/8 "2026-11-02T19:13:36Z")

</div>

Here’s a more minimal example, stemming from [a favorite old post of mine](https://discourse.julialang.org/t/optimizing-sums-of-products-dot-products/119515/18):

```julia-auto
julia> discriminant(a,b,c) = muladd(b, b, -4*a*c)
discriminant (generic function with 1 method)

julia> g1(x,y,z) = discriminant(x,y,z), y^2.0
g1 (generic function with 1 method)

julia> g2(x,y,z) = discriminant(x,y,z), y^2
g2 (generic function with 1 method)

julia> g1(.2, .1, .0125)
(-8.326672684688674e-19, 0.010000000000000002)

julia> g2(.2, .1, .0125)
(8.326672684688674e-19, 0.010000000000000002)

julia> Base.infer_effects(discriminant, (Float64, Float64, Float64))
(+c,+e,+n,+t,+s,+m,+u,+o,+r)

```

This then has potential real-world impacts in a quadratic-equation root-solver:

```julia-auto
julia> @inline function roots(a,b,c)
           if discriminant(a,b,c) < 0
               "no real roots"
           else
               roots = [(-b ± sqrt(discriminant(a,b,c)))/(2*a) for (±) in (+, -)]
               "root at $(unique(roots))"
           end
       end
roots (generic function with 1 method)

julia> roots(.2, .1, .0125)
"no real roots"

julia> f1(a,b,c) = roots(a,b,c), b^2.0
f1 (generic function with 1 method)

julia> f1(.2, .1, .0125)
("no real roots", 0.010000000000000002)

julia> f2(a,b,c) = roots(a,b,c), b*b
f2 (generic function with 1 method)

julia> f2(.2, .1, .0125)
ERROR: DomainError with -8.326672684688674e-19:
sqrt was called with a negative real argument but will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).
[...]

julia> versioninfo()
Julia Version 1.13.3
Commit 67ac47b9cd8 (2026-10-25 15:28 UTC)
Build Info:
  Official https://julialang.org release
Platform Info:
  OS: macOS (arm64-apple-darwin27.0.0)
  CPU: 8 × Apple M1 Pro
  WORD_SIZE: 64
  LLVM: libLLVM-20.1.8 (ORCJIT, apple-m1)
  GC: Built with stock GC
Threads: 1 default, 1 interactive, 1 GC (on 8 virtual cores)

```

`discriminant` is `+c` but is giving different values, even inside the same method body!

---

_[View the full topic](https://discourse.julialang.org/t/why-is-muladd-not-consistent-even-though-it-has-the-effect/140455)._
