Skip to content

Commit

Permalink
#306 - Part of functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sys27 committed Oct 4, 2020
1 parent 4cf3d5f commit e0eec56
Show file tree
Hide file tree
Showing 14 changed files with 235 additions and 71 deletions.
3 changes: 1 addition & 2 deletions xFunc.Maths/Expressions/Abs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Collections.Immutable;
using System.Numerics;
using xFunc.Maths.Analyzers;
Expand Down Expand Up @@ -55,7 +54,7 @@ public override object Execute(ExpressionParameters? parameters)

return result switch
{
double number => Math.Abs(number),
NumberValue number => NumberValue.Abs(number),
AngleValue angle => AngleValue.Abs(angle),
Complex complex => Complex.Abs(complex),
Vector vector => vector.Abs(parameters),
Expand Down
10 changes: 5 additions & 5 deletions xFunc.Maths/Expressions/Add.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ public override object Execute(ExpressionParameters? parameters)

return (leftResult, rightResult) switch
{
(double left, double right) => left + right,
(NumberValue left, NumberValue right) => left + right,

(double left, AngleValue right) => left + right,
(AngleValue left, double right) => left + right,
(NumberValue left, AngleValue right) => left + right,
(AngleValue left, NumberValue right) => left + right,
(AngleValue left, AngleValue right) => left + right,

(double left, Complex right) => left + right,
(Complex left, double right) => left + right,
(NumberValue left, Complex right) => left + right,
(Complex left, NumberValue right) => left + right,
(Complex left, Complex right) => left + right,

(Vector left, Vector right) => left.Add(right, parameters),
Expand Down
3 changes: 1 addition & 2 deletions xFunc.Maths/Expressions/Ceil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using xFunc.Maths.Analyzers;
Expand Down Expand Up @@ -53,7 +52,7 @@ public override object Execute(ExpressionParameters? parameters)

return result switch
{
double number => Math.Ceiling(number),
NumberValue number => NumberValue.Ceiling(number),
AngleValue angle => AngleValue.Ceiling(angle),
_ => throw new ResultIsNotSupportedException(this, result),
};
Expand Down
10 changes: 5 additions & 5 deletions xFunc.Maths/Expressions/Div.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ public override object Execute(ExpressionParameters? parameters)

return (leftResult, rightResult) switch
{
(double left, double right) => left / right,
(NumberValue left, NumberValue right) => left / right,

(double left, AngleValue right) => left / right,
(AngleValue left, double right) => left / right,
(NumberValue left, AngleValue right) => left / right,
(AngleValue left, NumberValue right) => left / right,
(AngleValue left, AngleValue right) => left / right,

(double left, Complex right) => left / right,
(Complex left, double right) => left / right,
(NumberValue left, Complex right) => left / right,
(Complex left, NumberValue right) => left / right,
(Complex left, Complex right) => (object)(left / right),

_ => throw new ResultIsNotSupportedException(this, leftResult, rightResult),
Expand Down
5 changes: 2 additions & 3 deletions xFunc.Maths/Expressions/Exp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Collections.Immutable;
using System.Numerics;
using xFunc.Maths.Analyzers;
Expand Down Expand Up @@ -51,8 +50,8 @@ public override object Execute(ExpressionParameters? parameters)

return result switch
{
double number => Math.Exp(number),
Complex complex => (object)Complex.Exp(complex),
NumberValue number => NumberValue.Exp(number),
Complex complex => (object)Complex.Exp(complex), // TODO:
_ => throw new ResultIsNotSupportedException(this, result),
};
}
Expand Down
3 changes: 1 addition & 2 deletions xFunc.Maths/Expressions/Fact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using xFunc.Maths.Analyzers;
Expand Down Expand Up @@ -50,7 +49,7 @@ public override object Execute(ExpressionParameters? parameters)

return result switch
{
double number => MathExtensions.Fact(Math.Round(number)),
NumberValue number => NumberValue.Factorial(number),
_ => throw new ResultIsNotSupportedException(this, result),
};
}
Expand Down
2 changes: 1 addition & 1 deletion xFunc.Maths/Expressions/Floor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public override object Execute(ExpressionParameters? parameters)

return result switch
{
double number => Math.Floor(number),
NumberValue number => NumberValue.Floor(number),
AngleValue angle => AngleValue.Floor(angle),
_ => throw new ResultIsNotSupportedException(this, result),
};
Expand Down
2 changes: 1 addition & 1 deletion xFunc.Maths/Expressions/Frac.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public override object Execute(ExpressionParameters? parameters)

return result switch
{
double number => MathExtensions.Frac(number),
NumberValue number => NumberValue.Frac(number),
AngleValue angle => AngleValue.Frac(angle),
_ => throw new ResultIsNotSupportedException(this, result),
};
Expand Down
4 changes: 2 additions & 2 deletions xFunc.Maths/Expressions/GCD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ public GCD(IExpression first, IExpression second)
/// <inheritdoc />
public override object Execute(ExpressionParameters? parameters)
{
var gcd = 0.0;
var gcd = new NumberValue(0.0);
foreach (var argument in Arguments)
{
var result = argument.Execute(parameters);

gcd = result switch
{
double number => MathExtensions.GCD(gcd, number),
NumberValue number => NumberValue.GCD(gcd, number),
_ => throw new ResultIsNotSupportedException(this, result),
};
}
Expand Down
4 changes: 2 additions & 2 deletions xFunc.Maths/Expressions/LCM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ public LCM(IExpression first, IExpression second)
/// <inheritdoc />
public override object Execute(ExpressionParameters? parameters)
{
var lcm = 1.0;
var lcm = new NumberValue(1.0);
foreach (var argument in Arguments)
{
var result = argument.Execute(parameters);

lcm = result switch
{
double number => MathExtensions.LCM(lcm, number),
NumberValue number => NumberValue.LCM(lcm, number),
_ => throw new ResultIsNotSupportedException(this, result),
};
}
Expand Down
3 changes: 1 addition & 2 deletions xFunc.Maths/Expressions/Lb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Collections.Immutable;
using xFunc.Maths.Analyzers;

Expand Down Expand Up @@ -51,7 +50,7 @@ public override object Execute(ExpressionParameters? parameters)

return result switch
{
double number => Math.Log(number, 2),
NumberValue number => NumberValue.Lb(number),
_ => throw new ResultIsNotSupportedException(this, result),
};
}
Expand Down

0 comments on commit e0eec56

Please sign in to comment.