Adding Min and Max

This commit is contained in:
Jordan Wages 2025-08-20 05:28:05 -05:00
commit e51068a27e
2 changed files with 70 additions and 0 deletions

View file

@ -0,0 +1,35 @@
using csmic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace stdlib.functions
{
public class Max : FunctionBase, ICodedFunction
{
public override IEnumerable<FunctionArgument> ExpectedArguments
{
get
{
yield return new FunctionArgument("first", FunctionValue.NUMBER);
yield return new FunctionArgument("second", FunctionValue.NUMBER);
}
}
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));
});
}
}
}

View file

@ -0,0 +1,35 @@
using csmic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace stdlib.functions
{
public class Min : FunctionBase, ICodedFunction
{
public override IEnumerable<FunctionArgument> ExpectedArguments
{
get
{
yield return new FunctionArgument("first", FunctionValue.NUMBER);
yield return new FunctionArgument("second", FunctionValue.NUMBER);
}
}
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));
});
}
}
}