2using System.Reflection;
28 private double magnitude;
42 this.error = Math.Abs(
Error);
50 get => this.magnitude;
51 set => this.magnitude = value;
60 set => this.unit = value;
69 set => this.error = value;
96 StringBuilder sb =
new StringBuilder();
117 return sb.ToString();
140 double Magnitude = this.magnitude * E.magnitude;
141 if (ResidueExponential != 0)
142 Magnitude *= Math.Pow(10, ResidueExponential);
144 double Error1 = this.error / this.magnitude;
145 double Error2 = E.error / E.magnitude;
151 return new Measurement(this.magnitude * d, this.unit, this.error * d);
164 if (ResidueExponential != 0)
165 Magnitude *= Math.Pow(10, ResidueExponential);
181 if (!
Unit.
TryConvert(E.magnitude, E.unit,
this.unit, out
double d))
192 return new Measurement(this.magnitude + d, this.unit, this.error);
203 return new Measurement(-this.magnitude, this.unit, this.error);
212 if (this.unit.
Equals(E.unit,
true))
213 return this.magnitude == E.magnitude && this.error == E.error;
216 double m1 = this.magnitude;
219 double m2 = E.magnitude;
238 int Result = this.magnitude.GetHashCode();
240 Result ^= Result << 5 ^ this.error.GetHashCode();
262 if (DesiredType == typeof(
byte))
264 if (this.magnitude >=
byte.MinValue && this.magnitude <=
byte.MaxValue)
266 Value = (byte)this.magnitude;
270 else if (DesiredType == typeof(decimal))
272 Value = (decimal)this.magnitude;
275 else if (DesiredType == typeof(
double))
277 Value = (double)this.magnitude;
280 else if (DesiredType == typeof(
short))
282 if (this.magnitude >=
short.MinValue && this.magnitude <=
short.MaxValue)
284 Value = (short)this.magnitude;
288 else if (DesiredType == typeof(
int))
290 if (this.magnitude >=
int.MinValue && this.magnitude <=
int.MaxValue)
292 Value = (int)this.magnitude;
296 else if (DesiredType == typeof(
long))
298 if (this.magnitude >=
long.MinValue && this.magnitude <=
long.MaxValue)
300 Value = (long)this.magnitude;
304 else if (DesiredType == typeof(sbyte))
306 if (this.magnitude >= sbyte.MinValue &&
this.magnitude <= sbyte.MaxValue)
308 Value = (sbyte)this.magnitude;
312 else if (DesiredType == typeof(
float))
314 Value = (float)this.magnitude;
317 else if (DesiredType == typeof(ushort))
319 if (this.magnitude >= ushort.MinValue &&
this.magnitude <= ushort.MaxValue)
321 Value = (ushort)this.magnitude;
325 else if (DesiredType == typeof(uint))
327 if (this.magnitude >= uint.MinValue &&
this.magnitude <= uint.MaxValue)
329 Value = (uint)this.magnitude;
333 else if (DesiredType == typeof(ulong))
335 if (this.magnitude >= ulong.MinValue &&
this.magnitude <= ulong.MaxValue)
337 Value = (ulong)this.magnitude;
341 else if (DesiredType.GetTypeInfo().IsAssignableFrom(typeof(
Measurement).GetTypeInfo()))
360 if (this.unit.
Equals(Q.unit,
true))
362 i = this.magnitude.CompareTo(Q.magnitude);
366 return this.error.CompareTo(Q.error);
369 if (!
Unit.
TryConvert(Q.magnitude, Q.unit,
this.unit, out
double d))
372 i = this.magnitude.CompareTo(d);
379 return this.error.CompareTo(d);
390 int i = s.IndexOf(
'±');
396 string s1 = s.Substring(0, i).Trim();
397 string s2 = s.Substring(i + 1).Trim();
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 TryParse(string s, out double Value)
Tries to parse a double-precision floating-point value.
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.
static readonly Measurement ZeroElement
Zero element (0)
override IAbelianGroupElement Add(IAbelianGroupElement Element)
Tries to add an element to the current element.
override bool Equals(object obj)
Compares the element to another. If elements are equal.
PhysicalQuantity Min
Estimate of measurement
int CompareTo(object obj)
IComparable.CompareTo
override bool TryConvertTo(Type DesiredType, out object Value)
Converts the value to a .NET type.
override int GetHashCode()
Calculates a hash code of the element. Hash code.
override ICommutativeRingWithIdentityElement One
Returns the identity element of the commutative ring with identity.
override IAbelianGroupElement Zero
Returns the zero element of the group.
double Magnitude
Magnitude
override IField AssociatedField
Associated Field.
override object AssociatedObjectValue
Associated object value.
override ICommutativeRingElement Multiply(ICommutativeRingElement Element)
Tries to multiply an element to the current element.
override IGroupElement Negate()
Negates the element.
PhysicalQuantity Max
Estimate of measurement
Measurement(double Magnitude, Unit Unit, double Error)
Physical quantity.
static readonly Measurement OneElement
Unit element (1)
PhysicalQuantity ToPhysicalQuantity()
Converts underlying object to a physical quantity.
static bool TryParse(string s, out Measurement Value)
Tries to parse a string to a physical quantity.
override string ToString()
override IRingElement Invert()
Inverts the element, if possible.
PhysicalQuantity Estimate
Estimate of measurement
Pseudo-field of physical measurements.
static bool TryParse(string s, out PhysicalQuantity Value)
Tries to parse a string to a physical quantity.
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...
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.