# Problem with rounding with big numbers

**URL:** <https://discourse.julialang.org/t/problem-with-rounding-with-big-numbers/4454>\
**Category:** General Usage\
**Created:** [June 26, 2017, 12:48am UTC](https://discourse.julialang.org/t/problem-with-rounding-with-big-numbers/4454 "2017-06-26T00:48:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jgk99](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@jgk99](https://discourse.julialang.org/u/jgk99)\
**Post date:** [June 26, 2017, 12:48am UTC](https://discourse.julialang.org/t/problem-with-rounding-with-big-numbers/4454/1 "2017-06-26T00:48:18Z")

</div>

BigInt(big(2017.)^2017) does not generate the correct value which is generated by: big(2017)^2017. Why is their a rounding error with BigFloat?

---

<div class="post-metadata">

**Author:** ![adamslc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adamslc/32/3452_2.png) [@adamslc](https://discourse.julialang.org/u/adamslc)\
**Post date:** [June 26, 2017, 1:45am UTC](https://discourse.julialang.org/t/problem-with-rounding-with-big-numbers/4454/2 "2017-06-26T01:45:33Z")

</div>

You can fix this by calling `setprecision` with a large enough value:

```julia
julia> big(2017.)^2017 == big(2017)^2017
false

julia> setprecision(100000)
100000

julia> big(2017.)^2017 == big(2017)^2017
true

```

You can also set the precision of individual `BigFloat`s as `BigFloat(2017, 100000)`, but it looks like the precision is not propagated through calculations. In the first case, this method is called:

```julia
function ^(x::BigFloat, y::ClongMax)
    z = BigFloat()
    ccall((:mpfr_pow_si, :libmpfr), Int32, (Ptr{BigFloat}, Ptr{BigFloat}, Clong, Int32), &z, &x, y, ROUNDING_MODE[])
    return z
end

```

You can see that `z` is created to store the result of the exponentiation, but it uses the default system precision for `BigFloat`s, not the precision of the `BigFloat` to be exponentiated.

---

<div class="post-metadata">

**Author:** ![maxchendt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxchendt/32/42976_2.png) [@maxchendt](https://discourse.julialang.org/u/maxchendt)\
**Post date:** [December 6, 2022, 10:05am UTC](https://discourse.julialang.org/t/problem-with-rounding-with-big-numbers/4454/3 "2022-12-06T10:05:41Z")

</div>

```julia
julia> typeof(big(2017)^2017)
BigInt

julia> typeof(big(2017.)^2017)
BigFloat

```

`BigFloat` is rounded (default precision 256 bits), `BigInt` is exact.
