JuliaData / DelimitedFiles.jl

A package for reading and writing files with delimited values (Originally a Julia stdlib)
MIT License
18 stars 2 forks source link

`readdlm` casts (un)signed integers to floats #8

Open jakebolewski opened 8 years ago

jakebolewski commented 8 years ago
julia> io = IOBuffer("0x0\n0x1\n0x2")
IOBuffer(data=UInt8[...], readable=true, writable=false, seekable=true, append=false, size=11, maxsize=Inf, ptr=1, mark=-1)

julia> readdlm(io)
3×1 Array{Float64,2}:
 0.0
 1.0
 2.0

julia> io = IOBuffer("0\n1\n2")
IOBuffer(data=UInt8[...], readable=true, writable=false, seekable=true, append=false, size=5, maxsize=Inf, ptr=1, mark=-1)

julia> readdlm(io)
3×1 Array{Float64,2}:
 0.0
 1.0
 2.0

julia> io = IOBuffer("foo\n1\n2")
IOBuffer(data=UInt8[...], readable=true, writable=false, seekable=true, append=false, size=7, maxsize=Inf, ptr=1, mark=-1)

julia> readdlm(io)
3×1 Array{Any,2}:
  "foo"
 1
 2

julia> io = IOBuffer("foo\n0x1\n0x2")
IOBuffer(data=UInt8[...], readable=true, writable=false, seekable=true, append=false, size=11, maxsize=Inf, ptr=1, mark=-1)

julia> readdlm(io)
3×1 Array{Any,2}:
  "foo"
 1
 2
jakebolewski commented 8 years ago

This is also a problem when you try to parse integers that are larger than Int64:

julia> io = IOBuffer("1234532123456543212345675432134899348390483940")
IOBuffer(data=UInt8[...], readable=true, writable=false, seekable=true, append=false, size=46, maxsize=Inf, ptr=1, mark=-1)

julia> readdlm(io)
1×1 Array{Float64,2}:
 1.23453e45

julia> ans[1] == eval(parse("1234532123456543212345675432134899348390483940"))
false