From 16dd3512553a06306a69a2f5da1595fc762112b3 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Sun, 19 Jul 2009 20:58:35 +0000 Subject: [PATCH] Added NextPowerOfTwo float and double overloads. --- Source/OpenTK/Math/Functions.cs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/Source/OpenTK/Math/Functions.cs b/Source/OpenTK/Math/Functions.cs index 00dd9396..5c9f3f22 100644 --- a/Source/OpenTK/Math/Functions.cs +++ b/Source/OpenTK/Math/Functions.cs @@ -48,7 +48,38 @@ namespace OpenTK #endregion - /// /// Calculates the factorial of a given natural number. + #region public static int NextPowerOfTwo(int n) + + /// + /// Returns the next power of two that is larger than the specified number. + /// + /// The specified number. + /// The next power of two. + public static float NextPowerOfTwo(float n) + { + if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive."); + return (float)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2))); + } + + #endregion + + + #region public static int NextPowerOfTwo(int n) + + /// + /// Returns the next power of two that is larger than the specified number. + /// + /// The specified number. + /// The next power of two. + public static double NextPowerOfTwo(double n) + { + if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive."); + return System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2))); + } + + #endregion + + /// Calculates the factorial of a given natural number. /// /// The number. /// n!