using Printf
function decode_Float64(x::Float64)
s = bitstring(x)
sgn = parse(Int,s[1],base=2)
e = parse(Int,s[2:12],base=2)
f = parse(Int,s[13:64],base=2)
ffrac = f/2^52
ebias = 1023
fstr = (@sprintf( "%.17f", ffrac) )[3:end]
if e == 0
println( @sprintf(" (-1)^(%i) x 2^(%i) x 0.%s = %g ", sgn, 1-ebias, fstr, x) )
elseif e == 2^11 - 1
println( @sprintf(" (-1)^(%i) x 2^(Inf) x 1.%s = %g ", sgn, fstr, x) )
else
println( @sprintf(" (-1)^(%i) x 2^(%i) x 1.%s = %g ", sgn, e-ebias, fstr, x) )
end
end
decode_Float64(Inf)
decode_Float64(NaN)
decode_Float64(0. / 0.)
decode_Float64(-Inf)
decode_Float64(-Inf + Inf)
decode_Float64(reinterpret(Float64,0x000fffffffffffff))
decode_Float64(1.)
decode_Float64(nextfloat(1.))
decode_Float64(prevfloat(1.))
decode_Float64(-prevfloat(1.))
setprecision(BigFloat,3)
setrounding(BigFloat,RoundDown)
x = big"1.0"
for i=1:25
x = nextfloat(x)
@show x
end
decode_Float64(Inf - Inf)
decode_Float64(1.)
decode_Float64(nextfloat(1.))
println( bitstring(1.) )
println( bitstring(nextfloat(1.)) )
@show eps(1.)
@show 2. ^(-52.)