- int sign;
- int expon;
- double fMant, fsMant;
- unsigned long hiMant, loMant;
-
- if (num < 0) {
- sign = 0x8000;
- num *= -1;
- } else {
- sign = 0;
- }
-
- if (num == 0) {
- expon = 0; hiMant = 0; loMant = 0;
- }
- else {
- fMant = frexp(num, &expon);
- if ((expon > 16384) || !(fMant < 1)) { /* Infinity or NaN */
- expon = sign|0x7FFF; hiMant = 0; loMant = 0; /* infinity */
- }
- else { /* Finite */
- expon += 16382;
- if (expon < 0) { /* denormalized */
- fMant = ldexp(fMant, expon);
- expon = 0;
- }
- expon |= sign;
- fMant = ldexp(fMant, 32);
- fsMant = floor(fMant);
- hiMant = FloatToUnsigned(fsMant);
- fMant = ldexp(fMant - fsMant, 32);
- fsMant = floor(fMant);
- loMant = FloatToUnsigned(fsMant);
- }
- }
-
- /* disable the warning about 'possible loss of data' */
- #ifdef _MSC_VER
- #pragma warning(disable: 4244)
- #endif /* Visual C++ */
-
- bytes[0] = (expon >> 8) & 0xff;
- bytes[1] = expon & 0xff;
- bytes[2] = (unsigned char) ((hiMant >> 24) & 0xff);
- bytes[3] = (unsigned char) ((hiMant >> 16) & 0xff);
- bytes[4] = (unsigned char) ((hiMant >> 8) & 0xff);
- bytes[5] = (unsigned char) (hiMant & 0xff);
- bytes[6] = (unsigned char) ((loMant >> 24) & 0xff);
- bytes[7] = (unsigned char) ((loMant >> 16) & 0xff);
- bytes[8] = (unsigned char) ((loMant >> 8) & 0xff);
- bytes[9] = (unsigned char) (loMant & 0xff;
-
- #ifdef _MSC_VER
- #pragma warning(default: 4244)
- #endif /* Visual C++ */
+ 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;