std: Fix up non-zero FP value generation
This commit is contained in:
parent
0da8e0bd2b
commit
653d087e15
12
src/std.c
12
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)
|
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);
|
||||||
|
|
Loading…
Reference in New Issue