63 lines
2.1 KiB
C#
63 lines
2.1 KiB
C#
namespace InnovEnergy.Lib.Units;
|
|
|
|
using T = Resistance;
|
|
|
|
public readonly struct Resistance
|
|
{
|
|
public static String Unit => "Ω";
|
|
public static String Symbol => "R";
|
|
|
|
public Decimal Value { get; }
|
|
|
|
public Resistance(Decimal value) => Value = value;
|
|
|
|
public override String ToString() => Value + Unit;
|
|
|
|
// U=RI
|
|
public static Voltage operator *(Resistance resistance, Current current) => new Voltage(resistance.Value * current.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
|
|
|
|
} |