# Range behavior for Float32

**URL:** <https://discourse.julialang.org/t/range-behavior-for-float32/88393>\
**Category:** General Usage\
**Created:** [October 7, 2022, 11:14am UTC](https://discourse.julialang.org/t/range-behavior-for-float32/88393 "2022-10-07T11:14:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Iulian.Cioarca](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iulian.cioarca/32/30166_2.png) [@Iulian.Cioarca](https://discourse.julialang.org/u/Iulian.Cioarca)\
**Post date:** [October 7, 2022, 11:14am UTC](https://discourse.julialang.org/t/range-behavior-for-float32/88393/1 "2022-10-07T11:14:30Z")

</div>

I ran into the following issue on Julia 1.7.1:

```julia
dt = 4.0e-9
l32 = 23_849_999
t = collect(0.0:dt:dt*l32) # Vector{Float64} with 23850000 elements
t0 = collect(LinRange(0.0, dt, l32+1)) # Vector{Float64} with 23850000 elements

dt = Float32(4.0e-9)
t = collect(Float32(0.0):dt:dt*l32) # Vector{Float32} with 23850001 elements
t0 = collect(LinRange(Float32(0.0), dt, l32+1)) # Vector{Float32} with 23850000 elements

```

Can someone explain why the Float32 vector generated without LinRange has different length?

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [October 7, 2022, 11:57am UTC](https://discourse.julialang.org/t/range-behavior-for-float32/88393/2 "2022-10-07T11:57:29Z")

</div>

Float32 is no longer accurate for such large number (not a Julia problem, I’m using 1.8.1, no version will “fix”, just in general an expected problem with IEEE floats, eventually if large enough):

```julia
julia> Int64(Float32(23_849_999))
23850000

```

I believe this is one reason for LinRange. So use that or respect:

```julia
julia> maxintfloat(Float64)
9.007199254740992e15

julia> Int64(maxintfloat(Float32)) # last accurate integer to last digit, much smaller than last (inaccurate) integer
16777216

julia> BigInt(floatmax(Float32)) # a bit deceiving
340282346638528859811704183484516925440

```
