1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-22 05:58:47 +00:00

Compare commits

..

4 Commits

15 changed files with 87 additions and 745 deletions

View File

@ -9,12 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- X1OD: `IBinaryInteger<T>.Factorial` now starts at `IBinaryInteger<T>.MultiplicativeIdentity` not
`IBinaryInteger<T>.One`.
- X10D: Removed `byte.Product`, `short.Product`, `ushort.Product`, `int.Product`, `uint.Product`, `long.Product`,
and `ulong.Product`, in favour of `INumber<T>.Product`.
- X10D: Removed `byte.RangeTo`, `short.RangeTo`, `ushort.RangeTo`, `int.RangeTo`, `uint.RangeTo`, `long.RangeTo`,
and `ulong.RangeTo`, in favour of `INumber<T>.RangeTo`.
- X10D: Removed `IEnumerable<T>.GreatestCommonFactor` for all integer types in favour of generic math.
- X10D: Removed `IEnumerable<T>.LowestCommonMultiple` for all integer types in favour of generic math.
- X10D: Removed `IEnumerable<T>.Product` for all integer types in favour of generic math.
- X10D: Removed `IEnumerable<T>.RangeTo` for all integer types in favour of generic math.
- X10D: Removed `T.Sign` for all numeric types in favour of generic math.
- X10D: Removed `T.Wrap` for all numeric types in favour of generic math.
### Removed

View File

@ -39,24 +39,6 @@ public static class BigIntegerExtensions
return result;
}
/// <summary>
/// Calculates the greatest common factor between this, and another, <see cref="BigInteger" />.
/// </summary>
/// <param name="value">The first value.</param>
/// <param name="other">The second value.</param>
/// <returns>The greatest common factor between <paramref name="value" /> and <paramref name="other" />.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static BigInteger GreatestCommonFactor(this BigInteger value, BigInteger other)
{
while (other != 0)
{
(value, other) = (other, value % other);
}
return value;
}
/// <summary>
/// Returns a value indicating whether the current value is not evenly divisible by 2.
/// </summary>
@ -109,34 +91,6 @@ public static class BigIntegerExtensions
return true;
}
/// <summary>
/// Calculates the lowest common multiple between the current 64-bit signed integer, and another 64-bit signed integer.
/// </summary>
/// <param name="value">The first value.</param>
/// <param name="other">The second value.</param>
/// <returns>The lowest common multiple between <paramref name="value" /> and <paramref name="other" />.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static BigInteger LowestCommonMultiple(this BigInteger value, BigInteger other)
{
if (value == 0 || other == 0)
{
return 0;
}
if (value == 1)
{
return other;
}
if (other == 1)
{
return value;
}
return value * other / value.GreatestCommonFactor(other);
}
/// <summary>
/// Returns the multiplicative persistence of a specified value.
/// </summary>
@ -182,32 +136,4 @@ public static class BigIntegerExtensions
return persistence;
}
/// <summary>
/// Wraps the current integer between a low and a high value.
/// </summary>
/// <param name="value">The value to wrap.</param>
/// <param name="low">The inclusive lower bound.</param>
/// <param name="high">The exclusive upper bound.</param>
/// <returns>The wrapped value.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static BigInteger Wrap(this BigInteger value, BigInteger low, BigInteger high)
{
BigInteger difference = high - low;
return low + (((value - low) % difference) + difference) % difference;
}
/// <summary>
/// Wraps the current integer between 0 and a high value.
/// </summary>
/// <param name="value">The value to wrap.</param>
/// <param name="length">The exclusive upper bound.</param>
/// <returns>The wrapped value.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static BigInteger Wrap(this BigInteger value, BigInteger length)
{
return ((value % length) + length) % length;
}
}

View File

