46 lines
1.8 KiB
C#
46 lines
1.8 KiB
C#
namespace Bts.ArithmeticExpressions;
|
|
|
|
using System.Numerics;
|
|
|
|
public static class ArithmeticExpressionExtensions {
|
|
public static IArithmeticExpression<TResult> Add<TLeft, TRight, TResult>(
|
|
this IArithmeticExpression<TLeft> left, IArithmeticExpression<TRight> right)
|
|
where TLeft :
|
|
INumber<TLeft>,
|
|
IAdditionOperators<TLeft, TRight, TResult>
|
|
where TRight : INumber<TRight>
|
|
where TResult : INumber<TResult> =>
|
|
new Sum<TLeft, TRight, TResult>(left, right);
|
|
|
|
public static IArithmeticExpression<TResult> Subtract<TLeft, TRight, TResult>(
|
|
this IArithmeticExpression<TLeft> left, IArithmeticExpression<TRight> right)
|
|
where TLeft :
|
|
INumber<TLeft>,
|
|
ISubtractionOperators<TLeft, TRight, TResult>
|
|
where TRight : INumber<TRight>
|
|
where TResult : INumber<TResult> =>
|
|
new Difference<TLeft, TRight, TResult>(left, right);
|
|
|
|
public static IArithmeticExpression<TResult> Multiply<TLeft, TRight, TResult>(
|
|
this IArithmeticExpression<TLeft> left, IArithmeticExpression<TRight> right)
|
|
where TLeft :
|
|
INumber<TLeft>,
|
|
IMultiplyOperators<TLeft, TRight, TResult>
|
|
where TRight : INumber<TRight>
|
|
where TResult : INumber<TResult> =>
|
|
new Product<TLeft, TRight, TResult>(left, right);
|
|
|
|
public static IArithmeticExpression<TResult> Divide<TLeft, TRight, TResult>(
|
|
this IArithmeticExpression<TLeft> left, IArithmeticExpression<TRight> right)
|
|
where TLeft :
|
|
INumber<TLeft>,
|
|
IDivisionOperators<TLeft, TRight, TResult>
|
|
where TRight : INumber<TRight>
|
|
where TResult : INumber<TResult> =>
|
|
new Quotient<TLeft, TRight, TResult>(left, right);
|
|
|
|
public static IArithmeticExpression<T> Negate<T>(this IArithmeticExpression<T> expression)
|
|
where T : INumber<T> =>
|
|
new AdditiveInverse<T>(expression);
|
|
}
|