From a54995eace16956868e1fdea29799a3703bf5150 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 5 Aug 2015 17:11:20 -0600 Subject: [PATCH 1/2] RoundScalar() fallback use powf(10.f, -x) instead of 1.0f/powf(10.0f,x) --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 011c5f1b..b578f8a4 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6000,7 +6000,7 @@ static inline float RoundScalar(float value, int decimal_precision) // So when our value is 1.99999 with a precision of 0.001 we'll end up rounding to 2.0 // FIXME: Investigate better rounding methods static const float min_steps[10] = { 1.0f, 0.1f, 0.01f, 0.001f, 0.0001f, 0.00001f, 0.000001f, 0.0000001f, 0.00000001f, 0.000000001f }; - float min_step = (decimal_precision >= 0 && decimal_precision < 10) ? min_steps[decimal_precision] : (1.0f / powf(10.0f, (float)decimal_precision)); + float min_step = (decimal_precision >= 0 && decimal_precision < 10) ? min_steps[decimal_precision] : powf(10.0f, (float)-decimal_precision); bool negative = value < 0.0f; value = fabsf(value); float remainder = fmodf(value, min_step); From 4b4f6d78ee2f79c11d1b68bc387898922ff0c179 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 5 Aug 2015 17:26:04 -0600 Subject: [PATCH 2/2] InputFloat() fixed 0 decimal_precision --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index b578f8a4..1e572123 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -7735,7 +7735,7 @@ static bool InputScalarEx(const char* label, ImGuiDataType data_type, void* data bool ImGui::InputFloat(const char* label, float* v, float step, float step_fast, int decimal_precision, ImGuiInputTextFlags extra_flags) { char display_format[16]; - if (decimal_precision) + if (decimal_precision < 0) strcpy(display_format, "%f"); // Ideally we'd have a minimum decimal precision of 1 to visually denote that this is a float, while hiding non-significant digits? %f doesn't have a minimum of 1 else ImFormatString(display_format, 16, "%%%df", decimal_precision);