Added two base functions
This commit is contained in:
parent
e458cdd910
commit
fcbdaa1f9d
4 changed files with 82 additions and 35 deletions
30
src/stdlib/functions/Sign.cs
Normal file
30
src/stdlib/functions/Sign.cs
Normal file
|
@ -0,0 +1,30 @@
|
|||
using csmic;
|
||||
using ValueType = csmic.ValueType;
|
||||
|
||||
namespace stdlib.functions
|
||||
{
|
||||
public class Sign : FunctionBase, ICodedFunction
|
||||
{
|
||||
public const decimal POSITIVE = 1;
|
||||
public const decimal NEGATIVE = -1;
|
||||
|
||||
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(ValueType.Numeric, number >= 0 ? POSITIVE : NEGATIVE);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue