Added two base functions

This commit is contained in:
Jordan Wages 2025-08-20 04:55:04 -05:00
commit fcbdaa1f9d
4 changed files with 82 additions and 35 deletions

View 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);
});
}
}
}