# Exponentiation of floats

**URL:** <https://discourse.julialang.org/t/exponentiation-of-floats/105951>\
**Category:** Performance\
**Tags:** question\
**Created:** [November 8, 2023, 2:18pm UTC](https://discourse.julialang.org/t/exponentiation-of-floats/105951 "2023-11-08T14:18:26Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [November 8, 2023, 4:07pm UTC](https://discourse.julialang.org/t/exponentiation-of-floats/105951/21 "2023-11-08T16:07:00Z")

</div>

that absolutely would explain the regression and is a pretty bad performance bug.

---

<div class="post-metadata">

**Author:** ![Zentrik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zentrik/32/35409_2.png) [@Zentrik](https://discourse.julialang.org/u/Zentrik)\
**Post date:** [November 8, 2023, 6:20pm UTC](https://discourse.julialang.org/t/exponentiation-of-floats/105951/22 "2023-11-08T18:20:34Z")

</div>

> <https://github.com/JuliaLang/julia/blob/5aaa94854367ca875375e38ae14f369f124e7315/base/math.jl#L54-L60>

Changing this to

```plaintext
@assume_effects :consistent @inline function two_mul(x::Float64, y::Float64)
    if Core.Intrinsics.have_fma(Float64)
        xy = x*y
        return xy, fma(x, y, -xy)
    end
    # return Base.twomul(x,y)
end

```

and running under Revise seems to mostly fix the regression (~5% slower now compared to 50-100% slower). Interestingly, the regression doesn’t reappear in the same REPL session if I revert the change. I see the same result from `test()` on 1.9, 1.10 and on 1.10 with the change.

```julia
julia> versioninfo()
Julia Version 1.10.0-rc1
Commit 5aaa948543 (2023-11-03 07:44 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 16 × AMD Ryzen 7 5700U with Radeon Graphics
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, znver2)
  Threads: 1 on 16 virtual cores

```

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [November 8, 2023, 6:28pm UTC](https://discourse.julialang.org/t/exponentiation-of-floats/105951/23 "2023-11-08T18:28:16Z")

</div>

It’s weirder than that.

```julia
julia> @btime x^y setup=begin x=rand(); y=rand()end;
  42.232 ns (0 allocations: 0 bytes)

julia> @eval Base.Math @assume_effects :consistent @inline function two_mul(x::Float64, y::Float64)
           if Core.Intrinsics.have_fma(Float64)
               xy = x*y
               return xy, fma(x, y, -xy)
           end
           return Base.twomul(x,y)
       end
two_mul (generic function with 3 methods)

julia> @btime x^y setup=begin x=rand(); y=rand()end;
  17.039 ns (0 allocations: 0 bytes)

```

Just forcing the compiler to re-evaluate exactly the same definition of `two_mul` is enough to make it fast.

---

<div class="post-metadata">

**Author:** ![richard\_sti](https://avatars.discourse-cdn.com/v4/letter/r/dec6dc/32.png) [@richard\_sti](https://discourse.julialang.org/u/richard_sti)\
**Post date:** [July 26, 2024, 7:48pm UTC](https://discourse.julialang.org/t/exponentiation-of-floats/105951/24 "2024-07-26T19:48:16Z")

</div>

Hey! Thanks everyone for the reply. May I ask whether there was any resolution to this? I keep finding the problem of newer versions of Julia to be consistently slower on benchmarks like this (which can turn rather expensive for some ODE problems).

---

<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:** [July 26, 2024, 8:09pm UTC](https://discourse.julialang.org/t/exponentiation-of-floats/105951/25 "2024-07-26T20:09:01Z")

</div>

Yes, I think this one was addressed through [Fix multiversioning issues caused by the parallel llvm work by gbaraldi · Pull Request #52194 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/52194) (and backported, too).

Please keep reporting any and all performance regressions — it’s very valuable to get that information.

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [July 26, 2024, 10:52pm UTC](https://discourse.julialang.org/t/exponentiation-of-floats/105951/26 "2024-07-26T22:52:01Z")

</div>

> [@richard\_sti](#):
>
> I keep finding the problem of newer versions of Julia to be consistently slower on benchmarks like this

Any specifics?

[Previous page](https://discourse.julialang.org/t/exponentiation-of-floats/105951.md?page=1)
