# Power function numerical mystery

**URL:** <https://discourse.julialang.org/t/power-function-numerical-mystery/9203>\
**Category:** General Usage\
**Tags:** question\
**Created:** [February 20, 2018, 1:59pm UTC](https://discourse.julialang.org/t/power-function-numerical-mystery/9203 "2018-02-20T13:59:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [February 20, 2018, 1:59pm UTC](https://discourse.julialang.org/t/power-function-numerical-mystery/9203/1 "2018-02-20T13:59:20Z")

</div>

I’m trying to hunt down a numerical platform deviation. Much simplification leads to this power computation, where I don’t understand the variation in the results (in the last bit of the mantissa).

```julia
julia> 15.632459f0 ^ 0.2f0
1.7330276f0

julia> 15.632459f0 .^ 0.2f0
1.7330276f0

julia> x, a = 15.632459f0, 0.2f0
(15.632459f0, 0.2f0)

julia> x ^ 0.2f0
1.7330276f0

julia> x .^ 0.2f0
1.7330275f0

julia> 15.632459f0 ^ a
1.7330276f0

julia> 15.632459f0 .^ a
1.7330275f0

julia> x ^ a
1.7330276f0

julia> x .^ a
1.7330276f0

julia> versioninfo()
Julia Version 0.6.2
Commit d386e40c17* (2017-12-13 18:08 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Xeon(R) CPU E31270 @ 3.40GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, sandybridge)

```

Can someone explain what’s going on here? Moreover, this variation does not happen on a Linux system with a more recent CPU:

```julia
julia> versioninfo()
Julia Version 0.6.2
Commit d386e40c17 (2017-12-13 18:08 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Prescott)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, broadwell)

```

---

<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:** [February 20, 2018, 2:59pm UTC](https://discourse.julialang.org/t/power-function-numerical-mystery/9203/2 "2018-02-20T14:59:30Z")

</div>

On 0.6, dot-ops fuse numeric literals into an anonymous function that gets compiled separately. I can’t reproduce, but maybe check the difference between:

```julia
f(x, a) = x ^ a
g(a) = 15.632459f0 ^ a

```

If `f(15.632459f0, 0.2f0)` and `g(0.2f0)` are different, then we can start digging into the LLVM/native code to see what’s different.

---

<div class="post-metadata">

**Author:** ![foobar\_lv2](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)\
**Post date:** [February 20, 2018, 4:00pm UTC](https://discourse.julialang.org/t/power-function-numerical-mystery/9203/3 "2018-02-20T16:00:48Z")

</div>

Cannot reproduce either. More precisely, I find no way to get `1.7330275f0`.

---

<div class="post-metadata">

**Author:** ![simonbyrne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simonbyrne/32/19_2.png) [@simonbyrne](https://discourse.julialang.org/u/simonbyrne)\
**Post date:** [February 20, 2018, 7:07pm UTC](https://discourse.julialang.org/t/power-function-numerical-mystery/9203/4 "2018-02-20T19:07:12Z")

</div>

Can you also check

```julia
h(x) = x^0.2f0
h(15.632459f0)

```

I suspect it is something weird with the system math library: though we use openlibm for most things, LLVM intrinsics (such as `pow`) still call the system library.

What OS and version of glibc are you running? You can find glibc version by `ldd --version`.

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [February 20, 2018, 9:13pm UTC](https://discourse.julialang.org/t/power-function-numerical-mystery/9203/5 "2018-02-20T21:13:52Z")

</div>

The odd results are from Windows 7 using the 64-bit binary from the download page. On Linux I get 1.7330276f0 in all cases.

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [February 20, 2018, 9:24pm UTC](https://discourse.julialang.org/t/power-function-numerical-mystery/9203/6 "2018-02-20T21:24:08Z")

</div>

Those all give the `1.7330275f0` result.

```julia
julia> f(x, a) = x ^ a
f (generic function with 1 method)

julia> g(a) = 15.632459f0 ^ a
g (generic function with 1 method)

julia> f(15.632459f0, 0.2f0)
1.7330275f0

julia> g(0.2f0)
1.7330275f0

julia> h(x) = x^0.2f0
h (generic function with 1 method)

julia> h(15.632459f0)
1.7330275f0

```

---

<div class="post-metadata">

**Author:** ![Seif\_Shebl](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Post date:** [February 21, 2018, 2:46pm UTC](https://discourse.julialang.org/t/power-function-numerical-mystery/9203/7 "2018-02-21T14:46:37Z")

</div>

Windows 10 64bit, Julia 0.7 (all except second one giving 1.7330275f0):

```julia
julia> 15.632459f0 ^ 0.2f0
1.7330275f0

julia> 15.632459f0 .^ 0.2f0
1.7330276f0

julia> x, a = 15.632459f0, 0.2f0
(15.632459f0, 0.2f0)

julia> x ^ 0.2f0
1.7330275f0

julia> x .^ 0.2f0
1.7330275f0

julia> 15.632459f0 ^ a
1.7330275f0

julia> 15.632459f0 .^ a
1.7330275f0

julia> x ^ a
1.7330275f0

julia> x .^ a
1.7330275f0

```

Julia 0.6.2 though gives different results:

```julia
julia> 15.632459f0 ^ 0.2f0
1.7330276f0

julia> 15.632459f0 .^ 0.2f0
1.7330276f0

julia> x, a = 15.632459f0, 0.2f0
(15.632459f0, 0.2f0)

julia> x ^ 0.2f0
1.7330276f0

julia> x .^ 0.2f0
1.7330275f0

julia> 15.632459f0 ^ a
1.7330276f0

julia> 15.632459f0 .^ a
1.7330275f0

julia> x ^ a
1.7330276f0

julia> x .^ a
1.7330276f0

```
