Fix and cover standard library functions
This commit is contained in:
parent
a936188e46
commit
858717deae
11 changed files with 146 additions and 30 deletions
|
|
@ -56,9 +56,9 @@ namespace CSMic.StandardLibrary.Functions
|
|||
var input2 = _args[1].Value;
|
||||
var input3 = _args[2].Value;
|
||||
|
||||
decimal start = Convert.ToDecimal(input);
|
||||
decimal end = Convert.ToDecimal(input2);
|
||||
decimal ammount = Convert.ToDecimal(input3);
|
||||
decimal start = Convert.ToDecimal(input.Value);
|
||||
decimal end = Convert.ToDecimal(input2.Value);
|
||||
decimal ammount = Convert.ToDecimal(input3.Value);
|
||||
|
||||
if (start == end)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -64,11 +64,11 @@ namespace CSMic.StandardLibrary.Functions
|
|||
var input4 = _args[3].Value;
|
||||
var input5 = _args[4].Value;
|
||||
|
||||
decimal number = Convert.ToDecimal(input);
|
||||
decimal oldMinimum = Convert.ToDecimal(input2);
|
||||
decimal oldMaximum = Convert.ToDecimal(input3);
|
||||
decimal newMinimum = Convert.ToDecimal(input4);
|
||||
decimal newMaximum = Convert.ToDecimal(input5);
|
||||
decimal number = Convert.ToDecimal(input.Value);
|
||||
decimal oldMinimum = Convert.ToDecimal(input2.Value);
|
||||
decimal oldMaximum = Convert.ToDecimal(input3.Value);
|
||||
decimal newMinimum = Convert.ToDecimal(input4.Value);
|
||||
decimal newMaximum = Convert.ToDecimal(input5.Value);
|
||||
|
||||
if (oldMinimum == oldMaximum)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -57,9 +57,9 @@ namespace CSMic.StandardLibrary.Functions
|
|||
var input2 = _args[1].Value;
|
||||
var input3 = _args[2].Value;
|
||||
|
||||
decimal number = Convert.ToDecimal(input);
|
||||
decimal minimum = Convert.ToDecimal(input2);
|
||||
decimal maximum = Convert.ToDecimal(input3);
|
||||
decimal number = Convert.ToDecimal(input.Value);
|
||||
decimal minimum = Convert.ToDecimal(input2.Value);
|
||||
decimal maximum = Convert.ToDecimal(input3.Value);
|
||||
|
||||
if (minimum == maximum)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ namespace CSMic.StandardLibrary.Functions.NumberTheory
|
|||
{
|
||||
var input = _args[0].Value;
|
||||
|
||||
int index = Convert.ToInt32(input);
|
||||
int index = Convert.ToInt32(input.Value);
|
||||
|
||||
if(index <= 0 || index > 140)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ namespace CSMic.StandardLibrary.Functions.NumberTheory
|
|||
{
|
||||
var input = _args[0].Value;
|
||||
|
||||
decimal value = Convert.ToDecimal(input);
|
||||
decimal value = Convert.ToDecimal(input.Value);
|
||||
|
||||
return new FunctionValue(FunctionValueType.Numeric, IsEven.CalculateIsEven(value) ? 1m : 0m);
|
||||
});
|
||||
|
|
@ -61,7 +61,7 @@ namespace CSMic.StandardLibrary.Functions.NumberTheory
|
|||
|
||||
internal static bool CalculateIsEven(decimal value)
|
||||
{
|
||||
return true;
|
||||
return IsInt.CalculateIsInt(value) && value % 2m == 0m;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -113,11 +113,16 @@ namespace CSMic.StandardLibrary.Functions.NumberTheory
|
|||
{
|
||||
var input = _args[0].Value;
|
||||
|
||||
decimal value = Convert.ToDecimal(input);
|
||||
decimal value = Convert.ToDecimal(input.Value);
|
||||
|
||||
return new FunctionValue(FunctionValueType.Numeric, IsEven.CalculateIsEven(value) ? 0m : 1m);
|
||||
return new FunctionValue(FunctionValueType.Numeric, CalculateIsOdd(value) ? 1m : 0m);
|
||||
});
|
||||
}
|
||||
|
||||
internal static bool CalculateIsOdd(decimal value)
|
||||
{
|
||||
return IsInt.CalculateIsInt(value) && value % 2m != 0m;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -169,7 +174,7 @@ namespace CSMic.StandardLibrary.Functions.NumberTheory
|
|||
{
|
||||
var input = _args[0].Value;
|
||||
|
||||
decimal value = Convert.ToDecimal(input);
|
||||
decimal value = Convert.ToDecimal(input.Value);
|
||||
|
||||
return new FunctionValue(FunctionValueType.Numeric, CalculateIsInt(value) ? 1m : 0m);
|
||||
});
|
||||
|
|
@ -255,7 +260,7 @@ namespace CSMic.StandardLibrary.Functions.NumberTheory
|
|||
{
|
||||
var input = _args[0].Value;
|
||||
|
||||
decimal value = Convert.ToDecimal(input);
|
||||
decimal value = Convert.ToDecimal(input.Value);
|
||||
|
||||
return new FunctionValue(FunctionValueType.Numeric, CalculateIsPrime(value) ? 1m : 0m);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using System.Text;
|
|||
namespace CSMic.StandardLibrary.Functions
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the standard-library <c>lerp</c> smooth-step function.
|
||||
/// Represents the standard-library <c>smoothstep</c> function.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This function evaluates a value between two edges, clamps it to the range from <c>0</c> through <c>1</c>, and
|
||||
|
|
@ -16,17 +16,17 @@ namespace CSMic.StandardLibrary.Functions
|
|||
/// <summary>
|
||||
/// Gets the expression-language name used to invoke this function.
|
||||
/// </summary>
|
||||
/// <value><c>lerp</c>.</value>
|
||||
/// <value><c>smoothstep</c>.</value>
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return "lerp";
|
||||
return "smoothstep";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the argument signature expected by the <c>lerp</c> smooth-step function.
|
||||
/// Gets the argument signature expected by the <c>smoothstep</c> function.
|
||||
/// </summary>
|
||||
/// <value>Three numeric arguments named <c>startEdge</c>, <c>endEdge</c>, and <c>value</c>.</value>
|
||||
public override IEnumerable<FunctionArgument> ExpectedArguments
|
||||
|
|
@ -40,7 +40,7 @@ namespace CSMic.StandardLibrary.Functions
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes the <c>lerp</c> smooth-step function.
|
||||
/// Executes the <c>smoothstep</c> function.
|
||||
/// </summary>
|
||||
/// <param name="args">
|
||||
/// The evaluated arguments supplied to the function. Exactly three numeric arguments are expected.
|
||||
|
|
@ -56,9 +56,9 @@ namespace CSMic.StandardLibrary.Functions
|
|||
var input2 = _args[1].Value;
|
||||
var input3 = _args[2].Value;
|
||||
|
||||
decimal startEdge = Convert.ToDecimal(input);
|
||||
decimal endEdge = Convert.ToDecimal(input2);
|
||||
decimal value = Convert.ToDecimal(input3);
|
||||
decimal startEdge = Convert.ToDecimal(input.Value);
|
||||
decimal endEdge = Convert.ToDecimal(input2.Value);
|
||||
decimal value = Convert.ToDecimal(input3.Value);
|
||||
|
||||
var normalization = Math.Clamp((value - startEdge) / (endEdge - startEdge), 0, 1);
|
||||
var polynomialization = normalization * normalization * (3 - (2 * normalization));
|
||||
|
|
|
|||
|
|
@ -65,6 +65,13 @@ namespace CSMic.StandardLibrary
|
|||
inputInterpreter.RegisterFunction(new Min());
|
||||
inputInterpreter.RegisterFunction(new Max());
|
||||
inputInterpreter.RegisterFunction(new SquareRoot());
|
||||
inputInterpreter.RegisterFunction(new Power());
|
||||
inputInterpreter.RegisterFunction(new Log());
|
||||
inputInterpreter.RegisterFunction(new Natural_Log());
|
||||
inputInterpreter.RegisterFunction(new Lerp());
|
||||
inputInterpreter.RegisterFunction(new SmoothStep());
|
||||
inputInterpreter.RegisterFunction(new Map());
|
||||
inputInterpreter.RegisterFunction(new Normalize());
|
||||
}
|
||||
|
||||
/// <summary> Initializes the angle-related functions. </summary>
|
||||
|
|
@ -97,6 +104,11 @@ namespace CSMic.StandardLibrary
|
|||
inputInterpreter.RegisterFunction(new Permutations());
|
||||
inputInterpreter.RegisterFunction(new GreatestCommonDivisor());
|
||||
inputInterpreter.RegisterFunction(new LeastCommonMultiple());
|
||||
inputInterpreter.RegisterFunction(new Fibonacci());
|
||||
inputInterpreter.RegisterFunction(new IsEven());
|
||||
inputInterpreter.RegisterFunction(new IsOdd());
|
||||
inputInterpreter.RegisterFunction(new IsInt());
|
||||
inputInterpreter.RegisterFunction(new IsPrime());
|
||||
}
|
||||
|
||||
/// <summary> Initializes the rounding functions. </summary>
|
||||
|
|
@ -178,6 +190,7 @@ namespace CSMic.StandardLibrary
|
|||
inputInterpreter.Interpret("tau :: 6.2831853071795862");
|
||||
inputInterpreter.Interpret("phi :: 1.6180339887498948");
|
||||
inputInterpreter.Interpret("goldenratio :: 1.6180339887498948");
|
||||
inputInterpreter.Interpret("eurler :: 0.5772156649015329");
|
||||
inputInterpreter.Interpret("euler :: 0.5772156649015329");
|
||||
inputInterpreter.Interpret("omega :: 0.5671432904097839");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ decimal result = interpreter.Interpret("max(10, abs(-12))");
|
|||
- `phi`
|
||||
- `goldenratio`
|
||||
- `eurler`
|
||||
- `euler`
|
||||
- `omega`
|
||||
|
||||
Constants are stored as interpreter variables, so they can be used in normal expressions:
|
||||
|
|
@ -59,6 +60,14 @@ Base functions:
|
|||
- `sign(value)`
|
||||
- `min(left, right)`
|
||||
- `max(left, right)`
|
||||
- `sqrt(value)`
|
||||
- `pow(base, exponent)`
|
||||
- `log(value, base)`
|
||||
- `ln(value)`
|
||||
- `lerp(start, end, amount)`
|
||||
- `smoothstep(startEdge, endEdge, value)`
|
||||
- `map(value, oldMinimum, oldMaximum, newMinimum, newMaximum)`
|
||||
- `normalize(value, minimum, maximum)`
|
||||
|
||||
Angle functions:
|
||||
|
||||
|
|
@ -101,6 +110,11 @@ Number theory functions:
|
|||
- `npr(n, r)`
|
||||
- `gcd(left, right)`
|
||||
- `lcm(left, right)`
|
||||
- `fib(index)`
|
||||
- `iseven(value)`
|
||||
- `isodd(value)`
|
||||
- `isint(value)`
|
||||
- `isprime(value)`
|
||||
|
||||
Random functions:
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue