Esempio n. 1
0
        private const double   CardinalOffset  = CardinalSegment / 2.0; // offset the pieces by 1/2 their size

        public Direction GetCardinalDir()
        {
            var ang = Theta % (2 * Math.PI);

            if (ang < 0.0f) // convert -PI > PI to 0 > 2PI
            {
                ang += 2 * (float)Math.PI;
            }

            return((Direction)(Math.Floor((ang + CardinalOffset) / CardinalSegment) * 2 % 8));
        }
Esempio n. 2
0
        public static double NextPowerOfTwo(double n)
        {
            if (double.IsNaN(n) || double.IsInfinity(n))
            {
                throw new ArgumentOutOfRangeException(nameof(n), "Must be a number.");
            }
            if (n <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(n), "Must be positive.");
            }

            // Don't return negative powers of two, that's nonsense.
            if (n < 1)
            {
                return(1.0);
            }

            return(Math.Pow(2, Math.Floor(Math.Log(n, 2)) + 1));
        }
Esempio n. 3
0
 public static double Mod(double n, double d)
 {
     return(n - Math.Floor(n / d) * d);
 }
Esempio n. 4
0
 public static float Floor(float f) => (float)Math.Floor(f);