namespace InnovEnergy.Lib.Units; using T = Power; public readonly struct Power { public static String Unit => "W"; public static String Symbol => "P"; public Decimal Value { get; } public Power(Decimal value) => Value = value; public override String ToString() => Value + Unit; // P=UI public static Voltage operator /(Power power, Current current) => new Voltage(power.Value / current.Value); public static Current operator /(Power power, Voltage voltage) => new Current(power.Value / voltage.Value); #region scalar multiplication public static T operator *(Decimal scalar, T t) => new T(scalar * t.Value); public static T operator *(T t, Decimal scalar) => new T(scalar * t.Value); public static T operator /(T t, Decimal scalar) => new T(t.Value / scalar); #endregion #region addition public static T operator +(T left, T right) => new T(left.Value + right.Value); public static T operator -(T left, T right) => new T(left.Value - right.Value); public static T operator -(T t) => new T(-t.Value); #endregion #region compare public static Boolean operator ==(T left, T right) => left.Value == right.Value; public static Boolean operator !=(T left, T right) => left.Value != right.Value; public static Boolean operator > (T left, T right) => left.Value > right.Value; public static Boolean operator < (T left, T right) => left.Value < right.Value; public static Boolean operator >=(T left, T right) => left.Value >= right.Value; public static Boolean operator <=(T left, T right) => left.Value <= right.Value; #endregion #region conversion public static implicit operator T(Decimal d) => new T(d); public static implicit operator T(Double d) => new T((Decimal)d); public static implicit operator T(Int32 i) => new T(i); public static implicit operator Decimal(T t) => t.Value; #endregion #region equality public Boolean Equals(T other) => Value == other.Value; public override Boolean Equals(Object? obj) => obj is T other && Equals(other); public override Int32 GetHashCode() => Value.GetHashCode(); #endregion }