From cb7232a818d9994a5d122cf5e1af0d4915e265c0 Mon Sep 17 00:00:00 2001 From: Sebastian Buchwald Date: Sun, 24 Aug 2025 19:48:24 +0200 Subject: [PATCH] Use integer type for UCI spin values In particular, parse spin values as integers to avoid rounding errors. Fixes https://github.com/official-stockfish/Stockfish/issues/6263 closes https://github.com/official-stockfish/Stockfish/pull/6264 No functional change --- src/ucioption.cpp | 6 +++--- src/ucioption.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ucioption.cpp b/src/ucioption.cpp index a76bd3ace..ff6235695 100644 --- a/src/ucioption.cpp +++ b/src/ucioption.cpp @@ -110,7 +110,7 @@ Option::Option(OnChange f) : max(0), on_change(std::move(f)) {} -Option::Option(double v, int minv, int maxv, OnChange f) : +Option::Option(int v, int minv, int maxv, OnChange f) : type("spin"), min(minv), max(maxv), @@ -154,7 +154,7 @@ Option& Option::operator=(const std::string& v) { if ((type != "button" && type != "string" && v.empty()) || (type == "check" && v != "true" && v != "false") - || (type == "spin" && (std::stof(v) < min || std::stof(v) > max))) + || (type == "spin" && (std::stoi(v) < min || std::stoi(v) > max))) return *this; if (type == "combo") @@ -202,7 +202,7 @@ std::ostream& operator<<(std::ostream& os, const OptionsMap& om) { } else if (o.type == "spin") - os << " default " << int(stof(o.defaultValue)) << " min " << o.min << " max " + os << " default " << stoi(o.defaultValue) << " min " << o.min << " max " << o.max; break; diff --git a/src/ucioption.h b/src/ucioption.h index 3d7386c30..0c957fda1 100644 --- a/src/ucioption.h +++ b/src/ucioption.h @@ -43,7 +43,7 @@ class Option { Option(OnChange = nullptr); Option(bool v, OnChange = nullptr); Option(const char* v, OnChange = nullptr); - Option(double v, int minv, int maxv, OnChange = nullptr); + Option(int v, int minv, int maxv, OnChange = nullptr); Option(const char* v, const char* cur, OnChange = nullptr); Option& operator=(const std::string&);