@ -69,31 +69,12 @@ public static class BinaryIntegerExtensions
return 1;
}
TInteger result = TInteger.MultiplicativeIdentity;
long result = 1L;
for (TInteger i = TInteger.One; i <= value; i++)
{
result *= i;
result *= long.CreateChecked(i);
}
return long.CreateChecked(result);
}
/// <summary>
/// Calculates the greatest common factor between the current binary integer, and another binary integer.
/// </summary>
/// <param name="value">The first value.</param>
/// <param name="other">The second value.</param>
/// <returns>The greatest common factor between <paramref name="value" /> and <paramref name="other" />.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static TInteger GreatestCommonFactor<TInteger>(this TInteger value, TInteger other)
where TInteger : IBinaryInteger<TInteger>
{
while (other != TInteger.Zero)
{
(value, other) = (other, value % other);
}
return value;
return result;
}
}

View File

@ -22,19 +22,6 @@ public static class ByteExtensions
return ((long)value).IsPrime();
}
/// <summary>
/// Calculates the lowest common multiple between the current 8-bit signed integer, and another 8-bit signed integer.
/// </summary>
/// <param name="value">The first value.</param>
/// <param name="other">The second value.</param>
/// <returns>The lowest common multiple between <paramref name="value" /> and <paramref name="other" />.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static byte LowestCommonMultiple(this byte value, byte other)
{
return (byte)((long)value).LowestCommonMultiple(other);
}
/// <summary>
/// Returns the multiplicative persistence of a specified value.
/// </summary>
@ -49,31 +36,4 @@ public static class ByteExtensions
{
return ((long)value).MultiplicativePersistence();
}
/// <summary>
/// Wraps the current 8-bit unsigned integer between a low and a high value.
/// </summary>
/// <param name="value">The value to wrap.</param>
/// <param name="low">The inclusive lower bound.</param>
/// <param name="high">The exclusive upper bound.</param>
/// <returns>The wrapped value.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static byte Wrap(this byte value, byte low, byte high)
{
return (byte)((ulong)value).Wrap(low, high);
}
/// <summary>
/// Wraps the current 8-bit unsigned integer between 0 and a high value.
/// </summary>
/// <param name="value">The value to wrap.</param>
/// <param name="length">The exclusive upper bound.</param>
/// <returns>The wrapped value.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static byte Wrap(this byte value, byte length)
{
return (byte)((ulong)value).Wrap(length);
}
}

View File

@ -90,40 +90,6 @@ public static class DecimalExtensions
return System.Math.Clamp(value, 0.0m, 1.0m);
}
/// <summary>
/// Returns an integer that indicates the sign of this decimal number.
/// </summary>
/// <param name="value">A signed number.</param>
/// <returns>
/// A number that indicates the sign of <paramref name="value" />, as shown in the following table.
///
/// <list type="table">
/// <listheader>
/// <term>Return value</term>
/// <description>Meaning</description>
/// </listheader>
///
/// <item>
/// <term>-1</term>
/// <description><paramref name="value" /> is less than zero.</description>
/// </item>
/// <item>
/// <term>0</term>
/// <description><paramref name="value" /> is equal to zero.</description>
/// </item>
/// <item>
/// <term>1</term>
/// <description><paramref name="value" /> is greater than zero.</description>
/// </item>
/// </list>
/// </returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static int Sign(this decimal value)
{
return System.Math.Sign(value);
}
/// <summary>
/// Returns the square root of this decimal number.
/// </summary>
@ -174,32 +140,4 @@ public static class DecimalExtensions
return current;
}
/// <summary>
/// Wraps the current decimal number between a low and a high value.
/// </summary>
/// <param name="value">The value to wrap.</param>
/// <param name="low">The inclusive lower bound.</param>
/// <param name="high">The exclusive upper bound.</param>
/// <returns>The wrapped value.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static decimal Wrap(this decimal value, decimal low, decimal high)
{
decimal difference = high - low;
return low + (((value - low) % difference) + difference) % difference;
}
/// <summary>
/// Wraps the current decimal number between 0 and a high value.
/// </summary>
/// <param name="value">The value to wrap.</param>
/// <param name="length">The exclusive upper bound.</param>
/// <returns>The wrapped value.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static decimal Wrap(this decimal value, decimal length)
{
return ((value % length) + length) % length;
}
}

