using System;
namespace MBS.Framework
{
public static class MathExtensions
{
///
/// Multiplies a floating point value x by the number 2 raised to the exp power.
///
/// The ldexp.
/// The x coordinate.
/// Exp.
public static float ldexp(float x, int exp)
{
return (float)(x * Math.Pow(2, exp));
}
///
/// Multiplies a floating point value x by the number 2 raised to the exp power.
///
/// The ldexp.
/// The x coordinate.
/// Exp.
public static double ldexp(double x, int exp)
{
return (x * Math.Pow(2, exp));
}
///
/// Returns a random between
/// and .
///
/// The random number.
/// The instance of being extended.
/// The inclusive minimum bound of the resulting random value.
/// The exclusive maximum bound of the resulting random value.
public static long NextLong (this Random random, long minValue = 0, long maxValue = long.MaxValue)
{
return (long)((random.NextDouble() * (maxValue - minValue)) + minValue);
}
///
/// Calculates the sum of all elements in the array.
///
/// The sum of all elements in the array.
/// The array to sum.
public static ushort Sum(this ushort[] array)
{
ushort value = 0;
for (int i = 0; i < array.Length; i++)
{
value += array[i];
}
return value;
}
}
}