double ReadExtended(const unsigned char *bytes) { double f; int expon; unsigned long hiMant, loMant; expon = ((bytes[0] & 0x7F) << 8) | (bytes[1] & 0xFF); hiMant = ReadLong(bytes+2); loMant = ReadLong(bytes+6); if (expon == 0 && hiMant == 0 && loMant == 0) f = 0; else { if (expon == 0x7FFF) /* Infinity or NaN */ f = -1; else { expon -= 16383; /* must #include <math.h> or these won't work */ f = ldexp(UnsignedToFloat(hiMant),expon -= 31); f += ldexp(UnsignedToFloat(loMant),expon -= 32); } } if (bytes[0] & 0x80) return -f; return f; }
double ConvertFromIeeeExtended(unsigned char* bytes /* LCN */) { double f; int expon; unsigned long hiMant, loMant; expon = ((bytes[0] & 0x7F) << 8) | (bytes[1] & 0xFF); hiMant = ((unsigned long)(bytes[2] & 0xFF) << 24) | ((unsigned long)(bytes[3] & 0xFF) << 16) | ((unsigned long)(bytes[4] & 0xFF) << 8) | ((unsigned long)(bytes[5] & 0xFF)); loMant = ((unsigned long)(bytes[6] & 0xFF) << 24) | ((unsigned long)(bytes[7] & 0xFF) << 16) | ((unsigned long)(bytes[8] & 0xFF) << 8) | ((unsigned long)(bytes[9] & 0xFF)); if (expon == 0 && hiMant == 0 && loMant == 0) { f = 0; } else { if (expon == 0x7FFF) { /* Infinity or NaN */ f = HUGE_VAL; } else { expon -= 16383; f = ldexp(UnsignedToFloat(hiMant), expon-=31); f += ldexp(UnsignedToFloat(loMant), expon-=32); } } if (bytes[0] & 0x80) return -f; else return f; }
WXDLLIMPEXP_BASE wxFloat64 wxConvertFromIeeeExtended(const wxInt8 *bytes) { wxFloat64 f; wxInt32 expon; wxUint32 hiMant, loMant; expon = ((bytes[0] & 0x7F) << 8) | (bytes[1] & 0xFF); hiMant = ((wxUint32)(bytes[2] & 0xFF) << 24) | ((wxUint32)(bytes[3] & 0xFF) << 16) | ((wxUint32)(bytes[4] & 0xFF) << 8) | ((wxUint32)(bytes[5] & 0xFF)); loMant = ((wxUint32)(bytes[6] & 0xFF) << 24) | ((wxUint32)(bytes[7] & 0xFF) << 16) | ((wxUint32)(bytes[8] & 0xFF) << 8) | ((wxUint32)(bytes[9] & 0xFF)); if (expon == 0 && hiMant == 0 && loMant == 0) { f = 0; } else { if (expon == 0x7FFF) { /* Infinity or NaN */ f = HUGE_VAL; } else { expon -= 16383; f = ldexp(UnsignedToFloat(hiMant), expon-=31); f += ldexp(UnsignedToFloat(loMant), expon-=32); } } if (bytes[0] & 0x80) return -f; else return f; }