Skip to content

Commit

Permalink
Add missing Math functions: clamp, log(d, b), log10, pow
Browse files Browse the repository at this point in the history
Add normalize function for strings
  • Loading branch information
Rohansi committed Feb 11, 2022
1 parent 7a1df3c commit a011787
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Mond/Libraries/Core/Math.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down
9 changes: 9 additions & 0 deletions Mond/VirtualMachine/Prototypes/StringPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,15 @@ public static string Trim([MondInstance] MondValue instance)
return ((string)instance).Trim();
}

/// <summary>
/// normalize(): string
/// </summary>
[MondFunction]
public static string Normalize([MondInstance] MondValue instance)
{
return ((string)instance).Normalize();
}

/// <summary>
/// format(): string
/// </summary>
Expand Down

0 comments on commit a011787

Please sign in to comment.