38 lines
991 B
C#
38 lines
991 B
C#
using CsMic;
|
|
using FunctionValueType = CsMic.FunctionValueType;
|
|
|
|
namespace CsMic.StandardLibrary.Functions
|
|
{
|
|
public class Sign : FunctionBase, ICodedFunction
|
|
{
|
|
public const decimal POSITIVE = 1;
|
|
public const decimal NEGATIVE = -1;
|
|
|
|
public string Name
|
|
{
|
|
get
|
|
{
|
|
return "sign";
|
|
}
|
|
}
|
|
|
|
public override IEnumerable<FunctionArgument> ExpectedArguments
|
|
{
|
|
get
|
|
{
|
|
yield return new FunctionArgument("value", FunctionValue.NUMBER);
|
|
}
|
|
}
|
|
|
|
public FunctionValue Execute(params FunctionArgument[] args)
|
|
{
|
|
return base.Execute(args, (_args) =>
|
|
{
|
|
var input = _args[0].Value;
|
|
decimal number = Convert.ToDecimal(input.Value);
|
|
|
|
return new FunctionValue(FunctionValueType.Numeric, number >= 0 ? POSITIVE : NEGATIVE);
|
|
});
|
|
}
|
|
}
|
|
}
|