diff --git a/xFunc.Maths/Analyzers/Analyzer{TResult,TContext}.cs b/xFunc.Maths/Analyzers/Analyzer{TResult,TContext}.cs
index 9a19d642e..154023673 100644
--- a/xFunc.Maths/Analyzers/Analyzer{TResult,TContext}.cs
+++ b/xFunc.Maths/Analyzers/Analyzer{TResult,TContext}.cs
@@ -117,6 +117,10 @@ public virtual TResult Analyze(Power exp, TContext context)
public virtual TResult Analyze(Temperature exp, TContext context)
=> Analyze(exp as IExpression, context);
+ ///
+ public virtual TResult Analyze(Mass exp, TContext context)
+ => Analyze(exp as IExpression, context);
+
///
public virtual TResult Analyze(ToDegree exp, TContext context)
=> Analyze(exp as IExpression, context);
diff --git a/xFunc.Maths/Analyzers/Analyzer{TResult}.cs b/xFunc.Maths/Analyzers/Analyzer{TResult}.cs
index eb0e84a7b..e7db78fd6 100644
--- a/xFunc.Maths/Analyzers/Analyzer{TResult}.cs
+++ b/xFunc.Maths/Analyzers/Analyzer{TResult}.cs
@@ -116,6 +116,10 @@ public virtual TResult Analyze(Power exp)
public virtual TResult Analyze(Temperature exp)
=> Analyze(exp as IExpression);
+ ///
+ public virtual TResult Analyze(Mass exp)
+ => Analyze(exp as IExpression);
+
///
public virtual TResult Analyze(ToDegree exp)
=> Analyze(exp as IExpression);
diff --git a/xFunc.Maths/Analyzers/Differentiator.cs b/xFunc.Maths/Analyzers/Differentiator.cs
index 92fb3bca2..9a2e4e8a4 100644
--- a/xFunc.Maths/Analyzers/Differentiator.cs
+++ b/xFunc.Maths/Analyzers/Differentiator.cs
@@ -234,6 +234,14 @@ public override IExpression Analyze(Temperature exp, DifferentiatorContext conte
return Number.Zero;
}
+ ///
+ public override IExpression Analyze(Mass exp, DifferentiatorContext context)
+ {
+ ValidateArguments(exp, context);
+
+ return Number.Zero;
+ }
+
///
public override IExpression Analyze(Pow exp, DifferentiatorContext context)
{
diff --git a/xFunc.Maths/Analyzers/Formatters/CommonFormatter.cs b/xFunc.Maths/Analyzers/Formatters/CommonFormatter.cs
index d2c45fb94..7f830d159 100644
--- a/xFunc.Maths/Analyzers/Formatters/CommonFormatter.cs
+++ b/xFunc.Maths/Analyzers/Formatters/CommonFormatter.cs
@@ -161,6 +161,10 @@ public virtual string Analyze(Power exp)
public virtual string Analyze(Temperature exp)
=> exp.Value.ToString();
+ ///
+ public virtual string Analyze(Mass exp)
+ => exp.Value.ToString();
+
///
public virtual string Analyze(ToDegree exp)
=> ToString(exp, "todegree({0})");
diff --git a/xFunc.Maths/Analyzers/IAnalyzer{TResult,TContext}.cs b/xFunc.Maths/Analyzers/IAnalyzer{TResult,TContext}.cs
index 3679eb663..b6de4ce67 100644
--- a/xFunc.Maths/Analyzers/IAnalyzer{TResult,TContext}.cs
+++ b/xFunc.Maths/Analyzers/IAnalyzer{TResult,TContext}.cs
@@ -212,6 +212,14 @@ public interface IAnalyzer
/// The result of analysis.
TResult Analyze(Temperature exp, TContext context);
+ ///
+ /// Analyzes the specified expression.
+ ///
+ /// The expression.
+ /// The context.
+ /// The result of analysis.
+ TResult Analyze(Mass exp, TContext context);
+
///
/// Analyzes the specified expression.
///
diff --git a/xFunc.Maths/Analyzers/IAnalyzer{TResult}.cs b/xFunc.Maths/Analyzers/IAnalyzer{TResult}.cs
index e7bb120e0..053c3ce21 100644
--- a/xFunc.Maths/Analyzers/IAnalyzer{TResult}.cs
+++ b/xFunc.Maths/Analyzers/IAnalyzer{TResult}.cs
@@ -186,6 +186,13 @@ public interface IAnalyzer
/// The result of analysis.
TResult Analyze(Temperature exp);
+ ///
+ /// Analyzes the specified expression.
+ ///
+ /// The expression.
+ /// The result of analysis.
+ TResult Analyze(Mass exp);
+
///
/// Analyzes the specified expression.
///
diff --git a/xFunc.Maths/Analyzers/TypeAnalyzers/ResultTypes.cs b/xFunc.Maths/Analyzers/TypeAnalyzers/ResultTypes.cs
index 38b0cb6d7..93a565e45 100644
--- a/xFunc.Maths/Analyzers/TypeAnalyzers/ResultTypes.cs
+++ b/xFunc.Maths/Analyzers/TypeAnalyzers/ResultTypes.cs
@@ -71,6 +71,11 @@ public enum ResultTypes
///
TemperatureNumber = 1 << 10,
+ ///
+ /// The expression returns a mass number.
+ ///
+ MassNumber = 1 << 11,
+
///
/// The expression returns a number or a complex number.
///
@@ -96,7 +101,7 @@ public enum ResultTypes
///
/// The expression returns any type of number.
///
- Numbers = Number | AngleNumber | PowerNumber | TemperatureNumber,
+ Numbers = Number | AngleNumber | PowerNumber | TemperatureNumber | MassNumber,
///
/// The expression returns a number or a angle number or a complex number or a vector.
diff --git a/xFunc.Maths/Analyzers/TypeAnalyzers/TypeAnalyzer.cs b/xFunc.Maths/Analyzers/TypeAnalyzers/TypeAnalyzer.cs
index 93425bc67..f2c26e7a5 100644
--- a/xFunc.Maths/Analyzers/TypeAnalyzers/TypeAnalyzer.cs
+++ b/xFunc.Maths/Analyzers/TypeAnalyzers/TypeAnalyzer.cs
@@ -309,6 +309,7 @@ ResultTypes.Number or ResultTypes.ComplexNumber or ResultTypes.Vector
ResultTypes.AngleNumber => ResultTypes.AngleNumber,
ResultTypes.PowerNumber => ResultTypes.PowerNumber,
ResultTypes.TemperatureNumber => ResultTypes.TemperatureNumber,
+ ResultTypes.MassNumber => ResultTypes.MassNumber,
_ => ResultTypes.NumbersOrComplexOrVector.ThrowFor(result),
};
}
@@ -345,6 +346,11 @@ public virtual ResultTypes Analyze(Add exp)
(ResultTypes.TemperatureNumber, ResultTypes.TemperatureNumber)
=> ResultTypes.TemperatureNumber,
+ (ResultTypes.Number, ResultTypes.MassNumber) or
+ (ResultTypes.MassNumber, ResultTypes.Number) or
+ (ResultTypes.MassNumber, ResultTypes.MassNumber)
+ => ResultTypes.MassNumber,
+
(ResultTypes.Number, ResultTypes.ComplexNumber) or
(ResultTypes.ComplexNumber, ResultTypes.Number) or
(ResultTypes.ComplexNumber, ResultTypes.ComplexNumber)
@@ -388,6 +394,7 @@ public virtual ResultTypes Analyze(Ceil exp)
ResultTypes.AngleNumber => ResultTypes.AngleNumber,
ResultTypes.PowerNumber => ResultTypes.PowerNumber,
ResultTypes.TemperatureNumber => ResultTypes.TemperatureNumber,
+ ResultTypes.MassNumber => ResultTypes.MassNumber,
_ => ResultTypes.Numbers.ThrowFor(result),
};
}
@@ -444,6 +451,9 @@ public virtual ResultTypes Analyze(Div exp)
(ResultTypes.TemperatureNumber, ResultTypes.Number)
=> ResultTypes.TemperatureNumber,
+ (ResultTypes.MassNumber, ResultTypes.Number)
+ => ResultTypes.MassNumber,
+
(ResultTypes.Number, ResultTypes.ComplexNumber) or
(ResultTypes.ComplexNumber, ResultTypes.Number) or
(ResultTypes.ComplexNumber, ResultTypes.ComplexNumber)
@@ -504,6 +514,7 @@ public virtual ResultTypes Analyze(Floor exp)
ResultTypes.AngleNumber => ResultTypes.AngleNumber,
ResultTypes.PowerNumber => ResultTypes.PowerNumber,
ResultTypes.TemperatureNumber => ResultTypes.TemperatureNumber,
+ ResultTypes.MassNumber => ResultTypes.MassNumber,
_ => ResultTypes.NumberOrAngle.ThrowFor(result),
};
}
@@ -523,6 +534,7 @@ public virtual ResultTypes Analyze(Trunc exp)
ResultTypes.AngleNumber => ResultTypes.AngleNumber,
ResultTypes.PowerNumber => ResultTypes.PowerNumber,
ResultTypes.TemperatureNumber => ResultTypes.TemperatureNumber,
+ ResultTypes.MassNumber => ResultTypes.MassNumber,
_ => ResultTypes.NumberOrAngle.ThrowFor(result),
};
}
@@ -542,6 +554,7 @@ public virtual ResultTypes Analyze(Frac exp)
ResultTypes.AngleNumber => ResultTypes.AngleNumber,
ResultTypes.PowerNumber => ResultTypes.PowerNumber,
ResultTypes.TemperatureNumber => ResultTypes.TemperatureNumber,
+ ResultTypes.MassNumber => ResultTypes.MassNumber,
_ => ResultTypes.NumberOrAngle.ThrowFor(result),
};
}
@@ -710,6 +723,10 @@ public virtual ResultTypes Analyze(Mul exp)
(ResultTypes.TemperatureNumber, ResultTypes.Number)
=> ResultTypes.TemperatureNumber,
+ (ResultTypes.Number, ResultTypes.MassNumber) or
+ (ResultTypes.MassNumber, ResultTypes.Number)
+ => ResultTypes.MassNumber,
+
(ResultTypes.Number, ResultTypes.ComplexNumber) or
(ResultTypes.ComplexNumber, ResultTypes.Number) or
(ResultTypes.ComplexNumber, ResultTypes.ComplexNumber)
@@ -759,6 +776,10 @@ public virtual ResultTypes Analyze(Power exp)
public virtual ResultTypes Analyze(Temperature exp)
=> CheckArgument(exp, ResultTypes.TemperatureNumber);
+ ///
+ public virtual ResultTypes Analyze(Mass exp)
+ => CheckArgument(exp, ResultTypes.MassNumber);
+
///
public virtual ResultTypes Analyze(ToDegree exp)
=> AngleConversion(exp);
@@ -849,15 +870,30 @@ public virtual ResultTypes Analyze(Round exp)
if (exp is null)
ArgNull(ExceptionArgument.exp);
- var enumerator = exp.Arguments.GetEnumerator();
- for (var i = 0; enumerator.MoveNext(); i++)
+ var number = exp.Arguments[0].Analyze(this);
+ var digits = exp.Arguments[1]?.Analyze(this) ?? ResultTypes.None;
+
+ if (digits is ResultTypes.None or ResultTypes.Undefined or ResultTypes.Number)
{
- var item = enumerator.Current.Analyze(this);
- if (item != ResultTypes.Undefined && item != ResultTypes.Number)
- throw new DifferentParameterTypeMismatchException(ResultTypes.Number, item, i);
+ return number switch
+ {
+ ResultTypes.Undefined => ResultTypes.Undefined,
+ ResultTypes.Number => ResultTypes.Number,
+ ResultTypes.AngleNumber => ResultTypes.AngleNumber,
+ ResultTypes.PowerNumber => ResultTypes.PowerNumber,
+ ResultTypes.TemperatureNumber => ResultTypes.TemperatureNumber,
+ ResultTypes.MassNumber => ResultTypes.MassNumber,
+ _ => throw new DifferentParameterTypeMismatchException(
+ ResultTypes.Undefined | ResultTypes.Numbers,
+ number,
+ 0),
+ };
}
- return ResultTypes.Number;
+ throw new DifferentParameterTypeMismatchException(
+ ResultTypes.None | ResultTypes.Undefined | ResultTypes.Number,
+ digits,
+ 1);
}
///
@@ -900,6 +936,11 @@ public virtual ResultTypes Analyze(Sub exp)
(ResultTypes.TemperatureNumber, ResultTypes.TemperatureNumber)
=> ResultTypes.TemperatureNumber,
+ (ResultTypes.Number, ResultTypes.MassNumber) or
+ (ResultTypes.MassNumber, ResultTypes.Number) or
+ (ResultTypes.MassNumber, ResultTypes.MassNumber)
+ => ResultTypes.MassNumber,
+
(ResultTypes.Number, ResultTypes.ComplexNumber) or
(ResultTypes.ComplexNumber, ResultTypes.Number) or
(ResultTypes.ComplexNumber, ResultTypes.ComplexNumber)
@@ -939,6 +980,7 @@ public virtual ResultTypes Analyze(UnaryMinus exp)
ResultTypes.AngleNumber => ResultTypes.AngleNumber,
ResultTypes.PowerNumber => ResultTypes.PowerNumber,
ResultTypes.TemperatureNumber => ResultTypes.TemperatureNumber,
+ ResultTypes.MassNumber => ResultTypes.MassNumber,
ResultTypes.ComplexNumber => ResultTypes.ComplexNumber,
_ => ResultTypes.NumberOrComplex.ThrowFor(result),
};
@@ -971,10 +1013,12 @@ public virtual ResultTypes Analyze(Sign exp)
return result switch
{
ResultTypes.Undefined => ResultTypes.Undefined,
- ResultTypes.Number => ResultTypes.Number,
- ResultTypes.AngleNumber => ResultTypes.Number,
- ResultTypes.PowerNumber => ResultTypes.Number,
- ResultTypes.TemperatureNumber => ResultTypes.Number,
+ ResultTypes.Number or
+ ResultTypes.AngleNumber or
+ ResultTypes.PowerNumber or
+ ResultTypes.TemperatureNumber or
+ ResultTypes.MassNumber => ResultTypes.Number,
+
_ => ResultTypes.Numbers.ThrowFor(result),
};
}
@@ -1010,6 +1054,7 @@ ResultTypes.Undefined or
ResultTypes.AngleNumber => ResultTypes.AngleNumber,
ResultTypes.PowerNumber => ResultTypes.PowerNumber,
ResultTypes.TemperatureNumber => ResultTypes.TemperatureNumber,
+ ResultTypes.MassNumber => ResultTypes.MassNumber,
_ => ResultTypes.Numbers.ThrowFor(valueResult),
};
diff --git a/xFunc.Maths/Expressions/Abs.cs b/xFunc.Maths/Expressions/Abs.cs
index 9cbe86225..93a7ddff8 100644
--- a/xFunc.Maths/Expressions/Abs.cs
+++ b/xFunc.Maths/Expressions/Abs.cs
@@ -43,6 +43,7 @@ public override object Execute(ExpressionParameters? parameters)
AngleValue angle => AngleValue.Abs(angle),
PowerValue power => PowerValue.Abs(power),
TemperatureValue temperature => TemperatureValue.Abs(temperature),
+ MassValue mass => MassValue.Abs(mass),
Complex complex => Complex.Abs(complex),
Vector vector => vector.Abs(parameters),
_ => throw new ResultIsNotSupportedException(this, result),
diff --git a/xFunc.Maths/Expressions/Add.cs b/xFunc.Maths/Expressions/Add.cs
index 3b97e8f81..5a86539a2 100644
--- a/xFunc.Maths/Expressions/Add.cs
+++ b/xFunc.Maths/Expressions/Add.cs
@@ -55,6 +55,10 @@ public override object Execute(ExpressionParameters? parameters)
(TemperatureValue left, NumberValue right) => left + right,
(TemperatureValue left, TemperatureValue right) => left + right,
+ (NumberValue left, MassValue right) => left + right,
+ (MassValue left, NumberValue right) => left + right,
+ (MassValue left, MassValue right) => left + right,
+
(NumberValue left, Complex right) => left + right,
(Complex left, NumberValue right) => left + right,
(Complex left, Complex right) => left + right,
diff --git a/xFunc.Maths/Expressions/Ceil.cs b/xFunc.Maths/Expressions/Ceil.cs
index 2c5842af2..d86490e54 100644
--- a/xFunc.Maths/Expressions/Ceil.cs
+++ b/xFunc.Maths/Expressions/Ceil.cs
@@ -41,6 +41,7 @@ public override object Execute(ExpressionParameters? parameters)
AngleValue angle => AngleValue.Ceiling(angle),
PowerValue power => PowerValue.Ceiling(power),
TemperatureValue temperature => TemperatureValue.Ceiling(temperature),
+ MassValue mass => MassValue.Ceiling(mass),
_ => throw new ResultIsNotSupportedException(this, result),
};
}
diff --git a/xFunc.Maths/Expressions/Collections/ParameterValue.cs b/xFunc.Maths/Expressions/Collections/ParameterValue.cs
index 0ee1165b2..a0192f389 100644
--- a/xFunc.Maths/Expressions/Collections/ParameterValue.cs
+++ b/xFunc.Maths/Expressions/Collections/ParameterValue.cs
@@ -42,6 +42,12 @@ public ParameterValue(TemperatureValue value)
{
}
+ ///
+ public ParameterValue(MassValue value)
+ : this(value as object)
+ {
+ }
+
///
public ParameterValue(Complex value)
: this(value as object)
@@ -86,6 +92,7 @@ value is NumberValue
or AngleValue
or PowerValue
or TemperatureValue
+ or MassValue
or Complex
or bool
or Vector
@@ -120,6 +127,10 @@ public static implicit operator ParameterValue(PowerValue value)
public static implicit operator ParameterValue(TemperatureValue value)
=> new ParameterValue(value);
+ ///
+ public static implicit operator ParameterValue(MassValue value)
+ => new ParameterValue(value);
+
///
public static implicit operator ParameterValue(Complex value)
=> new ParameterValue(value);
diff --git a/xFunc.Maths/Expressions/Div.cs b/xFunc.Maths/Expressions/Div.cs
index cf6e48bb9..e906b8997 100644
--- a/xFunc.Maths/Expressions/Div.cs
+++ b/xFunc.Maths/Expressions/Div.cs
@@ -44,6 +44,7 @@ public override object Execute(ExpressionParameters? parameters)
(AngleValue left, NumberValue right) => left / right,
(PowerValue left, NumberValue right) => left / right,
(TemperatureValue left, NumberValue right) => left / right,
+ (MassValue left, NumberValue right) => left / right,
(NumberValue left, Complex right) => left / right,
(Complex left, NumberValue right) => left / right,
diff --git a/xFunc.Maths/Expressions/Floor.cs b/xFunc.Maths/Expressions/Floor.cs
index 144b80054..cb102de0b 100644
--- a/xFunc.Maths/Expressions/Floor.cs
+++ b/xFunc.Maths/Expressions/Floor.cs
@@ -41,6 +41,7 @@ public override object Execute(ExpressionParameters? parameters)
AngleValue angle => AngleValue.Floor(angle),
PowerValue power => PowerValue.Floor(power),
TemperatureValue temperature => TemperatureValue.Floor(temperature),
+ MassValue mass => MassValue.Floor(mass),
_ => throw new ResultIsNotSupportedException(this, result),
};
}
diff --git a/xFunc.Maths/Expressions/Frac.cs b/xFunc.Maths/Expressions/Frac.cs
index 6e8c6176a..e2dcc4e99 100644
--- a/xFunc.Maths/Expressions/Frac.cs
+++ b/xFunc.Maths/Expressions/Frac.cs
@@ -41,6 +41,7 @@ public override object Execute(ExpressionParameters? parameters)
AngleValue angle => AngleValue.Frac(angle),
PowerValue power => PowerValue.Frac(power),
TemperatureValue temperature => TemperatureValue.Frac(temperature),
+ MassValue mass => MassValue.Frac(mass),
_ => throw new ResultIsNotSupportedException(this, result),
};
}
diff --git a/xFunc.Maths/Expressions/Mul.cs b/xFunc.Maths/Expressions/Mul.cs
index d38f3471b..4085ae6b0 100644
--- a/xFunc.Maths/Expressions/Mul.cs
+++ b/xFunc.Maths/Expressions/Mul.cs
@@ -51,6 +51,9 @@ public override object Execute(ExpressionParameters? parameters)
(NumberValue left, TemperatureValue right) => left * right,
(TemperatureValue left, NumberValue right) => left * right,
+ (NumberValue left, MassValue right) => left * right,
+ (MassValue left, NumberValue right) => left * right,
+
(NumberValue left, Complex right) => left * right,
(Complex left, NumberValue right) => left * right,
(Complex left, Complex right) => left * right,
diff --git a/xFunc.Maths/Expressions/NumberValue.cs b/xFunc.Maths/Expressions/NumberValue.cs
index cd5cf7998..b7b58c425 100644
--- a/xFunc.Maths/Expressions/NumberValue.cs
+++ b/xFunc.Maths/Expressions/NumberValue.cs
@@ -1,6 +1,7 @@
// Copyright (c) Dmytro Kyshchenko. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -109,6 +110,7 @@ public override bool Equals(object? obj)
=> obj is NumberValue other && Equals(other);
///
+ [ExcludeFromCodeCoverage]
public override int GetHashCode()
=> HashCode.Combine(Number);
@@ -426,6 +428,26 @@ public override string ToString()
public static TemperatureValue operator +(NumberValue left, TemperatureValue right)
=> new TemperatureValue(left.Number + right.Value, right.Unit);
+ ///
+ /// Adds and .
+ ///
+ /// The first object to add.
+ /// The second object to add.
+ /// An object that is the sum of and .
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static MassValue operator +(MassValue left, NumberValue right)
+ => new MassValue(left.Value + right.Number, left.Unit);
+
+ ///
+ /// Adds and .
+ ///
+ /// The first object to add.
+ /// The second object to add.
+ /// An object that is the sum of and .
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static MassValue operator +(NumberValue left, MassValue right)
+ => new MassValue(left.Number + right.Value, right.Unit);
+
///
/// Adds and .
///
@@ -536,6 +558,26 @@ public override string ToString()
public static TemperatureValue operator -(TemperatureValue left, NumberValue right)
=> new TemperatureValue(left.Value - right.Number, left.Unit);
+ ///
+ /// Subtracts and .
+ ///
+ /// The first object to sub.
+ /// The second object to sub.
+ /// An object that is the difference of and .
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static MassValue operator -(NumberValue left, MassValue right)
+ => new MassValue(left.Number - right.Value, right.Unit);
+
+ ///
+ /// Subtracts and .
+ ///
+ /// The first object to sub.
+ /// The second object to sub.
+ /// An object that is the difference of and .
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static MassValue operator -(MassValue left, NumberValue right)
+ => new MassValue(left.Value - right.Number, left.Unit);
+
///
/// Subtracts and .
///
@@ -646,6 +688,26 @@ public override string ToString()
public static TemperatureValue operator *(NumberValue left, TemperatureValue right)
=> new TemperatureValue(left.Number * right.Value, right.Unit);
+ ///
+ /// Multiplies and .
+ ///
+ /// The first object to multiply.
+ /// The second object to multiply.
+ /// An object that is the product of and .
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static MassValue operator *(MassValue left, NumberValue right)
+ => new MassValue(left.Value * right.Number, left.Unit);
+
+ ///
+ /// Multiplies and .
+ ///
+ /// The first object to multiply.
+ /// The second object to multiply.
+ /// An object that is the product of and .
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static MassValue operator *(NumberValue left, MassValue right)
+ => new MassValue(left.Number * right.Value, right.Unit);
+
///
/// Multiplies and .
///
@@ -706,16 +768,6 @@ public override string ToString()
public static AngleValue operator /(AngleValue left, NumberValue right)
=> new AngleValue(left.Angle / right.Number, left.Unit);
- ///
- /// Divides by .
- ///
- /// The first object to divide.
- /// The second object to divide.
- /// An object that is the fraction of and .
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static AngleValue operator /(NumberValue left, AngleValue right)
- => new AngleValue(left.Number / right.Angle, right.Unit);
-
///
/// Divides by .
///
@@ -726,16 +778,6 @@ public override string ToString()
public static PowerValue operator /(PowerValue left, NumberValue right)
=> new PowerValue(left.Value / right.Number, left.Unit);
- ///
- /// Divides by .
- ///
- /// The first object to divide.
- /// The second object to divide.
- /// An object that is the fraction of and .
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static PowerValue operator /(NumberValue left, PowerValue right)
- => new PowerValue(left.Number / right.Value, right.Unit);
-
///
/// Divides by .
///
@@ -747,14 +789,14 @@ public override string ToString()
=> new TemperatureValue(left.Value / right.Number, left.Unit);
///
- /// Divides by .
+ /// Divides by .
///
/// The first object to divide.
/// The second object to divide.
/// An object that is the fraction of and .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static TemperatureValue operator /(NumberValue left, TemperatureValue right)
- => new TemperatureValue(left.Number / right.Value, right.Unit);
+ public static MassValue operator /(MassValue left, NumberValue right)
+ => new MassValue(left.Value / right.Number, left.Unit);
///
/// Divides by .
diff --git a/xFunc.Maths/Expressions/Round.cs b/xFunc.Maths/Expressions/Round.cs
index 91418d1ad..25bd16b71 100644
--- a/xFunc.Maths/Expressions/Round.cs
+++ b/xFunc.Maths/Expressions/Round.cs
@@ -49,6 +49,10 @@ public override object Execute(ExpressionParameters? parameters)
return (result, digits) switch
{
(NumberValue left, NumberValue right) => NumberValue.Round(left, right),
+ (AngleValue left, NumberValue right) => AngleValue.Round(left, right),
+ (PowerValue left, NumberValue right) => PowerValue.Round(left, right),
+ (TemperatureValue left, NumberValue right) => TemperatureValue.Round(left, right),
+ (MassValue left, NumberValue right) => MassValue.Round(left, right),
_ => throw new ResultIsNotSupportedException(this, result, digits),
};
}
diff --git a/xFunc.Maths/Expressions/Sign.cs b/xFunc.Maths/Expressions/Sign.cs
index 038dc51d2..11d2d20ff 100644
--- a/xFunc.Maths/Expressions/Sign.cs
+++ b/xFunc.Maths/Expressions/Sign.cs
@@ -42,6 +42,7 @@ public override object Execute(ExpressionParameters? parameters)
AngleValue angle => angle.Sign,
PowerValue power => power.Sign,
TemperatureValue temperature => temperature.Sign,
+ MassValue mass => mass.Sign,
_ => throw new ResultIsNotSupportedException(this, result),
};
diff --git a/xFunc.Maths/Expressions/Sub.cs b/xFunc.Maths/Expressions/Sub.cs
index 0acdceed3..6884fa9f3 100644
--- a/xFunc.Maths/Expressions/Sub.cs
+++ b/xFunc.Maths/Expressions/Sub.cs
@@ -53,6 +53,10 @@ public override object Execute(ExpressionParameters? parameters)
(TemperatureValue left, NumberValue right) => left - right,
(TemperatureValue left, TemperatureValue right) => left - right,
+ (NumberValue left, MassValue right) => left - right,
+ (MassValue left, NumberValue right) => left - right,
+ (MassValue left, MassValue right) => left - right,
+
(NumberValue left, Complex right) => left - right,
(Complex left, NumberValue right) => left - right,
(Complex left, Complex right) => left - right,
diff --git a/xFunc.Maths/Expressions/Trunc.cs b/xFunc.Maths/Expressions/Trunc.cs
index 051b2bfa4..1b676d920 100644
--- a/xFunc.Maths/Expressions/Trunc.cs
+++ b/xFunc.Maths/Expressions/Trunc.cs
@@ -41,6 +41,7 @@ public override object Execute(ExpressionParameters? parameters)
AngleValue angle => AngleValue.Truncate(angle),
PowerValue power => PowerValue.Truncate(power),
TemperatureValue temperature => TemperatureValue.Truncate(temperature),
+ MassValue mass => MassValue.Truncate(mass),
_ => throw new ResultIsNotSupportedException(this, result),
};
}
diff --git a/xFunc.Maths/Expressions/UnaryMinus.cs b/xFunc.Maths/Expressions/UnaryMinus.cs
index e407780f0..ec43ea747 100644
--- a/xFunc.Maths/Expressions/UnaryMinus.cs
+++ b/xFunc.Maths/Expressions/UnaryMinus.cs
@@ -30,6 +30,7 @@ public override object Execute(ExpressionParameters? parameters)
AngleValue angle => -angle,
PowerValue power => -power,
TemperatureValue temperature => -temperature,
+ MassValue mass => -mass,
Complex complex => Complex.Negate(complex),
_ => throw new ResultIsNotSupportedException(this, result),
};
diff --git a/xFunc.Maths/Expressions/Units/AngleUnits/AngleValue.cs b/xFunc.Maths/Expressions/Units/AngleUnits/AngleValue.cs
index d36a56d3f..5543c2349 100644
--- a/xFunc.Maths/Expressions/Units/AngleUnits/AngleValue.cs
+++ b/xFunc.Maths/Expressions/Units/AngleUnits/AngleValue.cs
@@ -198,32 +198,6 @@ public override int GetHashCode()
public static AngleValue operator -(AngleValue angleValue)
=> new AngleValue(-angleValue.Angle, angleValue.Unit);
- ///
- /// Multiplies two objects of .
- ///
- /// The first object to multiply.
- /// The second object to multiply.
- /// An object that is the product of and .
- public static AngleValue operator *(AngleValue left, AngleValue right)
- {
- (left, right) = ToCommonUnits(left, right);
-
- return new AngleValue(left.Angle * right.Angle, left.Unit);
- }
-
- ///
- /// Divides two objects of .
- ///
- /// The first object to divide.
- /// The second object to divide.
- /// An object that is the fraction of and .
- public static AngleValue operator /(AngleValue left, AngleValue right)
- {
- (left, right) = ToCommonUnits(left, right);
-
- return new AngleValue(left.Angle / right.Angle, left.Unit);
- }
-
private static (AngleValue Left, AngleValue Right) ToCommonUnits(AngleValue left, AngleValue right)
{
var commonUnit = GetCommonUnit(left.Unit, right.Unit);
@@ -253,7 +227,7 @@ private static AngleUnit GetCommonUnit(AngleUnit left, AngleUnit right)
AngleUnit.Degree => ToDegree(),
AngleUnit.Radian => ToRadian(),
AngleUnit.Gradian => ToGradian(),
- _ => throw new ArgumentOutOfRangeException(nameof(unit)),
+ _ => throw new ArgumentOutOfRangeException(nameof(unit), unit, null),
};
///
@@ -360,6 +334,16 @@ public static AngleValue Truncate(AngleValue angleValue)
public static AngleValue Frac(AngleValue angleValue)
=> new AngleValue(NumberValue.Frac(angleValue.Angle), angleValue.Unit);
+ ///
+ /// Rounds a double-precision floating-point value to a specified number of fractional digits,
+ /// and uses the specified rounding convention for midpoint values.
+ ///
+ /// The angle number.
+ /// The number of fractional digits in the return value.
+ /// The number nearest to that has a number of fractional digits equal to . If value has fewer fractional digits than , is returned unchanged.
+ public static AngleValue Round(AngleValue angleValue, NumberValue digits)
+ => new AngleValue(NumberValue.Round(angleValue.Angle, digits), angleValue.Unit);
+
///
/// The 'sin' function.
///
diff --git a/xFunc.Maths/Expressions/Units/Converters/Converter.cs b/xFunc.Maths/Expressions/Units/Converters/Converter.cs
index ff544c53a..0ab5f95d9 100644
--- a/xFunc.Maths/Expressions/Units/Converters/Converter.cs
+++ b/xFunc.Maths/Expressions/Units/Converters/Converter.cs
@@ -19,6 +19,7 @@ public Converter()
new AngleConverter(),
new PowerConverter(),
new TemperatureConverter(),
+ new MassConverter(),
};
///
diff --git a/xFunc.Maths/Expressions/Units/Converters/MassConverter.cs b/xFunc.Maths/Expressions/Units/Converters/MassConverter.cs
new file mode 100644
index 000000000..6c20428e4
--- /dev/null
+++ b/xFunc.Maths/Expressions/Units/Converters/MassConverter.cs
@@ -0,0 +1,52 @@
+// Copyright (c) Dmytro Kyshchenko. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+namespace xFunc.Maths.Expressions.Units.Converters;
+
+///
+/// The mass unit converter.
+///
+public class MassConverter : IConverter, IConverter