]> sigrok.org Git - libsigrok.git/commitdiff
std: Fix up non-zero FP value generation
authorSoeren Apel <redacted>
Tue, 14 Aug 2018 08:03:35 +0000 (10:03 +0200)
committerUwe Hermann <redacted>
Mon, 3 Sep 2018 23:31:56 +0000 (01:31 +0200)
src/std.c

index 522606f8fd48b737ea33861a3b8dd46e58f09b40..47c3e5344b7d462461dee1516aeefc80b2ab501a 100644 (file)
--- a/src/std.c
+++ b/src/std.c
@@ -712,15 +712,21 @@ SR_PRIV GVariant *std_gvar_min_max_step_array(const double a[3])
 
 SR_PRIV GVariant *std_gvar_min_max_step_thresholds(const double min, const double max, const double step)
 {
-       double d;
+       double d, v;
        GVariant *gvar, *range[2];
        GVariantBuilder gvb;
 
        g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
 
        for (d = min; d <= max; d += step) {
-               range[0] = g_variant_new_double(d);
-               range[1] = g_variant_new_double(d);
+               /*
+                * We will never see exactly 0.0 because of the error we're
+                * accumulating, so catch the "zero" value and force it to be 0.
+                */
+               v = ((d > (-step / 2)) && (d < (step / 2))) ? 0 : d;
+
+               range[0] = g_variant_new_double(v);
+               range[1] = g_variant_new_double(v);
 
                gvar = g_variant_new_tuple(range, 2);
                g_variant_builder_add_value(&gvb, gvar);