From: Daniel Mehrmann <mehrmann>
Date: Wed, 28 Apr 2004 21:43:39 +0000 (+0000)
Subject: Added u64 to double cast for all compiler
X-Git-Tag: v4.2.8~40
X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=8019632e111c32b9b4a3de999324c602f3d56821;p=xboard.git

Added u64 to double cast for all compiler
---

diff --git a/backend.c b/backend.c
index a23803c..673811c 100644
--- a/backend.c
+++ b/backend.c
@@ -212,10 +212,12 @@ void ParseFeatures P((char* args, ChessProgramState *cps));
 void InitBackEnd3 P((void));
 void FeatureDone P((ChessProgramState* cps, int val));
 void InitChessProgram P((ChessProgramState *cps));
+double u64ToDouble P((u64 value));
 
 #ifdef WIN32
 	extern void ConsoleCreate();
 #endif
+
 extern int tinyLayout, smallLayout;
 static ChessProgramStats programStats;
 
@@ -258,6 +260,26 @@ static ChessProgramStats programStats;
 #define TN_SGA  0003
 #define TN_PORT 23
 
+/* Some compiler can't cast u64 to double
+ * This function do the job for us:
+
+ * We use the highest bit for cast, this only
+ * works if the highest bit is not
+ * in use (This should not happen)
+ *
+ * We used this for all compiler
+ */
+double
+u64ToDouble(u64 value)
+{
+  double r;
+  u64 tmp = value & 0x7fffffffffffffff;
+  r = (double)(s64)tmp;
+  if (value & 0x8000000000000000)
+	r +=  9.2233720368547758080e18; /* 2^63 */
+ return r;
+}
+
 /* Fake up flags for now, as we aren't keeping track of castling
    availability yet */
 int
@@ -9251,8 +9273,8 @@ DisplayAnalysis()
     if (programStats.got_only_move) {
 	strcpy(buf, programStats.movelist);
     } else {
-	nps = (((u64)programStats.nodes) /
-	       (((double)programStats.time)/100.0));
+	nps = (u64ToDouble(programStats.nodes) /
+	      ((double)programStats.time /100.0));
 
 	cs = programStats.time % 100;
 	s = programStats.time / 100;
diff --git a/backend.h b/backend.h
index 2c63b76..244838d 100644
--- a/backend.h
+++ b/backend.h
@@ -174,22 +174,33 @@ extern GameInfo gameInfo;
 #define ICS_ICC 1
 #define ICS_FICS 2
 #define ICS_CHESSNET 3 /* not really supported */
-int ics_type;
-
-/* unsigned int 64 for engine nodes work and display */
-#ifdef WIN32
-	/* I don't know the name for this type of other compilers 
-	 * If it not work just added here 
-	 * Thats for MS Visual Studio 
-	 */
-	#define u64	unsigned __int64
-	#define u64Display  "%I64u"
-#else
-	/* GNU gcc */
-	#define u64	unsigned long long
-	#define u64Display  "%llu"
-#endif
-
+int ics_type;
+
+/* unsigned int 64 for engine nodes work and display */
+#ifdef WIN32
+	/* I don't know the name for this type of other compiler
+	 * If it not work, just modify here
+	 * This is for MS Visual Studio
+	 */
+	#ifdef _MSC_VER
+		#define u64	unsigned __int64
+		#define s64 signed __int64
+		#define u64Display  "%I64u"
+	#else
+		/* place holder
+		 * or dummy types for other compiler
+		 */
+		#define u64	unsigned __int64
+		#define s64 signed __int64
+		#define u64Display  "%I64u"
+	#endif
+#else
+	/* GNU gcc */
+	#define u64	unsigned long long
+	#define s64 signed long long
+	#define u64Display  "%llu"
+#endif
+
 
 /* pgntags.c prototypes
  */