using CSMic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSMic.StandardLibrary.Functions
{
///
/// Represents the standard-library min function.
///
///
/// The min function evaluates two numeric expressions and returns the smaller value.
///
public class Min : FunctionBase, ICodedFunction
{
///
/// Gets the expression-language name used to invoke this function.
///
/// min.
public string Name
{
get
{
return "min";
}
}
///
/// Gets the argument signature expected by the min function.
///
/// Two numeric arguments named first and second.
public override IEnumerable ExpectedArguments
{
get
{
yield return new FunctionArgument("first", FunctionValue.NUMBER);
yield return new FunctionArgument("second", FunctionValue.NUMBER);
}
}
///
/// Executes the min function.
///
///
/// The evaluated arguments supplied to the function. Exactly two numeric arguments are expected.
///
///
/// A numeric containing the smaller of the two input values.
///
public FunctionValue Execute(params FunctionArgument[] args)
{
return base.Execute(args, (_args) =>
{
var inputFirst = _args[0].Value;
var inputSecond = _args[1].Value;
decimal first = Convert.ToDecimal(inputFirst.Value);
decimal second = Convert.ToDecimal(inputSecond.Value);
return new FunctionValue(FunctionValueType.Numeric, Math.Min(first, second));
});
}
}
}