added OrderDataHelper.PriceComparers for double and decimal
This commit is contained in:
1 parent
09f08f0a57
commit
f22e68f4bc
1 file changed
+23
@@ -304,6 +304,29 @@ namespace mbts.spark.utilities {
|
||||
|
||||
public static OneofDescriptor oneof_descriptor => _oneof_desc;
|
||||
|
||||
const double _price_error_margin = 0.0000001;
|
||||
const decimal _price_error_margin_decimal = 0.0000001m;
|
||||
|
||||
public static readonly IComparer<double> PriceComparer = Comparer<double>.Create((a, b) => {
|
||||
if (double.IsNaN(a)) {
|
||||
return double.IsNaN(b) ? 0 : -1;
|
||||
} else if (double.IsNaN(b)) {
|
||||
return 1;
|
||||
} else {
|
||||
double diff = a - b;
|
||||
if (diff <= _price_error_margin && diff >= -_price_error_margin)
|
||||
return 0;
|
||||
return diff > 0 ? 1 : -1;
|
||||
}
|
||||
});
|
||||
|
||||
public static readonly IComparer<decimal> PriceComparerDecimal = Comparer<decimal>.Create((a, b) => {
|
||||
decimal diff = a - b;
|
||||
if (diff <= _price_error_margin_decimal && diff >= -_price_error_margin_decimal)
|
||||
return 0;
|
||||
return diff > 0 ? 1 : -1;
|
||||
});
|
||||
|
||||
const string _primary_child_field = "child";
|
||||
// algo-type-case maps
|
||||
// Note: obv this will break if we change the name of the 'CustomOneofCase' field
|
||||
|
||||
Reference in new issue
Block a user