X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Ftypes.h;h=2d7696307060002af557620d27c18b8087181cbd;hp=c7ac4c643f4d1d4a559b6b21a6e7b06b3d9795a3;hb=58fdb84b0df76a951da40dc10a6db018ed0927fb;hpb=ab276357d7dea388a81ea75f9b7d89670cf4fcf0 diff --git a/src/types.h b/src/types.h index c7ac4c64..2d769630 100644 --- a/src/types.h +++ b/src/types.h @@ -273,11 +273,15 @@ inline Score make_score(int mg, int eg) { /// according to the standard a simple cast to short is implementation defined /// and so is a right shift of a signed integer. inline Value mg_value(Score s) { - return Value(((s + 0x8000) & ~0xFFFF) / 0x10000); + + union { uint16_t u; int16_t s; } mg = { uint16_t(unsigned(s + 0x8000) >> 16) }; + return Value(mg.s); } inline Value eg_value(Score s) { - return Value((int)(unsigned(s) & 0x7FFFU) - (int)(unsigned(s) & 0x8000U)); + + union { uint16_t u; int16_t s; } eg = { uint16_t(unsigned(s)) }; + return Value(eg.s); } #define ENABLE_BASE_OPERATORS_ON(T) \