View File

@ -300,41 +300,6 @@ public static class DoubleExtensions
return System.Math.Sinh(value);
}
/// <summary>
/// Returns an integer that indicates the sign of this double-precision floating-point number.
/// </summary>
/// <param name="value">A signed number.</param>
/// <returns>
/// A number that indicates the sign of <paramref name="value" />, as shown in the following table.
///
/// <list type="table">
/// <listheader>
/// <term>Return value</term>
/// <description>Meaning</description>
/// </listheader>
///
/// <item>
/// <term>-1</term>
/// <description><paramref name="value" /> is less than zero.</description>
/// </item>
/// <item>
/// <term>0</term>
/// <description><paramref name="value" /> is equal to zero.</description>
/// </item>
/// <item>
/// <term>1</term>
/// <description><paramref name="value" /> is greater than zero.</description>
/// </item>
/// </list>
/// </returns>
/// <exception cref="ArithmeticException"><paramref name="value" /> is equal to <see cref="double.NaN" />.</exception>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static int Sign(this double value)
{
return System.Math.Sign(value);
}
/// <summary>
/// Returns the square root of this double-precision floating-point number.
/// </summary>
@ -421,32 +386,4 @@ public static class DoubleExtensions
{
return System.Math.Tanh(value);
}
/// <summary>
/// Wraps the current double-precision floating-point number between a low and a high value.
/// </summary>
/// <param name="value">The value to wrap.</param>
/// <param name="low">The inclusive lower bound.</param>
/// <param name="high">The exclusive upper bound.</param>
/// <returns>The wrapped value.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static double Wrap(this double value, double low, double high)
{
double difference = high - low;
return low + (((value - low) % difference) + difference) % difference;
}
/// <summary>
/// Wraps the current double-precision floating-point number between 0 and a high value.
/// </summary>
/// <param name="value">The value to wrap.</param>
/// <param name="length">The exclusive upper bound.</param>
/// <returns>The wrapped value.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static double Wrap(this double value, double length)
{
return ((value % length) + length) % length;
}
}

View File

@ -23,19 +23,6 @@ public static class Int16Extensions
return ((long)value).IsPrime();
}
/// <summary>
/// Calculates the lowest common multiple between the current 16-bit signed integer, and another 16-bit signed integer.
/// </summary>
/// <param name="value">The first value.</param>
/// <param name="other">The second value.</param>
/// <returns>The lowest common multiple between <paramref name="value" /> and <paramref name="other" />.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static short LowestCommonMultiple(this short value, short other)
{
return (short)((long)value).LowestCommonMultiple(other);
}
/// <summary>
/// Returns the multiplicative persistence of a specified value.
/// </summary>
@ -50,65 +37,4 @@ public static class Int16Extensions
{
return ((long)value).MultiplicativePersistence();
}
/// <summary>
/// Returns an integer that indicates the sign of this 16-bit signed integer.
/// </summary>
/// <param name="value">A signed number.</param>
/// <returns>
/// A number that indicates the sign of <paramref name="value" />, as shown in the following table.
///
/// <list type="table">
/// <listheader>
/// <term>Return value</term>
/// <description>Meaning</description>
/// </listheader>
///
/// <item>
/// <term>-1</term>
/// <description><paramref name="value" /> is less than zero.</description>
/// </item>
/// <item>
/// <term>0</term>
/// <description><paramref name="value" /> is equal to zero.</description>
/// </item>
/// <item>
/// <term>1</term>
/// <description><paramref name="value" /> is greater than zero.</description>
/// </item>
/// </list>
/// </returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static int Sign(this short value)
{
return System.Math.Sign(value);
}
/// <summary>
/// Wraps the current 16-bit signed integer between a low and a high value.
/// </summary>
/// <param name="value">The value to wrap.</param>
/// <param name="low">The inclusive lower bound.</param>
/// <param name="high">The exclusive upper bound.</param>
/// <returns>The wrapped value.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static short Wrap(this short value, short low, short high)
{
return (short)((long)value).Wrap(low, high);
}
/// <summary>
/// Wraps the current 16-bit signed integer between 0 and a high value.
/// </summary>
/// <param name="value">The value to wrap.</param>
/// <param name="length">The exclusive upper bound.</param>
/// <returns>The wrapped value.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static short Wrap(this short value, short length)
{
return (short)((long)value).Wrap(length);
}
}

