X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/777553d227ce02078f6509a785e84715fbddc7d6..88594d02eb59a55ac85d3210a49d02918124617b:/src/common/extended.c

diff --git a/src/common/extended.c b/src/common/extended.c
index 1dae07e953..cf9f95fd2f 100644
--- a/src/common/extended.c
+++ b/src/common/extended.c
@@ -1,10 +1,11 @@
 #include "wx/setup.h"
+
 #include <math.h>
 
 #if wxUSE_APPLE_IEEE
 
 /*
- * C O N V E R T   T O	 I E E E   E X T E N D E D
+ * C O N V E R T   T O     I E E E   E X T E N D E D
  */
 
 /* Copyright (C) 1988-1991 Apple Computer, Inc.
@@ -13,7 +14,7 @@
  * Machine-independent I/O routines for IEEE floating-point numbers.
  *
  * NaN's and infinities are converted to HUGE_VAL or HUGE, which
- * happens to be infinity on IEEE machines.	 Unfortunately, it is
+ * happens to be infinity on IEEE machines.     Unfortunately, it is
  * impossible to preserve NaN's in a machine-independent way.
  * Infinities are, however, preserved on IEEE machines.
  *
@@ -46,65 +47,68 @@
 
 void ConvertToIeeeExtended(double num, unsigned char *bytes)
 {
-	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;
-	bytes[1] = expon;
-	bytes[2] = (unsigned char) hiMant >> 24;
-	bytes[3] = (unsigned char) hiMant >> 16;
-	bytes[4] = (unsigned char) hiMant >> 8;
-	bytes[5] = (unsigned char) hiMant;
-	bytes[6] = (unsigned char) loMant >> 24;
-	bytes[7] = (unsigned char) loMant >> 16;
-	bytes[8] = (unsigned char) loMant >> 8;
-	bytes[9] = (unsigned char) loMant;
-
-    #ifdef _MSC_VER
-        #pragma warning(default: 4244)
-    #endif /* Visual C++ */
+    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' & 'conversion between
+     * diff types' */
+#ifdef _MSC_VER
+#pragma warning(disable: 4244)
+#pragma warning(disable: 4135)
+#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)
+#pragma warning(default: 4135)
+#endif /* Visual C++ */
 }
 
 /*
- * C O N V E R T   F R O M	 I E E E   E X T E N D E D
+ * C O N V E R T   F R O M     I E E E   E X T E N D E D
  */
 
 /*
@@ -114,16 +118,16 @@ void ConvertToIeeeExtended(double num, unsigned char *bytes)
  * Machine-independent I/O routines for IEEE floating-point numbers.
  *
  * NaN's and infinities are converted to HUGE_VAL or HUGE, which
- * happens to be infinity on IEEE machines.	 Unfortunately, it is
+ * happens to be infinity on IEEE machines.     Unfortunately, it is
  * impossible to preserve NaN's in a machine-independent way.
  * Infinities are, however, preserved on IEEE machines.
  *
  * These routines have been tested on the following machines:
- *	  Apple Macintosh, MPW 3.1 C compiler
- *	  Apple Macintosh, THINK C compiler
- *	  Silicon Graphics IRIS, MIPS compiler
- *	  Cray X/MP and Y/MP
- *	  Digital Equipment VAX
+ *      Apple Macintosh, MPW 3.1 C compiler
+ *      Apple Macintosh, THINK C compiler
+ *      Silicon Graphics IRIS, MIPS compiler
+ *      Cray X/MP and Y/MP
+ *      Digital Equipment VAX
  *
  *
  * Implemented by Malcolm Slaney and Ken Turkowski.
@@ -151,38 +155,38 @@ void ConvertToIeeeExtended(double num, unsigned char *bytes)
 
 double ConvertFromIeeeExtended(const unsigned char *bytes)
 {
-	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;
+    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;
 }
 
 #endif /* wxUSE_APPLE_IEEE */