Fix stdlib typos and logic bugs: Round precision arg; rename Trancate->Truncate; correct degrees/radians conversion; wrapangle shift into range; Random rands add lower; correct gcd/lcm names/logic; fix 13! constant; clarify atan2 args; update initializer registrations

This commit is contained in:
Jordan Wages 2025-08-21 03:52:26 -05:00
commit 736f05a023
11 changed files with 22 additions and 17 deletions

View file

@ -26,7 +26,8 @@
var input = _args[0].Value;
decimal value = Convert.ToDecimal(input.Value);
return new FunctionValue(FunctionValueType.Numeric, double.DegreesToRadians((double)value));
// Convert radians to degrees
return new FunctionValue(FunctionValueType.Numeric, double.RadiansToDegrees((double)value));
});
}
}

View file

@ -26,7 +26,8 @@
var input = _args[0].Value;
decimal value = Convert.ToDecimal(input.Value);
return new FunctionValue(FunctionValueType.Numeric, double.RadiansToDegrees((double)value));
// Convert degrees to radians
return new FunctionValue(FunctionValueType.Numeric, double.DegreesToRadians((double)value));
});
}
}

View file

@ -31,12 +31,12 @@
var inputPeriodEnd = _args[2].Value;
decimal periodEnd = Convert.ToDecimal(inputPeriodEnd.Value);
// Perform modulo.
// Perform modulo and shift into [periodStart, periodEnd)
decimal width = periodEnd - periodStart;
decimal modulus = value % width;
modulus = modulus < 0 ? modulus + width : modulus;
return new FunctionValue(FunctionValueType.Numeric, modulus);
return new FunctionValue(FunctionValueType.Numeric, periodStart + modulus);
});
}
}

View file

@ -37,7 +37,7 @@ namespace CSMic.StandardLibrary.Functions.NumberTheory
/* 10 */ 3628800,
/* 11 */ 39916800,
/* 12 */ 479001600,
/* 13 */ 62207020800,
/* 13 */ 6227020800,
/* 14 */ 87178291200,
/* 15 */ 1307674368000,
/* 16 */ 20922789888000,

View file

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace CSMic.StandardLibrary.Functions.NumberTheory
{
public class GreatestCommonDevisor : FunctionBase, ICodedFunction
public class GreatestCommonDivisor : FunctionBase, ICodedFunction
{
public string Name
{
@ -46,9 +46,8 @@ namespace CSMic.StandardLibrary.Functions.NumberTheory
}
decimal gcd = EuclideanAlgorithm(first, second);
decimal lcd = (first * second) / gcd;
return new FunctionValue(FunctionValueType.Numeric, lcd);
return new FunctionValue(FunctionValueType.Numeric, gcd);
});
}

View file

@ -13,7 +13,7 @@ namespace CSMic.StandardLibrary.Functions.NumberTheory
{
get
{
return "gcd";
return "lcm";
}
}
@ -45,7 +45,10 @@ namespace CSMic.StandardLibrary.Functions.NumberTheory
return FunctionValue.ZERO;
}
return new FunctionValue(FunctionValueType.Numeric, EuclideanAlgorithm(first, second));
decimal gcd = EuclideanAlgorithm(first, second);
decimal lcm = (first * second) / gcd;
return new FunctionValue(FunctionValueType.Numeric, lcm);
});
}

View file

@ -36,7 +36,7 @@ namespace CSMic.StandardLibrary.Functions.Random
return FunctionValue.ZERO;
}
return new FunctionValue(FunctionValueType.Numeric, NextDecimal() * (upper - lower));
return new FunctionValue(FunctionValueType.Numeric, lower + NextDecimal() * (upper - lower));
});
}
}

View file

@ -16,6 +16,7 @@
get
{
yield return new FunctionArgument("value", FunctionValue.NUMBER);
yield return new FunctionArgument("precision", FunctionValue.NUMBER);
}
}
@ -26,7 +27,7 @@
var inputValue = _args[0].Value;
decimal value = Convert.ToDecimal(inputValue.Value);
var inputPrecision = _args[1].Value;
decimal precision = Convert.ToDecimal(inputValue.Value);
decimal precision = Convert.ToDecimal(inputPrecision.Value);
precision = Math.Round(precision);
int precisionInt = Convert.ToInt32(precision);

View file

@ -1,6 +1,6 @@
namespace CSMic.StandardLibrary.Functions.Rounding
{
public class Trancate : FunctionBase, ICodedFunction
public class Truncate : FunctionBase, ICodedFunction
{
public string Name

View file

@ -15,8 +15,8 @@
{
get
{
yield return new FunctionArgument("value", FunctionValue.NUMBER);
yield return new FunctionArgument("value", FunctionValue.NUMBER);
yield return new FunctionArgument("y", FunctionValue.NUMBER);
yield return new FunctionArgument("x", FunctionValue.NUMBER);
}
}

View file

@ -66,7 +66,7 @@ namespace CSMic.StandardLibrary
inputInterpreter.RegisterFunction(new Factorial());
inputInterpreter.RegisterFunction(new BinomialCoefficient());
inputInterpreter.RegisterFunction(new Permutations());
inputInterpreter.RegisterFunction(new GreatestCommonDevisor());
inputInterpreter.RegisterFunction(new GreatestCommonDivisor());
inputInterpreter.RegisterFunction(new LeastCommonMultiple());
}
@ -80,7 +80,7 @@ namespace CSMic.StandardLibrary
inputInterpreter.RegisterFunction(new Floor());
inputInterpreter.RegisterFunction(new Ceiling());
inputInterpreter.RegisterFunction(new Fractional());
inputInterpreter.RegisterFunction(new Trancate());
inputInterpreter.RegisterFunction(new Truncate());
inputInterpreter.RegisterFunction(new Round());
inputInterpreter.RegisterFunction(new Clamp());
}