Created
February 8, 2014 17:54
-
-
Save aprell/8887486 to your computer and use it in GitHub Desktop.
Functions for inspecting IEEE 754 floating-point numbers in Julia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function floatdump(n::Float32) | |
sign = bits(n)[1] | |
exp = bits(n)[2:9] | |
mant = bits(n)[10:end] | |
println("Sign: $sign $(sign == '1' ? "(-)" : "(+)")") | |
println("Exponent: $exp ($(parseint(exp, 2) - 127) + 127)") | |
println("Mantissa: $mant ($(parseint(mant, 2) / 2^23) * 2^23)") | |
end | |
function floatdump(n::Float64) | |
sign = bits(n)[1] | |
exp = bits(n)[2:12] | |
mant = bits(n)[13:end] | |
println("Sign: $sign $(sign == '1' ? "(-)" : "(+)")") | |
println("Exponent: $exp ($(parseint(exp, 2) - 1023) + 1023)") | |
println("Mantissa: $mant ($(parseint(mant, 2) / 2^52) * 2^52)") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment