# Is the least significant bit from bitstring() correct?

I don’t know if this is a bug but it isn’t what I was expecting:

julia> bitstring(Float32(0.777777777777777777777777777777777777777777777777))
"00111111010001110001110001110010"

julia> bitstring(Float64(0.777777777777777777777777777777777777777777777777))
"0011111111101000111000111000111000111000111000111000111000111001"


Shouldn’t the least significant bit of the Float32 encoding be a 1 and the least significant bit of the Float64 encoding by a 0 to capture the 000111… pattern? (Also, the next to least significant bit of the Float32 encoding appears to be flipped.)

This is just rounding. It’s kinda like a plain old decimal representation of \frac{1}{101} = 0.\overline{0099}. If you limit that repeating 0.009900990099\dots to 7 decimal places, it rounds to: 0.0099010. That’s exactly what’s happening here: \frac{7}{9} is similarly a repeating fraction in both decimal and binary and it’s gotta snap to the nearest representable value at some point.

1 Like