-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
977 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// 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.Collections.Immutable; | ||
|
||
namespace xFunc.Maths.Expressions; | ||
|
||
/// <summary> | ||
/// Represents the rational number expression. | ||
/// </summary> | ||
public class Rational : BinaryExpression | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="Rational"/> class. | ||
/// </summary> | ||
/// <param name="left">The left (first) operand.</param> | ||
/// <param name="right">The right (second) operand.</param> | ||
public Rational(IExpression left, IExpression right) | ||
: base(left, right) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="Rational"/> class. | ||
/// </summary> | ||
/// <param name="arguments">The list of arguments.</param> | ||
internal Rational(ImmutableArray<IExpression> arguments) | ||
: base(arguments) | ||
{ | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override object Execute(ExpressionParameters? parameters) | ||
{ | ||
var leftResult = Left.Execute(parameters); | ||
var rightResult = Right.Execute(parameters); | ||
|
||
return (leftResult, rightResult) switch | ||
{ | ||
(NumberValue left, NumberValue right) => new RationalValue(left, right), | ||
|
||
_ => throw new ResultIsNotSupportedException(this, leftResult, rightResult), | ||
}; | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override TResult AnalyzeInternal<TResult>(IAnalyzer<TResult> analyzer) | ||
=> analyzer.Analyze(this); | ||
|
||
/// <inheritdoc /> | ||
protected override TResult AnalyzeInternal<TResult, TContext>( | ||
IAnalyzer<TResult, TContext> analyzer, | ||
TContext context) | ||
=> analyzer.Analyze(this, context); | ||
|
||
/// <inheritdoc /> | ||
public override IExpression Clone(IExpression? left = null, IExpression? right = null) | ||
=> new Rational(left ?? Left, right ?? Right); | ||
} |
Oops, something went wrong.