]> git.sesse.net Git - stockfish/commitdiff
Fix GrainSize rounding error
authorMarco Costalba <mcostalba@gmail.com>
Sat, 10 Aug 2013 15:11:13 +0000 (17:11 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 10 Aug 2013 15:11:13 +0000 (17:11 +0200)
The rounding formula is different between
positive and negative scores due to the
GrainSize/2 term that is asymmetric.

So use truncation instead of rounding. This
guarantees that evaluation is rounded to zero
in the same way for both positive and negative
scores.

Found with position's flip

bench: 4634244

src/evaluate.cpp

index 25ee79ead4df1ca94f1ddbe95d62a36b49496c84..147a1b3e90b5eb788fcbcdbb359f08792b91c293 100644 (file)
@@ -1083,7 +1083,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
 
     int ev = (eg_value(v) * int(sf)) / SCALE_FACTOR_NORMAL;
     int result = (mg_value(v) * int(ph) + ev * int(128 - ph)) / 128;
 
     int ev = (eg_value(v) * int(sf)) / SCALE_FACTOR_NORMAL;
     int result = (mg_value(v) * int(ph) + ev * int(128 - ph)) / 128;
-    return Value((result + GrainSize / 2) & ~(GrainSize - 1));
+    return Value((result / GrainSize) * GrainSize); // Sign independent
   }
 
   // apply_weight() weights score v by score w trying to prevent overflow
   }
 
   // apply_weight() weights score v by score w trying to prevent overflow