using System;
using System.Collections.Generic;
using System.Text;
namespace CSMic.StandardLibrary.Functions
{
///
/// Represents the standard-library sqrt function.
///
///
/// The sqrt function evaluates a numeric expression and returns its square root.
///
public class SquareRoot: FunctionBase, ICodedFunction
{
///
/// Gets the expression-language name used to invoke this function.
///
/// sqrt.
public string Name
{
get
{
return "sqrt";
}
}
///
/// Gets the argument signature expected by the sqrt function.
///
/// A single numeric argument named value.
public override IEnumerable ExpectedArguments
{
get
{
yield return new FunctionArgument("value", FunctionValue.NUMBER);
}
}
///
/// Executes the sqrt function.
///
///
/// The evaluated arguments supplied to the function. Exactly one numeric argument is expected.
///
///
/// A numeric containing the square root of the input.
///
public FunctionValue Execute(params FunctionArgument[] args)
{
return base.Execute(args, (_args) =>
{
var input = _args[0].Value;
double number = Convert.ToDouble(input.Value);
return new FunctionValue(FunctionValueType.Numeric, Math.Sqrt(number));
});
}
}
}