View File

@ -23,19 +23,6 @@ public static class Int32Extensions
return ((long)value).IsPrime();
}
/// <summary>
/// Calculates the lowest common multiple between the current 32-bit signed integer, and another 32-bit signed integer.
/// </summary>
/// <param name="value">The first value.</param>
/// <param name="other">The second value.</param>
/// <returns>The lowest common multiple between <paramref name="value" /> and <paramref name="other" />.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static int LowestCommonMultiple(this int value, int other)
{
return (int)((long)value).LowestCommonMultiple(other);
}
/// <summary>
/// Returns the multiplicative persistence of a specified value.
/// </summary>
@ -50,65 +37,4 @@ public static class Int32Extensions
{
return ((long)value).MultiplicativePersistence();
}
/// <summary>
/// Returns an integer that indicates the sign of this 32-bit signed integer.
/// </summary>
/// <param name="value">A signed number.</param>
/// <returns>
/// A number that indicates the sign of <paramref name="value" />, as shown in the following table.
///
/// <list type="table">
/// <listheader>
/// <term>Return value</term>
/// <description>Meaning</description>
/// </listheader>
///
/// <item>
/// <term>-1</term>
/// <description><paramref name="value" /> is less than zero.</description>
/// </item>
/// <item>
/// <term>0</term>
/// <description><paramref name="value" /> is equal to zero.</description>
/// </item>
/// <item>
/// <term>1</term>
/// <description><paramref name="value" /> is greater than zero.</description>
/// </item>
/// </list>
/// </returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static int Sign(this int value)
{
return System.Math.Sign(value);
}
/// <summary>
/// Wraps the current 32-bit signed integer between a low and a high value.
/// </summary>
/// <param name="value">The value to wrap.</param>
/// <param name="low">The inclusive lower bound.</param>
/// <param name="high">The exclusive upper bound.</param>
/// <returns>The wrapped value.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static int Wrap(this int value, int low, int high)
{
return (int)((long)value).Wrap(low, high);
}
/// <summary>
/// Wraps the current 32-bit signed integer between 0 and a high value.
/// </summary>
/// <param name="value">The value to wrap.</param>
/// <param name="length">The exclusive upper bound.</param>
/// <returns>The wrapped value.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static int Wrap(this int value, int length)
{
return (int)((long)value).Wrap(length);
}
}

View File

@ -42,34 +42,6 @@ public static class Int64Extensions
return true;
}
/// <summary>
/// Calculates the lowest common multiple between the current 64-bit signed integer, and another 64-bit signed integer.
/// </summary>
/// <param name="value">The first value.</param>
/// <param name="other">The second value.</param>
/// <returns>The lowest common multiple between <paramref name="value" /> and <paramref name="other" />.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static long LowestCommonMultiple(this long value, long other)
{
if (value == 0 || other == 0)
{
return 0;
}
if (value == 1)
{
return other;
}
if (other == 1)
{
return value;
}
return value * other / value.GreatestCommonFactor(other);
}
/// <summary>
/// Returns the multiplicative persistence of a specified value.
/// </summary>
@ -115,66 +87,4 @@ public static class Int64Extensions
return persistence;
}
/// <summary>
/// Returns an integer that indicates the sign of this 64-bit signed integer.
/// </summary>
/// <param name="value">A signed number.</param>
/// <returns>
/// A number that indicates the sign of <paramref name="value" />, as shown in the following table.
///
/// <list type="table">
/// <listheader>
/// <term>Return value</term>
/// <description>Meaning</description>
/// </listheader>
///
/// <item>
/// <term>-1</term>
/// <description><paramref name="value" /> is less than zero.</description>
/// </item>
/// <item>
/// <term>0</term>
/// <description><paramref name="value" /> is equal to zero.</description>
/// </item>
/// <item>
/// <term>1</term>
/// <description><paramref name="value" /> is greater than zero.</description>
/// </item>
/// </list>
/// </returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static int Sign(this long value)
{
return System.Math.Sign(value);
}
/// <summary>
/// Wraps the current 64-bit signed integer between a low and a high value.
/// </summary>
/// <param name="value">The value to wrap.</param>
/// <param name="low">The inclusive lower bound.</param>
/// <param name="high">The exclusive upper bound.</param>
/// <returns>The wrapped value.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static long Wrap(this long value, long low, long high)
{
long difference = high - low;
return low + (((value - low) % difference) + difference) % difference;
}
/// <summary>
/// Wraps the current 64-bit signed integer between 0 and a high value.
/// </summary>
/// <param name="value">The value to wrap.</param>
/// <param name="length">The exclusive upper bound.</param>
/// <returns>The wrapped value.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static long Wrap(this long value, long length)
{
return ((value % length) + length) % length;
}
}

View File

@ -10,6 +10,25 @@ namespace X10D.Math;
/// </summary>
public static class NumberExtensions
{
/// <summary>
/// Calculates the greatest common factor between the current number and another number.
/// </summary>
/// <param name="value">The first value.</param>
/// <param name="other">The second value.</param>
/// <returns>The greatest common factor between <paramref name="value" /> and <paramref name="other" />.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static TNumber GreatestCommonFactor<TNumber>(this TNumber value, TNumber other)
where TNumber : INumber<TNumber>
{
while (other != TNumber.Zero)
{
(value, other) = (other, value % other);
}
return value;
}
/// <summary>
/// Returns a value indicating whether the current value is evenly divisible by 2.
/// </summary>
@ -42,6 +61,35 @@ public static class NumberExtensions
return !value.IsEven();
}
/// <summary>
/// Calculates the lowest common multiple between the current 64-bit signed integer, and another 64-bit signed integer.
/// </summary>
/// <param name="value">The first value.</param>
/// <param name="other">The second value.</param>
/// <returns>The lowest common multiple between <paramref name="value" /> and <paramref name="other" />.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static TNumber LowestCommonMultiple<TNumber>(this TNumber value, TNumber other)
where TNumber : INumber<TNumber>
{
if (value == TNumber.Zero || other == TNumber.Zero)
{
return TNumber.Zero;
}
if (value == TNumber.One)
{
return other;
}
if (other == TNumber.One)
{
return value;
}
return value * other / value.GreatestCommonFactor(other);
}
/// <summary>
/// Performs a modulo operation which supports a negative dividend.
/// </summary>
@ -99,4 +147,34 @@ public static class NumberExtensions
{
return TNumber.Sign(value);
}
/// <summary>
/// Wraps the current integer between a low and a high value.
/// </summary>
/// <param name="value">The value to wrap.</param>
/// <param name="low">The inclusive lower bound.</param>
/// <param name="high">The exclusive upper bound.</param>
/// <returns>The wrapped value.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static TNumber Wrap<TNumber>(this TNumber value, TNumber low, TNumber high)
where TNumber : INumber<TNumber>
{
TNumber difference = high - low;
return low + (((value - low) % difference) + difference) % difference;
}
/// <summary>
/// Wraps the current integer between 0 and a high value.
/// </summary>
/// <param name="value">The value to wrap.</param>
/// <param name="length">The exclusive upper bound.</param>
/// <returns>The wrapped value.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static TNumber Wrap<TNumber>(this TNumber value, TNumber length)
where TNumber : INumber<TNumber>
{
return ((value % length) + length) % length;
}
}

View File

