mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Replace PVS dictionaries with memory magic (#4795)
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
@@ -697,6 +697,32 @@ namespace Robust.Shared.Maths
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Round up (ceiling) a value to a multiple of a known power of two.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to round up.</param>
|
||||
/// <param name="powerOfTwo">
|
||||
/// The power of two to round up to a multiple of. The result is undefined if this is not a power of two.
|
||||
/// </param>
|
||||
/// <remarks>
|
||||
/// The result is undefined if either value is negative.
|
||||
/// </remarks>
|
||||
/// <typeparam name="T">The type of integer to operate on.</typeparam>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// MathHelper.CeilMultiplyPowerOfTwo(5, 4) // 8
|
||||
/// MathHelper.CeilMultiplyPowerOfTwo(4, 4) // 4
|
||||
/// MathHelper.CeilMultiplyPowerOfTwo(8, 4) // 8
|
||||
/// </code>
|
||||
/// </example>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static T CeilMultipleOfPowerOfTwo<T>(T value, T powerOfTwo) where T : IBinaryInteger<T>
|
||||
{
|
||||
var mask = powerOfTwo - T.One;
|
||||
var remainder = value & mask;
|
||||
return remainder == T.Zero ? value : (value | mask) + T.One;
|
||||
}
|
||||
|
||||
#endregion Public Members
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user