Innovenergy_trunk/csharp/lib/Units/Resistance.cs

35 lines
1.8 KiB
C#

namespace InnovEnergy.Units;
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;
// series
public static Resistance operator +(Resistance left, Resistance right) => new Resistance(left.Value + right.Value);
// parallel
public static Resistance operator |(Resistance left, Resistance right) => new Resistance(1m / (1m / left.Value + 1m / right.Value));
// scalar multiplication
public static Resistance operator *(Decimal scalar , Resistance resistance) => new Resistance(scalar * resistance.Value);
public static Resistance operator *(Resistance resistance, Decimal scalar ) => new Resistance(scalar * resistance.Value);
public static Resistance operator *(Int32 scalar , Resistance resistance) => new Resistance(scalar * resistance.Value);
public static Resistance operator *(Resistance resistance, Int32 scalar ) => new Resistance(scalar * resistance.Value);
public static Resistance operator /(Resistance resistance, Decimal scalar ) => new Resistance(resistance.Value / scalar);
public static Resistance operator /(Resistance resistance, Int32 scalar ) => new Resistance(resistance.Value / scalar);
// U=RI
public static Voltage operator *(Resistance resistance, Current current) => new Voltage(resistance.Value* current.Value);
// 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);
}