From 1d4e7bbdf5a8b2e87daaa54eea52cbe01d699fdb Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sat, 3 Jul 2010 16:02:07 +0100 Subject: [PATCH] Fix DIVIDE BY ZERO exception in init_search() 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 --- src/evaluate.cpp | 2 +- src/material.cpp | 2 +- src/pawns.cpp | 2 +- src/search.cpp | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 7fd0db57..80bec874 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -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) - - (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()); diff --git a/src/material.cpp b/src/material.cpp index a5f560ba..f2e501c1 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -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(); - 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 diff --git a/src/pawns.cpp b/src/pawns.cpp index 8835d327..1cdeb461 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -148,7 +148,7 @@ PawnInfo* PawnInfoTable::get_pawn_info(const Position& pos) const { 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 diff --git a/src/search.cpp b/src/search.cpp index d6d459b0..68a578cd 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -214,7 +214,7 @@ namespace { 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 @@ -353,8 +353,8 @@ void init_search() { } // 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++) -- 2.39.2