Fix #118073: show exact integer representation in some cases in socket inspection

Without the extra precision, `fmt::format` rounds the resulting float to one with
fewer significant digits. This is generally nice, but not desired in this specific
case for consistency with the value stored in the socket.

Pull Request: https://projects.blender.org/blender/blender/pulls/118797
This commit is contained in:
Jacques Lucke 2024-02-27 20:38:41 +01:00
parent 64febcf155
commit f65e6da101
1 changed files with 10 additions and 1 deletions

View File

@ -1274,7 +1274,16 @@ static void create_inspection_string_for_generic_value(const bNodeSocket &socket
ss << fmt::format(TIP_("{} (Integer)"), *static_cast<int *>(socket_value));
}
else if (socket_type.is<float>()) {
ss << fmt::format(TIP_("{} (Float)"), *static_cast<float *>(socket_value));
const float float_value = *static_cast<float *>(socket_value);
/* Above that threshold floats can't represent fractions anymore. */
if (std::abs(float_value) > (1 << 24)) {
/* Use higher precision to display correct integer value instead of one that is rounded to
* fewer significant digits. */
ss << fmt::format(TIP_("{:.10} (Float)"), float_value);
}
else {
ss << fmt::format(TIP_("{} (Float)"), float_value);
}
}
else if (socket_type.is<blender::float3>()) {
const blender::float3 &vector = *static_cast<blender::float3 *>(socket_value);