std: Fix up non-zero FP value generation

This commit is contained in:
Soeren Apel 2018-08-14 10:03:35 +02:00 committed by Uwe Hermann
parent 0da8e0bd2b
commit 653d087e15
1 changed files with 9 additions and 3 deletions

View File

@ -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) 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]; GVariant *gvar, *range[2];
GVariantBuilder gvb; GVariantBuilder gvb;
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY); g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
for (d = min; d <= max; d += step) { 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); gvar = g_variant_new_tuple(range, 2);
g_variant_builder_add_value(&gvb, gvar); g_variant_builder_add_value(&gvb, gvar);