Skip to content

Commit

Permalink
Add Clamp
Browse files Browse the repository at this point in the history
  • Loading branch information
nikeee committed Jun 20, 2014
1 parent 3111828 commit cf38192
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
Binary file modified dist/lib/net40/NTH.dll
Binary file not shown.
68 changes: 68 additions & 0 deletions src/NTH/NTH/MathEx.cs
Expand Up @@ -64,6 +64,74 @@ public static long Pow(long x, long y)

#endregion

#region Clamp

public static byte Clamp(byte value, byte min, byte max)
{
if (value < min)
return min;
if (value > max)
return max;
return value;
}

public static short Clamp(short value, short min, short max)
{
if (value < min)
return min;
if (value > max)
return max;
return value;
}

public static int Clamp(int value, int min, int max)
{
if (value < min)
return min;
if (value > max)
return max;
return value;
}

public static long Clamp(long value, long min, long max)
{
if (value < min)
return min;
if (value > max)
return max;
return value;
}

public static float Clamp(float value, float min, float max)
{
if (value < min)
return min;
if (value > max)
return max;
return value;
}

public static double Clamp(double value, double min, double max)
{
if (value < min)
return min;
if (value > max)
return max;
return value;
}

public static decimal Clamp(decimal value, decimal min, decimal max)
{
if (value < min)
return min;
if (value > max)
return max;
return value;
}

#endregion


#region Min, 3 params

/// <summary>Returns the smaller of three 32-bit signed integers.</summary>
Expand Down

0 comments on commit cf38192

Please sign in to comment.