fix (vs): Use precison in terms of actual data for eq comp

Bugs (fixed):
  * The tick up/down buttons have no effect for vol input cells

  Cause: The cell vm ignores some value updates because the equality
  comparer incorrectly considers the new value equal to the current one
  (because it doesn't use enough decimal places in the comparison)
This commit is contained in:
John Colvin committed 2022-08-11 01:33:43 -04:00
1 parent 470ca0093e
commit 6ca2753951
2 files changed
+27 -3

No files matched your search

@@ -64,8 +64,21 @@
return tick_factors.tick(dbl, is_up ? tick_move : -tick_move);
};
public static IEqualityComparer<double> get_double_comparer(TickFactors tick_factors = null) =>
(tick_factors ?? new(10^7, 1)).tick_equality_comparer();
public static IEqualityComparer<double> get_double_comparer(
TickFactors tick_factors = null, double display_mult = double.NaN) {
if (tick_factors is null) {
return new TickFactors(10^7, 1).tick_equality_comparer();
}
// This equality comparer is used to compare actual values (not multiplied by
// 'display_mult'), while the TickFactors are used to format the display value (multiplied
// by 'display_mult'). Multiply the tick base by 'display_mult' so the equality comparison
// is done with the correct number of decimal places.
if (display_mult > 0 && Math.Log10(display_mult).is_int()) {
tick_factors = tick_factors.with(
tick_base: tick_factors.tick_base * display_mult);
}
return tick_factors.tick_equality_comparer();
}
public static VolSurfaceDisplayGridColumn get_double_output_col(
string group,
@@ -128,7 +141,9 @@
format: get_double_tostring(col_config.tick_factors, col_config.tick_display),
parse: get_parse_double(col_config.tick_factors, col_config.tick_display),
tick_move: get_double_tickmove(col_config.tick_factors, col_config.tick_move),
comparer: get_double_comparer(col_config.tick_factors).cast<double, object>());
comparer: get_double_comparer(
col_config.tick_factors, col_config.tick_display.display_multiplier)
.cast<double, object>());
}
}
}
@@ -43,6 +43,15 @@ namespace bts.utils {
public static T if_nan<T>(this T d, T if_nan) where T : IFloatingPoint<T> =>
d.is_nan() ? if_nan : d;
public static bool is_int<T>(this T value) where T : IFloatingPoint<T> =>
MathUtils.is_int(value);
public static bool is_int<T>(this T value, T epsilon) where T : IFloatingPoint<T> =>
MathUtils.is_int(value, epsilon);
public static bool is_int<T>(this T value, out T with_int_value) where T : IFloatingPoint<T> =>
MathUtils.is_int(value, out with_int_value);
public static T get_if<T>(this T i, Func<T> get, T comparand) where T : INumber<T> =>
i == comparand ? get() : i;