From a0117873a4fc07b4e59342f969f34ed2abdc5c4f Mon Sep 17 00:00:00 2001 From: Rohan Singh Date: Thu, 10 Feb 2022 22:30:56 -0500 Subject: [PATCH] Add missing Math functions: clamp, log(d, b), log10, pow Add normalize function for strings --- Mond/Libraries/Core/Math.cs | 17 +++++++++++++++++ .../Prototypes/StringPrototype.cs | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/Mond/Libraries/Core/Math.cs b/Mond/Libraries/Core/Math.cs index ff0143b9..e9e20da8 100644 --- a/Mond/Libraries/Core/Math.cs +++ b/Mond/Libraries/Core/Math.cs @@ -24,6 +24,14 @@ internal class MathModule [MondFunction] public static double Ceiling(double d) => Math.Ceiling(d); + [MondFunction] + public static double Clamp(double value, double min, double max) + { + if (value < min) return min; + if (value > max) return max; + return value; + } + [MondFunction] public static double Cos(double d) => Math.Cos(d); @@ -39,12 +47,21 @@ internal class MathModule [MondFunction] public static double Log(double d) => Math.Log(d); + [MondFunction] + public static double Log(double d, double b) => Math.Log(d, b); + + [MondFunction] + public static double Log10(double d) => Math.Log10(d); + [MondFunction] public static double Max(double x, double y) => Math.Max(x, y); [MondFunction] public static double Min(double x, double y) => Math.Min(x, y); + [MondFunction] + public static double Pow(double x, double y) => Math.Pow(x, y); + [MondFunction] public static double Round(double d) => Math.Round(d); diff --git a/Mond/VirtualMachine/Prototypes/StringPrototype.cs b/Mond/VirtualMachine/Prototypes/StringPrototype.cs index 8e632bdf..46f029d0 100644 --- a/Mond/VirtualMachine/Prototypes/StringPrototype.cs +++ b/Mond/VirtualMachine/Prototypes/StringPrototype.cs @@ -187,6 +187,15 @@ public static string Trim([MondInstance] MondValue instance) return ((string)instance).Trim(); } + /// + /// normalize(): string + /// + [MondFunction] + public static string Normalize([MondInstance] MondValue instance) + { + return ((string)instance).Normalize(); + } + /// /// format(): string ///