2023-03-01 07:14:08 +00:00
|
|
|
namespace InnovEnergy.Lib.Units;
|
|
|
|
|
|
|
|
using T = Percent;
|
|
|
|
|
|
|
|
public readonly struct Percent
|
|
|
|
{
|
|
|
|
public static String Unit => "%";
|
|
|
|
public static String Symbol => "%"; // ??
|
|
|
|
|
2023-03-01 07:25:23 +00:00
|
|
|
public Percent(Decimal value) => Value = value;
|
|
|
|
|
2023-03-01 07:14:08 +00:00
|
|
|
// not generated
|
2023-03-01 09:38:46 +00:00
|
|
|
// TODO: generate?
|
2023-03-01 07:14:08 +00:00
|
|
|
|
|
|
|
public Decimal Value { get; }
|
|
|
|
public override String ToString() => Value + Unit;
|
|
|
|
|
|
|
|
// scalar multiplication
|
2023-03-01 07:25:23 +00:00
|
|
|
public static Decimal operator *(Decimal scalar, T t) => scalar * t.Value / 100m;
|
|
|
|
public static Decimal operator *(T t, Decimal scalar) => scalar * t.Value / 100m;
|
2023-03-01 07:14:08 +00:00
|
|
|
|
|
|
|
// parallel
|
2023-03-01 07:25:23 +00:00
|
|
|
public static Percent operator |(T left, T right) => new T((left.Value + right.Value) / 2m);
|
2023-03-01 09:38:46 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
// 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();
|
2023-03-01 07:14:08 +00:00
|
|
|
}
|