Innovenergy_trunk/csharp/Lib/Units/Generator/Operators.cs

51 lines
2.2 KiB
C#
Raw Normal View History

2023-05-24 10:04:01 +00:00
using System.Diagnostics.CodeAnalysis;
using InnovEnergy.Lib.Utils;
// ReSharper disable once CheckNamespace
namespace InnovEnergy.Lib.Units;
[SuppressMessage("ReSharper", "CompareOfFloatsByEqualityOperator")]
public readonly struct Operators
{
public static String Unit => throw new NotImplementedException();
public static String Symbol => throw new NotImplementedException();
#if !HAS_CONSTRUCTOR
public Operators(Double value) => Value = value;
#endif
public Double Value { get; }
public override String ToString() => Value.RoundToSignificantDigits(Units.DisplaySignificantDigits) + Unit;
// scalar multiplication
public static Operators operator *(Double scalar, Operators t) => new Operators(scalar * t.Value);
public static Operators operator *(Operators t, Double scalar) => new Operators(scalar * t.Value);
public static Operators operator /(Operators t, Double scalar) => new Operators(t.Value / scalar);
// addition
public static Operators operator +(Operators left, Operators right) => new Operators(left.Value + right.Value);
public static Operators operator -(Operators left, Operators right) => new Operators(left.Value - right.Value);
public static Operators operator -(Operators t) => new Operators(-t.Value);
// compare
public static Boolean operator ==(Operators left, Operators right) => left.Value == right.Value;
public static Boolean operator !=(Operators left, Operators right) => left.Value != right.Value;
public static Boolean operator > (Operators left, Operators right) => left.Value > right.Value;
public static Boolean operator < (Operators left, Operators right) => left.Value < right.Value;
public static Boolean operator >=(Operators left, Operators right) => left.Value >= right.Value;
public static Boolean operator <=(Operators left, Operators right) => left.Value <= right.Value;
// conversion
public static implicit operator Operators(Double d) => new Operators(d);
// equality
public Boolean Equals(Operators other) => Value == other.Value;
public override Boolean Equals(Object? obj) => obj is Operators other && Equals(other);
public override Int32 GetHashCode() => Value.GetHashCode();
}