2using System.Globalization;
3using System.Reflection;
28 private double magnitude;
47 get => this.magnitude;
48 set => this.magnitude = value;
57 set => this.unit = value;
96 double Magnitude = this.magnitude * Q.magnitude;
97 if (ResidueExponential != 0)
98 Magnitude *= Math.Pow(10, ResidueExponential);
116 if (ResidueExponential != 0)
117 Magnitude *= Math.Pow(10, ResidueExponential);
132 if (
Unit.
TryConvert(Q.magnitude, Q.unit,
this.unit, out
double d))
156 if (this.unit.
Equals(E.unit,
true))
157 return this.magnitude == E.magnitude;
160 double m1 = this.magnitude;
163 double m2 = E.magnitude;
173 int Result = this.magnitude.GetHashCode();
196 if (DesiredType == typeof(
byte))
198 if (this.magnitude >=
byte.MinValue && this.magnitude <=
byte.MaxValue)
200 Value = (byte)this.magnitude;
204 else if (DesiredType == typeof(decimal))
206 Value = (decimal)this.magnitude;
209 else if (DesiredType == typeof(
double))
211 Value = (double)this.magnitude;
214 else if (DesiredType == typeof(
short))
216 if (this.magnitude >=
short.MinValue && this.magnitude <=
short.MaxValue)
218 Value = (short)this.magnitude;
222 else if (DesiredType == typeof(
int))
224 if (this.magnitude >=
int.MinValue && this.magnitude <=
int.MaxValue)
226 Value = (int)this.magnitude;
230 else if (DesiredType == typeof(
long))
232 if (this.magnitude >=
long.MinValue && this.magnitude <=
long.MaxValue)
234 Value = (long)this.magnitude;
238 else if (DesiredType == typeof(sbyte))
240 if (this.magnitude >= sbyte.MinValue &&
this.magnitude <= sbyte.MaxValue)
242 Value = (sbyte)this.magnitude;
246 else if (DesiredType == typeof(
float))
248 Value = (float)this.magnitude;
251 else if (DesiredType == typeof(ushort))
253 if (this.magnitude >= ushort.MinValue &&
this.magnitude <= ushort.MaxValue)
255 Value = (ushort)this.magnitude;
259 else if (DesiredType == typeof(uint))
261 if (this.magnitude >= uint.MinValue &&
this.magnitude <= uint.MaxValue)
263 Value = (uint)this.magnitude;
267 else if (DesiredType == typeof(ulong))
269 if (this.magnitude >= ulong.MinValue &&
this.magnitude <= ulong.MaxValue)
271 Value = (ulong)this.magnitude;
275 else if (DesiredType.IsAssignableFrom(typeof(
PhysicalQuantity).GetTypeInfo()))
294 if (this.unit.
Equals(Q.unit,
true))
295 return this.magnitude.
CompareTo(Q.magnitude);
297 if (!
Unit.
TryConvert(Q.magnitude, Q.unit,
this.unit, out
double d))
300 return this.magnitude.CompareTo(d);
311 int i = s.Length - 1;
313 while (i >= 0 &&
char.IsWhiteSpace(s[i]))
318 while (i >= 0 && !
char.IsWhiteSpace(s[i]))
323 !
double.TryParse(s.Substring(0, i).Trim(), NumberStyles.None, CultureInfo.InvariantCulture, 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, bool AcceptInformationLoss, 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.