# InexactError in Range

**URL:** <https://discourse.julialang.org/t/inexacterror-in-range/112691>\
**Category:** General Usage\
**Created:** [April 8, 2024, 6:57pm UTC](https://discourse.julialang.org/t/inexacterror-in-range/112691 "2024-04-08T18:57:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdm204](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jdm204/32/39289_2.png) [@jdm204](https://discourse.julialang.org/u/jdm204)\
**Post date:** [April 8, 2024, 6:57pm UTC](https://discourse.julialang.org/t/inexacterror-in-range/112691/1 "2024-04-08T18:57:33Z")

</div>

With `f = -9.223372036854776e18`, `(f/2):0.0` gives a range of floats, while `f:0.0` gives the following error:

```julia
ERROR: InexactError: trunc(Int64, 9.223372036854776e18)
Stacktrace:
 [1] trunc
   @ ./float.jl:905 [inlined]
 [2] round
   @ ./float.jl:385 [inlined]
 [3] (::Colon)(start::Float64, step::Float64, stop::Float64)
   @ Base ./twiceprecision.jl:427
 [4] (::Colon)(a::Float64, b::Float64)
   @ Base ./range.jl:14
 [5] top-level scope

```

I’m struggling to understand what boundary I’m crossing going from `f/2` to `f` that makes Julia not able to give me a value for `f:0.0`!

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [April 8, 2024, 7:21pm UTC](https://discourse.julialang.org/t/inexacterror-in-range/112691/2 "2024-04-08T19:21:16Z")

</div>

```julia
julia> f == typemin(Int)
true

```

This is an implementation issue, unfortunately, where the length of the range is assumed to be an `Int`, but it can’t be rounded to an `Int` accurately.

```julia
julia> start = f
-9.223372036854776e18

julia> stop = 0.0
0.0

julia> step = 1.0
1.0

julia> lf = (stop-start)/step
9.223372036854776e18

julia> lf > typemax(Int)
true

```

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [April 8, 2024, 8:30pm UTC](https://discourse.julialang.org/t/inexacterror-in-range/112691/3 "2024-04-08T20:30:08Z")

</div>

If you need this to work, `BigInt` may help.

```julia-repl
julia> r = BigInt(f):0.0
-9.223372036854775808e+18:1.0:0.0

julia> length(r)
9223372036854775809

```
