]> git.sesse.net Git - stockfish/commitdiff
Fix DIVIDE BY ZERO exception in init_search()
authorMarco Costalba <mcostalba@gmail.com>
Sat, 3 Jul 2010 15:02:07 +0000 (16:02 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 3 Jul 2010 15:12:20 +0000 (16:12 +0100)
It happens that when d == 0 we calculate:

log(double(0 * 0) / 2)

Unfortunately, log(0) is "illegal" and can generate either a
floating point exception or return a nonsense "huge" value
depending on the platform.

This fixs in the proper way the GCC/ICC rounding difference,
bug was from our side, not in the intel compiler.

Also fixed some few other warnings.

Bug spotted by Richard Lloyd.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/evaluate.cpp
src/material.cpp
src/pawns.cpp
src/search.cpp

index 7fd0db57dc668c37b330c77a51d4561957509f36..80bec8746f8bd8edd7bd6db869c9c5b31b439e90 100644 (file)
@@ -894,7 +894,7 @@ namespace {
             Square s = pop_1st_bit(&b);
             Square queeningSquare = relative_square(c, make_square(square_file(s), RANK_8));
             int d =  square_distance(s, queeningSquare)
             Square s = pop_1st_bit(&b);
             Square queeningSquare = relative_square(c, make_square(square_file(s), RANK_8));
             int d =  square_distance(s, queeningSquare)
-                   - (relative_rank(c, s) == RANK_2) // Double pawn push
+                   - int(relative_rank(c, s) == RANK_2) // Double pawn push
                    - square_distance(pos.king_square(opposite_color(c)), queeningSquare)
                    + int(c != pos.side_to_move());
 
                    - square_distance(pos.king_square(opposite_color(c)), queeningSquare)
                    + int(c != pos.side_to_move());
 
index a5f560baee15f29d1c250daaf18687a9ed173912..f2e501c1d862091545806cbc07b148e82e2754b5 100644 (file)
@@ -182,7 +182,7 @@ Phase MaterialInfoTable::game_phase(const Position& pos) {
 MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
 
   Key key = pos.get_material_key();
 MaterialInfo* MaterialInfoTable::get_material_info(const Position& pos) {
 
   Key key = pos.get_material_key();
-  int index = key & (size - 1);
+  unsigned index = unsigned(key & (size - 1));
   MaterialInfo* mi = entries + index;
 
   // If mi->key matches the position's material hash key, it means that we
   MaterialInfo* mi = entries + index;
 
   // If mi->key matches the position's material hash key, it means that we
index 8835d327e068b1e12215cfe754d3e17bcd641970..1cdeb461d51e2a2e74a56860f3d3e3c65998d70d 100644 (file)
@@ -148,7 +148,7 @@ PawnInfo* PawnInfoTable::get_pawn_info(const Position& pos) const {
   assert(pos.is_ok());
 
   Key key = pos.get_pawn_key();
   assert(pos.is_ok());
 
   Key key = pos.get_pawn_key();
-  int index = int(key & (size - 1));
+  unsigned index = unsigned(key & (size - 1));
   PawnInfo* pi = entries + index;
 
   // If pi->key matches the position's pawn hash key, it means that we
   PawnInfo* pi = entries + index;
 
   // If pi->key matches the position's pawn hash key, it means that we
index d6d459b0487c71491bd57716418b941382bd98ce..68a578cd741765042682dc86fa9da9abc9961309 100644 (file)
@@ -214,7 +214,7 @@ namespace {
   int32_t FutilityMarginsMatrix[16][64]; // [depth][moveNumber]
   int FutilityMoveCountArray[32]; // [depth]
 
   int32_t FutilityMarginsMatrix[16][64]; // [depth][moveNumber]
   int FutilityMoveCountArray[32]; // [depth]
 
-  inline Value futility_margin(Depth d, int mn) { return Value(d < 7 * OnePly ? FutilityMarginsMatrix[Max(d, 0)][Min(mn, 63)] : 2 * VALUE_INFINITE); }
+  inline Value futility_margin(Depth d, int mn) { return Value(d < 7 * OnePly ? FutilityMarginsMatrix[Max(d, 1)][Min(mn, 63)] : 2 * VALUE_INFINITE); }
   inline int futility_move_count(Depth d) { return d < 16 * OnePly ? FutilityMoveCountArray[d] : 512; }
 
   // Step 14. Reduced search
   inline int futility_move_count(Depth d) { return d < 16 * OnePly ? FutilityMoveCountArray[d] : 512; }
 
   // Step 14. Reduced search
@@ -353,8 +353,8 @@ void init_search() {
   }
 
   // Init futility margins array
   }
 
   // Init futility margins array
-  for (d = 0; d < 16; d++) for (mc = 0; mc < 64; mc++)
-      FutilityMarginsMatrix[d][mc] = 112 * int(log(double(d * d) / 2) / log(2.0) + 1.001) - 8 * mc + 45;
+  for (d = 1; d < 16; d++) for (mc = 0; mc < 64; mc++)
+      FutilityMarginsMatrix[d][mc] = 112 * int(log(double(d * d) / 2) / log(2.0) + 1) - 8 * mc + 45;
 
   // Init futility move count array
   for (d = 0; d < 32; d++)
 
   // Init futility move count array
   for (d = 0; d < 32; d++)