@ -24,19 +24,6 @@ public static class SByteExtensions
return ((long)value).IsPrime();
}
/// <summary>
/// Calculates the lowest common multiple between the current 8-bit signed integer, and another 8-bit signed integer.
/// </summary>
/// <param name="value">The first value.</param>
/// <param name="other">The second value.</param>
/// <returns>The lowest common multiple between <paramref name="value" /> and <paramref name="other" />.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static sbyte LowestCommonMultiple(this sbyte value, sbyte other)
{
return (sbyte)((long)value).LowestCommonMultiple(other);
}
/// <summary>
/// Returns the multiplicative persistence of a specified value.
/// </summary>
@ -85,31 +72,4 @@ public static class SByteExtensions
{
return System.Math.Sign(value);
}
/// <summary>
/// Wraps the current 8-bit signed integer between a low and a high value.
/// </summary>
/// <param name="value">The value to wrap.</param>
/// <param name="low">The inclusive lower bound.</param>
/// <param name="high">The exclusive upper bound.</param>
/// <returns>The wrapped value.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static sbyte Wrap(this sbyte value, sbyte low, sbyte high)
{
return (sbyte)((long)value).Wrap(low, high);
}
/// <summary>
/// Wraps the current 8-bit signed integer between 0 and a high value.
/// </summary>
/// <param name="value">The value to wrap.</param>
/// <param name="length">The exclusive upper bound.</param>
/// <returns>The wrapped value.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static sbyte Wrap(this sbyte value, sbyte length)
{
return (sbyte)((long)value).Wrap(length);
}
}

View File

@ -268,40 +268,6 @@ public static class SingleExtensions
return System.Math.Clamp(value, 0.0f, 1.0f);
}
/// <summary>
/// Returns an integer that indicates the sign of this single-precision floating-point number.
/// </summary>
/// <param name="value">A signed number.</param>
/// <returns>
/// A number that indicates the sign of <paramref name="value" />, as shown in the following table.
///
/// <list type="table">
/// <listheader>
/// <term>Return value</term>
/// <description>Meaning</description>
/// </listheader>
///
/// <item>
/// <term>-1</term>
/// <description><paramref name="value" /> is less than zero.</description>
/// </item>
/// <item>
/// <term>0</term>
/// <description><paramref name="value" /> is equal to zero.</description>
/// </item>
/// <item>
/// <term>1</term>
/// <description><paramref name="value" /> is greater than zero.</description>
/// </item>
/// </list>
/// </returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static int Sign(this float value)
{
return MathF.Sign(value);
}
/// <summary>
/// Returns the square root of this single-precision floating-point number.
/// </summary>
@ -420,31 +386,4 @@ public static class SingleExtensions
{
return MathF.Tanh(value);
}
/// <summary>
/// Wraps the current single-precision floating-point number between a low and a high value.
/// </summary>
/// <param name="value">The value to wrap.</param>
/// <param name="low">The inclusive lower bound.</param>
/// <param name="high">The exclusive upper bound.</param>
/// <returns>The wrapped value.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static float Wrap(this float value, float low, float high)
{
return (float)((double)value).Wrap(low, high);
}
/// <summary>
/// Wraps the current single-precision floating-point number between 0 and a high value.
/// </summary>
/// <param name="value">The value to wrap.</param>
/// <param name="length">The exclusive upper bound.</param>
/// <returns>The wrapped value.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static float Wrap(this float value, float length)
{
return (float)((double)value).Wrap(length);
}
}

View File

@ -24,20 +24,6 @@ public static class UInt16Extensions
return ((ulong)value).IsPrime();
}
/// <summary>
/// Calculates the lowest common multiple between the current 16-bit unsigned integer, and another 16-bit unsigned
/// integer.
/// </summary>
/// <param name="value">The first value.</param>
/// <param name="other">The second value.</param>
/// <returns>The lowest common multiple between <paramref name="value" /> and <paramref name="other" />.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static ushort LowestCommonMultiple(this ushort value, ushort other)
{
return (ushort)((ulong)value).LowestCommonMultiple(other);
}
/// <summary>
/// Returns the multiplicative persistence of a specified value.
/// </summary>
@ -52,31 +38,4 @@ public static class UInt16Extensions
{
return ((ulong)value).MultiplicativePersistence();
}
/// <summary>
/// Wraps the current 16-bit unsigned integer between a low and a high value.
/// </summary>
/// <param name="value">The value to wrap.</param>
/// <param name="low">The inclusive lower bound.</param>
/// <param name="high">The exclusive upper bound.</param>
/// <returns>The wrapped value.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static ushort Wrap(this ushort value, ushort low, ushort high)
{
return (ushort)((ulong)value).Wrap(low, high);
}
/// <summary>
/// Wraps the current 16-bit unsigned integer between 0 and a high value.
/// </summary>
/// <param name="value">The value to wrap.</param>
/// <param name="length">The exclusive upper bound.</param>
/// <returns>The wrapped value.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static ushort Wrap(this ushort value, ushort length)
{
return (ushort)((ulong)value).Wrap(length);
}
}

