2using System.Reflection;
27 private double magnitude;
46 get => this.magnitude;
47 set => this.magnitude = value;
56 set => this.unit = value;
95 double Magnitude = this.magnitude * Q.magnitude;
96 if (ResidueExponential != 0)
97 Magnitude *= Math.Pow(10, ResidueExponential);
115 if (ResidueExponential != 0)
116 Magnitude *= Math.Pow(10, ResidueExponential);
131 if (
Unit.
TryConvert(Q.magnitude, Q.unit,
this.unit, out
double d))
155 if (this.unit.
Equals(E.unit,
true))
156 return this.magnitude == E.magnitude;
159 double m1 = this.magnitude;
162 double m2 = E.magnitude;
172 int Result = this.magnitude.GetHashCode();
195 if (DesiredType == typeof(
byte))
197 if (this.magnitude >=
byte.MinValue && this.magnitude <=
byte.MaxValue)
199 Value = (byte)this.magnitude;
203 else if (DesiredType == typeof(decimal))
205 Value = (decimal)this.magnitude;
208 else if (DesiredType == typeof(
double))
210 Value = (double)this.magnitude;
213 else if (DesiredType == typeof(
short))
215 if (this.magnitude >=
short.MinValue && this.magnitude <=
short.MaxValue)
217 Value = (short)this.magnitude;
221 else if (DesiredType == typeof(
int))
223 if (this.magnitude >=
int.MinValue && this.magnitude <=
int.MaxValue)
225 Value = (int)this.magnitude;
229 else if (DesiredType == typeof(
long))
231 if (this.magnitude >=
long.MinValue && this.magnitude <=
long.MaxValue)
233 Value = (long)this.magnitude;
237 else if (DesiredType == typeof(sbyte))
239 if (this.magnitude >= sbyte.MinValue &&
this.magnitude <= sbyte.MaxValue)
241 Value = (sbyte)this.magnitude;
245 else if (DesiredType == typeof(
float))
247 Value = (float)this.magnitude;
250 else if (DesiredType == typeof(ushort))
252 if (this.magnitude >= ushort.MinValue &&
this.magnitude <= ushort.MaxValue)
254 Value = (ushort)this.magnitude;
258 else if (DesiredType == typeof(uint))
260 if (this.magnitude >= uint.MinValue &&
this.magnitude <= uint.MaxValue)
262 Value = (uint)this.magnitude;
266 else if (DesiredType == typeof(ulong))
268 if (this.magnitude >= ulong.MinValue &&
this.magnitude <= ulong.MaxValue)
270 Value = (ulong)this.magnitude;
274 else if (DesiredType.GetTypeInfo().IsAssignableFrom(typeof(
PhysicalQuantity).GetTypeInfo()))
293 if (this.unit.
Equals(Q.unit,
true))
294 return this.magnitude.
CompareTo(Q.magnitude);
296 if (!
Unit.
TryConvert(Q.magnitude, Q.unit,
this.unit, out
double d))
299 return this.magnitude.CompareTo(d);
310 int i = s.Length - 1;
312 while (i >= 0 &&
char.IsWhiteSpace(s[i]))
317 while (i >= 0 && !
char.IsWhiteSpace(s[i]))
322 !
double.TryParse(s.Substring(0, i).Trim().Replace(System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator,
"."), out
double ParsedValue))
Base class for all types of elements.
abstract object AssociatedObjectValue
Associated object value.
Base class for all types of field elements.
Base class for script exceptions.
Class managing a script expression.
static bool TryConvert(object Value, Type DesiredType, out object Result)
Tries to convert an object Value to an object of type DesiredType .
static string ToString(double Value)
Converts a value to a string, that can be parsed as part of an expression.
Pseudo-field of physical quantities.
override IRingElement Invert()
Inverts the element, if possible.
PhysicalQuantity ToPhysicalQuantity()
Converts underlying object to a physical quantity.
override object AssociatedObjectValue
Associated object value.
override IAbelianGroupElement Zero
Returns the zero element of the group.
override int GetHashCode()
Calculates a hash code of the element. Hash code.
override IField AssociatedField
Associated Field.
static readonly PhysicalQuantity ZeroElement
0
override bool TryConvertTo(Type DesiredType, out object Value)
Converts the value to a .NET type.
override IAbelianGroupElement Add(IAbelianGroupElement Element)
Tries to add an element to the current element.
static bool TryParse(string s, out PhysicalQuantity Value)
Tries to parse a string to a physical quantity.
PhysicalQuantity(double Magnitude, Unit Unit)
Physical quantity.
double Magnitude
Magnitude
override IGroupElement Negate()
Negates the element.
override ICommutativeRingElement Multiply(ICommutativeRingElement Element)
Tries to multiply an element to the current element.
override ICommutativeRingWithIdentityElement One
Returns the identity element of the commutative ring with identity.
static readonly PhysicalQuantity OneElement
1
override bool Equals(object obj)
Compares the element to another. If elements are equal.
int CompareTo(object obj)
IComparable.CompareTo
override string ToString()
static bool TryConvert(double From, Unit FromUnit, Unit ToUnit, out double To)
Tries to convert a magnitude in one unit to a magnitude in another.
override string ToString()
bool IsEmpty
If the unit is empty. (A unit of only a prefix, but no factors, is not empty.)
Unit Invert(out int ResidueExponent)
Inverts the unit.
override bool Equals(object obj)
static readonly Unit Empty
Empty unit.
static Unit Multiply(Unit Left, Unit Right, out int ResidueExponent)
Multiplies two units with each other.
override int GetHashCode()
Unit ToReferenceUnits(ref double Magnitude)
Converts the unit to a series of reference unit factors. (Unrecognized units will be assumed to be re...
static bool TryParse(string UnitString, out Unit Unit)
Tries to parse a string into a unit.
Basic interface for all types of abelian group elements.
Basic interface for all types of commutative ring elements.
Basic interface for all types of commutative ring with identity elements.
Basic interface for all types of group elements.
Basic interface for all types of ring elements.
Basic interface for all types of fields.
Interface for objects that can be represented as a physical quantity.