/// <summary>Returns the result of division of double and object.</summary> public static T operator /(double lhs, DoubleArithmetic <T> rhs) { if (rhs == null && DoubleUtil.Equal(lhs, 0.0)) { return(null); } else if (rhs == null) { throw new Exception("Cannot accept null argument as it contains no information to create the result."); } return(rhs.Apply(lhs, (x, y) => x / y)); }
/// <summary>Returns the result of subtraction of object and double.</summary> public static T operator -(DoubleArithmetic <T> lhs, double rhs) { if (lhs == null && DoubleUtil.Equal(rhs, 0.0)) { return((T)lhs); } else if (lhs == null) { throw new Exception("Cannot accept null argument as it contains no information to create the result."); } return(lhs.Subtract(rhs)); }
/// <summary>Returns the result of division of object and double.</summary> public static T operator /(DoubleArithmetic <T> lhs, double rhs) { if (DoubleUtil.Equal(rhs, 0.0)) { throw new Exception("Division of array by zero."); } else if (lhs == null) { return(null); } return(lhs.DivideBy(rhs)); }
/// <summary>Variants are equal when both types and values are equal. /// Comparison of doubles is performed with roundoff tolerance.</summary> public bool Equals(Variant other) { // The purpose of this check is to ensure that variant holds only one of the supported types switch (value_) { case null: return(other.value_ == null); case string stringValue: return(other.value_ is string && stringValue == (string)other.value_); case double doubleValue: // Perform comparison of doubles by function that uses numerical tolerance return(other.value_ is double && DoubleUtil.Equal(doubleValue, (double)other.value_)); case bool boolValue: return(other.value_ is bool && boolValue == (bool)other.value_); case int intValue: return(other.value_ is int && intValue == (int)other.value_); case long longValue: return(other.value_ is long && longValue == (long)other.value_); case LocalDate dateValue: return(other.value_ is LocalDate && dateValue == (LocalDate)other.value_); case LocalTime timeValue: return(other.value_ is LocalTime && timeValue == (LocalTime)other.value_); case LocalMinute minuteValue: return(other.value_ is LocalMinute && minuteValue == (LocalMinute)other.value_); case LocalDateTime dateTimeValue: return(other.value_ is LocalDateTime && dateTimeValue == (LocalDateTime)other.value_); case Instant instantValue: return(other.value_ is Instant && instantValue == (Instant)other.value_); case Enum enumValue: // Use Equals(other) to avoid unintended reference comparison return(other.value_ is Enum && enumValue.Equals(other.value_)); default: // Error message if any other type, should normally not get here throw new Exception(GetWrongTypeErrorMessage(value_)); } }