View File

@ -24,20 +24,6 @@ public static class UInt32Extensions
return ((ulong)value).IsPrime();
}
/// <summary>
/// Calculates the lowest common multiple between the current 32-bit unsigned integer, and another 32-bit unsigned
/// integer.
/// </summary>
/// <param name="value">The first value.</param>
/// <param name="other">The second value.</param>
/// <returns>The lowest common multiple between <paramref name="value" /> and <paramref name="other" />.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static uint LowestCommonMultiple(this uint value, uint other)
{
return (uint)((ulong)value).LowestCommonMultiple(other);
}
/// <summary>
/// Returns the multiplicative persistence of a specified value.
/// </summary>
@ -52,31 +38,4 @@ public static class UInt32Extensions
{
return ((ulong)value).MultiplicativePersistence();
}
/// <summary>
/// Wraps the current 32-bit unsigned integer between a low and a high value.
/// </summary>
/// <param name="value">The value to wrap.</param>
/// <param name="low">The inclusive lower bound.</param>
/// <param name="high">The exclusive upper bound.</param>
/// <returns>The wrapped value.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static uint Wrap(this uint value, uint low, uint high)
{
return (uint)((ulong)value).Wrap(low, high);
}
/// <summary>
/// Wraps the current 32-bit unsigned integer between 0 and a high value.
/// </summary>
/// <param name="value">The value to wrap.</param>
/// <param name="length">The exclusive upper bound.</param>
/// <returns>The wrapped value.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static uint Wrap(this uint value, uint length)
{
return (uint)((ulong)value).Wrap(length);
}
}

View File

@ -43,35 +43,6 @@ public static class UInt64Extensions
return true;
}
/// <summary>
/// Calculates the lowest common multiple between the current 64-bit unsigned integer, and another 64-bit unsigned
/// integer.
/// </summary>
/// <param name="value">The first value.</param>
/// <param name="other">The second value.</param>
/// <returns>The lowest common multiple between <paramref name="value" /> and <paramref name="other" />.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static ulong LowestCommonMultiple(this ulong value, ulong other)
{
if (value == 0 || other == 0)
{
return 0;
}
if (value == 1)
{
return other;
}
if (other == 1)
{
return value;
}
return value * other / value.GreatestCommonFactor(other);
}
/// <summary>
/// Returns the multiplicative persistence of a specified value.
/// </summary>
@ -117,32 +88,4 @@ public static class UInt64Extensions
return persistence;
}
/// <summary>
/// Wraps the current 64-bit unsigned integer between a low and a high value.
/// </summary>
/// <param name="value">The value to wrap.</param>
/// <param name="low">The inclusive lower bound.</param>
/// <param name="high">The exclusive upper bound.</param>
/// <returns>The wrapped value.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static ulong Wrap(this ulong value, ulong low, ulong high)
{
ulong difference = high - low;
return low + (((value - low) % difference) + difference) % difference;
}
/// <summary>
/// Wraps the current 64-bit unsigned integer between 0 and a high value.
/// </summary>
/// <param name="value">The value to wrap.</param>
/// <param name="length">The exclusive upper bound.</param>
/// <returns>The wrapped value.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static ulong Wrap(this ulong value, ulong length)
{
return ((value % length) + length) % length;
}
}