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; var input = _args[0].Value;
decimal value = Convert.ToDecimal(input.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; var input = _args[0].Value;
decimal value = Convert.ToDecimal(input.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; var inputPeriodEnd = _args[2].Value;
decimal periodEnd = Convert.ToDecimal(inputPeriodEnd.Value); decimal periodEnd = Convert.ToDecimal(inputPeriodEnd.Value);
// Perform modulo. // Perform modulo and shift into [periodStart, periodEnd)
decimal width = periodEnd - periodStart; decimal width = periodEnd - periodStart;
decimal modulus = value % width; decimal modulus = value % width;
modulus = modulus < 0 ? modulus + width : modulus; 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, /* 10 */ 3628800,
/* 11 */ 39916800, /* 11 */ 39916800,
/* 12 */ 479001600, /* 12 */ 479001600,
/* 13 */ 62207020800, /* 13 */ 6227020800,
/* 14 */ 87178291200, /* 14 */ 87178291200,
/* 15 */ 1307674368000, /* 15 */ 1307674368000,
/* 16 */ 20922789888000, /* 16 */ 20922789888000,

View file

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace CSMic.StandardLibrary.Functions.NumberTheory namespace CSMic.StandardLibrary.Functions.NumberTheory
{ {
public class GreatestCommonDevisor : FunctionBase, ICodedFunction public class GreatestCommonDivisor : FunctionBase, ICodedFunction
{ {
public string Name public string Name
{ {
@ -46,9 +46,8 @@ namespace CSMic.StandardLibrary.Functions.NumberTheory
} }
decimal gcd = EuclideanAlgorithm(first, second); 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 get
{ {
return "gcd"; return "lcm";
} }
} }
@ -45,7 +45,10 @@ namespace CSMic.StandardLibrary.Functions.NumberTheory
return FunctionValue.ZERO; 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 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 get
{ {
yield return new FunctionArgument("value", FunctionValue.NUMBER); yield return new FunctionArgument("value", FunctionValue.NUMBER);
yield return new FunctionArgument("precision", FunctionValue.NUMBER);
} }
} }
@ -26,7 +27,7 @@
var inputValue = _args[0].Value; var inputValue = _args[0].Value;
decimal value = Convert.ToDecimal(inputValue.Value); decimal value = Convert.ToDecimal(inputValue.Value);
var inputPrecision = _args[1].Value; var inputPrecision = _args[1].Value;
decimal precision = Convert.ToDecimal(inputValue.Value); decimal precision = Convert.ToDecimal(inputPrecision.Value);
precision = Math.Round(precision); precision = Math.Round(precision);
int precisionInt = Convert.ToInt32(precision); int precisionInt = Convert.ToInt32(precision);

View file

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

View file

@ -15,8 +15,8 @@
{ {
get get
{ {
yield return new FunctionArgument("value", FunctionValue.NUMBER); yield return new FunctionArgument("y", FunctionValue.NUMBER);
yield return new FunctionArgument("value", 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 Factorial());
inputInterpreter.RegisterFunction(new BinomialCoefficient()); inputInterpreter.RegisterFunction(new BinomialCoefficient());
inputInterpreter.RegisterFunction(new Permutations()); inputInterpreter.RegisterFunction(new Permutations());
inputInterpreter.RegisterFunction(new GreatestCommonDevisor()); inputInterpreter.RegisterFunction(new GreatestCommonDivisor());
inputInterpreter.RegisterFunction(new LeastCommonMultiple()); inputInterpreter.RegisterFunction(new LeastCommonMultiple());
} }
@ -80,7 +80,7 @@ namespace CSMic.StandardLibrary
inputInterpreter.RegisterFunction(new Floor()); inputInterpreter.RegisterFunction(new Floor());
inputInterpreter.RegisterFunction(new Ceiling()); inputInterpreter.RegisterFunction(new Ceiling());
inputInterpreter.RegisterFunction(new Fractional()); inputInterpreter.RegisterFunction(new Fractional());
inputInterpreter.RegisterFunction(new Trancate()); inputInterpreter.RegisterFunction(new Truncate());
inputInterpreter.RegisterFunction(new Round()); inputInterpreter.RegisterFunction(new Round());
inputInterpreter.RegisterFunction(new Clamp()); inputInterpreter.RegisterFunction(new Clamp());
} }