Adding Min and Max
This commit is contained in:
parent
82ceb7e5cd
commit
e51068a27e
2 changed files with 70 additions and 0 deletions
35
src/stdlib/functions/Max.cs
Normal file
35
src/stdlib/functions/Max.cs
Normal 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));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
35
src/stdlib/functions/Min.cs
Normal file
35
src/stdlib/functions/Min.cs
Normal 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));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue