# BigFloat wrong

**URL:** <https://discourse.julialang.org/t/bigfloat-wrong/27987>\
**Category:** Numerics\
**Created:** [August 26, 2019, 6:37am UTC](https://discourse.julialang.org/t/bigfloat-wrong/27987 "2019-08-26T06:37:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mefi](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@mefi](https://discourse.julialang.org/u/mefi)\
**Post date:** [August 26, 2019, 6:37am UTC](https://discourse.julialang.org/t/bigfloat-wrong/27987/1 "2019-08-26T06:37:18Z")

</div>

Why BigFloat(10^(1/4) is wrong?  
julia\> BigFloat(10^(1/4))  
1.778279410038922758729995621251873672008514404296875

exact: 1.77827941003892280122542119519…

Thanks

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 26, 2019, 6:54am UTC](https://discourse.julialang.org/t/bigfloat-wrong/27987/2 "2019-08-26T06:54:27Z")

</div>

Perhaps you want to convert before the operation:

```julia
julia> BigFloat(10)^(1/4)
1.778279410038922801225421195192684844735790526402255358011830722776301881539489

```

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [August 26, 2019, 7:05am UTC](https://discourse.julialang.org/t/bigfloat-wrong/27987/3 "2019-08-26T07:05:31Z")

</div>

To elaborate more on the previous answer, when `x` is a `Float64`, `BigFloat(x)` doesn’t give you extra precision compared to the original `x`, it just represents `x`, which has 53 bits of precision, as a `BigFloat`. To construct a `BigFloat` you want either to start from an integer (like in the example above) or use the `big"..."` string literal

---

<div class="post-metadata">

**Author:** ![mefi](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@mefi](https://discourse.julialang.org/u/mefi)\
**Post date:** [August 26, 2019, 7:07am UTC](https://discourse.julialang.org/t/bigfloat-wrong/27987/4 "2019-08-26T07:07:29Z")

</div>

Oh, Thanks. What you mean with “convert”?

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [August 26, 2019, 7:20am UTC](https://discourse.julialang.org/t/bigfloat-wrong/27987/5 "2019-08-26T07:20:44Z")

</div>

Try:

```julia
julia> 10^(1/BigFloat(4))
1.778279410038922801225421195192684844735790526402255358011830722776301881539489

```

You must make sure that already the first operation, the division is done with high accuracy.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 26, 2019, 7:25am UTC](https://discourse.julialang.org/t/bigfloat-wrong/27987/6 "2019-08-26T07:25:57Z")

</div>

`BigFloat(10)` will convert `10::Int` to a `BigFloat`.

The key point is that `^` already happens with `BigFloat`s, which can be achieved by either argument being one.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [August 26, 2019, 2:38pm UTC](https://discourse.julialang.org/t/bigfloat-wrong/27987/7 "2019-08-26T14:38:15Z")

</div>

It’s often more convenient to just write `big(n)` to get either a `BigFloat` or a `BigInt` depending on the argument type:

```julia
julia> big(10)^(1/4)
1.778279410038922801225421195192684844735790526402255358011830722776301881539489

julia> 10^(1/big(4))
1.778279410038922801225421195192684844735790526402255358011830722776301881539489

```

Note that for `1/4` these are the same because `1/4` is exactly representable in binary but for other fractions, as @ufechner7 pointed out, you’ll want to make sure the division is done in high precision by doing the latter version. Here’s an example where they differ:

```julia
julia> big(10)^(1/5)
1.584893192461113525718041298089470305609734784375671350368393872884966550887179

julia> 10^(1/big(5))
1.584893192461113485202101373391507013269442133825039068316296812316656863668456

```

---

<div class="post-metadata">

**Author:** ![mefi](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@mefi](https://discourse.julialang.org/u/mefi)\
**Post date:** [August 26, 2019, 4:42pm UTC](https://discourse.julialang.org/t/bigfloat-wrong/27987/8 "2019-08-26T16:42:27Z")

</div>

Thank You for this tip.  
Sincerely

Albert Gächter
