(* Read in a 32-bit IEEE 754 floating point number *)
let read_float32 ic =
        let rec pow2 = function
                | 0 -> 1
                | n -> 2 * (pow2 (n - 1))
        in
        let getbit b n =
                (b land (pow2 n)) lsr n 
        in
        let b0 = input_byte ic in        
        let b1 = input_byte ic in        
        let b2 = input_byte ic in        
        let b3 = input_byte ic in
        let sign = getbit b3 7
        and exponent = 128*(getbit b3 6) + 64*(getbit b3 5) + 32*(getbit b3 4) 
                                        + 16*(getbit b3 3) + 8*(getbit b3 2) + 4*(getbit b3 1) 
                                        + 2*(getbit b3 0) + (getbit b2 7) 
        and significand = b0 + 256*b1 + 65536*(((b2 lsl 1) land 0xFF ) lsr 1) in
        let max_significand = (float (pow2 23)) -. 1.0 in
        if exponent = 255 then
                if significand = 0 then
                        if sign = 0 then neg_infinity else infinity
                else
                        nan
        else if exponent = 0 then
                if significand = 0 then
                        if sign = 0 then 0.0 else -0.0
                else
                        let fs = if sign = 0 then 1.0 else -1.0
                        and fexp = (2.0) ** (-126.0)
                        and fsig = ((float significand) /. max_significand) in
                        fs *. fexp *. fsig
        else
                let fs = if sign = 0 then 1.0 else -1.0
                and fexp = (2.0) ** (float (exponent - 127))
                and fsig = 1.0 +. ((float significand) /. max_significand) in
                fs *. fexp *. fsig