From: Soeren Apel Date: Tue, 14 Aug 2018 08:03:35 +0000 (+0200) Subject: std: Fix up non-zero FP value generation X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=653d087e15293c562409ef29ae231f8b16de39ea;p=libsigrok.git std: Fix up non-zero FP value generation --- diff --git a/src/std.c b/src/std.c index 522606f8..47c3e534 100644 --- 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);