--- psiconv/trunk/lib/psiconv/parse_simple.c 2001/01/30 23:15:24 100 +++ psiconv/trunk/lib/psiconv/parse_simple.c 2001/01/30 23:57:28 101 @@ -21,6 +21,7 @@ #include "compat.h" #include +#include #include "parse_routines.h" #include "error.h" @@ -303,3 +304,45 @@ *length = 0; return NULL; } + +psiconv_float_t psiconv_read_float(const psiconv_buffer buf, int lev, + psiconv_u32 off, int *length, int *status) +{ + psiconv_float_t result,bitvalue; + int res,bit; + psiconv_u32 temp=0; + + psiconv_progress(lev+1,off,"Going to read a float"); + + bitvalue = 0.5; + result = 1.0; + for (bit = 0x33; bit > 0; bit--) { + if ((bit == 0x33) || ((bit & 0x07) == 0x07)) + temp = psiconv_read_u8(buf,lev+2,off+ (bit >> 3),&res); + if (res) + goto ERROR; + if (temp & (0x01 << (bit & 0x07))) + result += bitvalue; + bitvalue /= 2.0; + } + temp = psiconv_read_u16(buf,lev+2,off+6,&res); + if (res) + goto ERROR; + if (temp & 0x8000) + result = -result; + temp = (temp & 0x7ff0) >> 4; + result *= pow(2.0,((int) temp)-0x3ff); + psiconv_debug(lev+1,off,"Float value: %f",result); + if (length) + *length = 8; + if (*status) + *status = res; + return result; +ERROR: + psiconv_warn(lev+1,off,"Reading of float failed"); + if (length) + *length = 0; + if (*status) + *status = res; + return 0.0; +}