コード例 #1
0
ファイル: test_long2.cs プロジェクト: csritter/MaxMath
        public static void Constructor_Long()
        {
            long2 x = new long2(TestData_LHS[0].x);

            Assert.AreEqual(x.x == TestData_LHS[0].x &
                            x.y == TestData_LHS[0].x, true);
        }
コード例 #2
0
ファイル: long2x2.cs プロジェクト: xposure/Atma.Math
 /// <summary>
 /// Constructs this matrix from a series of column vectors. Non-overwritten fields are from an Identity matrix.
 /// </summary>
 public long2x2(long2 c0, long2 c1)
 {
     this.m00 = c0.x;
     this.m01 = c0.y;
     this.m10 = c1.x;
     this.m11 = c1.y;
 }
コード例 #3
0
 public void Constructors()
 {
     {
         var v = new long2(1);
         Assert.AreEqual(1, v.x);
         Assert.AreEqual(1, v.y);
     }
     {
         var v = new long2(3L, 5L);
         Assert.AreEqual(3L, v.x);
         Assert.AreEqual(5L, v.y);
     }
     {
         var v = new long2(new long2(-7L, -7L));
         Assert.AreEqual(-7L, v.x);
         Assert.AreEqual(-7L, v.y);
     }
     {
         var v = new long2(new long3(-3L, 6L, 6L));
         Assert.AreEqual(-3L, v.x);
         Assert.AreEqual(6L, v.y);
     }
     {
         var v = new long2(new long4(2L, 5L, -6L, -7L));
         Assert.AreEqual(2L, v.x);
         Assert.AreEqual(5L, v.y);
     }
 }
コード例 #4
0
        public void PropertyValues()
        {
            var v    = new long2(9L, -3L);
            var vals = v.Values;

            Assert.AreEqual(9L, vals[0]);
            Assert.AreEqual(-3L, vals[1]);
            Assert.That(vals.SequenceEqual(v.ToArray()));
        }
コード例 #5
0
        public void Indexer()
        {
            var v = new long2(-8L, -3L);

            Assert.AreEqual(-8L, v[0]);
            Assert.AreEqual(-3L, v[1]);

            Assert.Throws <ArgumentOutOfRangeException>(() => { var s = v[-2147483648]; });
            Assert.Throws <ArgumentOutOfRangeException>(() => { v[-2147483648] = 0; });
            Assert.Throws <ArgumentOutOfRangeException>(() => { var s = v[-1]; });
            Assert.Throws <ArgumentOutOfRangeException>(() => { v[-1] = 0; });
            Assert.Throws <ArgumentOutOfRangeException>(() => { var s = v[2]; });
            Assert.Throws <ArgumentOutOfRangeException>(() => { v[2] = 0; });
            Assert.Throws <ArgumentOutOfRangeException>(() => { var s = v[2147483647]; });
            Assert.Throws <ArgumentOutOfRangeException>(() => { v[2147483647] = 0; });
            Assert.Throws <ArgumentOutOfRangeException>(() => { var s = v[5]; });
            Assert.Throws <ArgumentOutOfRangeException>(() => { v[5] = 0; });

            v[0] = 0;
            Assert.AreEqual(0, v[0]);
            v[0] = 1;
            Assert.AreEqual(1, v[0]);
            v[1] = 2L;
            Assert.AreEqual(2L, v[1]);
            v[1] = 3L;
            Assert.AreEqual(3L, v[1]);
            v[0] = 4L;
            Assert.AreEqual(4L, v[0]);
            v[0] = 5L;
            Assert.AreEqual(5L, v[0]);
            v[1] = 6L;
            Assert.AreEqual(6L, v[1]);
            v[0] = 7L;
            Assert.AreEqual(7L, v[0]);
            v[0] = 8L;
            Assert.AreEqual(8L, v[0]);
            v[0] = 9L;
            Assert.AreEqual(9L, v[0]);
            v[1] = -1L;
            Assert.AreEqual(-1L, v[1]);
            v[0] = -2L;
            Assert.AreEqual(-2L, v[0]);
            v[1] = -3L;
            Assert.AreEqual(-3L, v[1]);
            v[0] = -4L;
            Assert.AreEqual(-4L, v[0]);
            v[0] = -5L;
            Assert.AreEqual(-5L, v[0]);
            v[0] = -6L;
            Assert.AreEqual(-6L, v[0]);
            v[1] = -7L;
            Assert.AreEqual(-7L, v[1]);
            v[1] = -8L;
            Assert.AreEqual(-8L, v[1]);
            v[0] = -9L;
            Assert.AreEqual(-9L, v[0]);
        }
コード例 #6
0
ファイル: long3x2.cs プロジェクト: xposure/Atma.Math
 /// <summary>
 /// Constructs this matrix from a series of column vectors. Non-overwritten fields are from an Identity matrix.
 /// </summary>
 public long3x2(long2 c0, long2 c1, long2 c2)
 {
     this.m00 = c0.x;
     this.m01 = c0.y;
     this.m10 = c1.x;
     this.m11 = c1.y;
     this.m20 = c2.x;
     this.m21 = c2.y;
 }
コード例 #7
0
ファイル: long3x2.cs プロジェクト: xposure/Atma.Math
 /// <summary>
 /// Constructs this matrix from a series of column vectors. Non-overwritten fields are from an Identity matrix.
 /// </summary>
 public long3x2(long2 c0, long2 c1)
 {
     this.m00 = c0.x;
     this.m01 = c0.y;
     this.m10 = c1.x;
     this.m11 = c1.y;
     this.m20 = 0;
     this.m21 = 0;
 }
コード例 #8
0
ファイル: long2x3.cs プロジェクト: xposure/Atma.Math
 /// <summary>
 /// Constructs this matrix from a series of column vectors. Non-overwritten fields are from an Identity matrix.
 /// </summary>
 public long2x3(long2 c0, long2 c1)
 {
     this.m00 = c0.x;
     this.m01 = c0.y;
     this.m02 = 0;
     this.m10 = c1.x;
     this.m11 = c1.y;
     this.m12 = 0;
 }
コード例 #9
0
        public void SerializationJson()
        {
            var v0 = new long2(7L, 5L);
            var s0 = JsonConvert.SerializeObject(v0);

            var v1 = JsonConvert.DeserializeObject <long2>(s0);
            var s1 = JsonConvert.SerializeObject(v1);

            Assert.AreEqual(v0, v1);
            Assert.AreEqual(s0, s1);
        }
コード例 #10
0
ファイル: lzcnt.cs プロジェクト: csritter/MaxMath
        public static void long2()
        {
            Random64 rng = new Random64(135);

            for (long i = 0; i < 64; i++)
            {
                long2 x = rng.NextLong2();

                Assert.AreEqual(new long2((long)math.lzcnt(x.x), (long)math.lzcnt(x.y)), maxmath.lzcnt(x));
            }
        }
コード例 #11
0
ファイル: long4x2.cs プロジェクト: xposure/Atma.Math
 /// <summary>
 /// Constructs this matrix from a series of column vectors. Non-overwritten fields are from an Identity matrix.
 /// </summary>
 public long4x2(long2 c0, long2 c1, long2 c2, long2 c3)
 {
     this.m00 = c0.x;
     this.m01 = c0.y;
     this.m10 = c1.x;
     this.m11 = c1.y;
     this.m20 = c2.x;
     this.m21 = c2.y;
     this.m30 = c3.x;
     this.m31 = c3.y;
 }
コード例 #12
0
        public static void long2()
        {
            Random64 rng = new Random64(135);

            for (long i = 0; i < 64; i++)
            {
                long2 x = rng.NextLong2();
                long2 y = rng.NextLong2();

                Assert.AreEqual(new ulong2((ulong)_gcd(x.x, y.x), (ulong)_gcd(x.y, y.y)), maxmath.gcd(x, y));
            }
        }
コード例 #13
0
        public static void long2()
        {
            Random64 rng = new Random64(135);

            for (long i = 0; i < 64; i++)
            {
                long2  x = rng.NextLong2();
                ulong2 n = rng.NextULong2();

                Assert.AreEqual(new long2((long)_intpow(x.x, n.x), (long)_intpow(x.y, n.y)), maxmath.intpow(x, n));
            }
        }
コード例 #14
0
 public void TriangleInequality()
 {
     {
         var v0 = new long2(-1L, 5L);
         var v1 = new long2(-9L, 6L);
         Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax);
     }
     {
         var v0 = new long2(-6L, -3L);
         var v1 = new long2(1, 1);
         Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax);
     }
     {
         var v0 = new long2(-5L, -8L);
         var v1 = new long2(1, 4L);
         Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax);
     }
     {
         var v0 = new long2(7L, -8L);
         var v1 = new long2(-3L, 5L);
         Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax);
     }
     {
         var v0 = new long2(2L, -8L);
         var v1 = new long2(2L, -6L);
         Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax);
     }
     {
         var v0 = new long2(-6L, 0);
         var v1 = new long2(3L, 2L);
         Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax);
     }
     {
         var v0 = new long2(0, 7L);
         var v1 = new long2(-5L, 2L);
         Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax);
     }
     {
         var v0 = new long2(-6L, -5L);
         var v1 = new long2(-5L, -6L);
         Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax);
     }
     {
         var v0 = new long2(-5L, -5L);
         var v1 = new long2(-7L, 5L);
         Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax);
     }
     {
         var v0 = new long2(9L, 8L);
         var v1 = new long2(9L, -6L);
         Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax);
     }
 }
コード例 #15
0
 public void InvariantCommutative()
 {
     {
         var v0 = new long2(5L, -6L);
         var v1 = new long2(-5L, -1L);
         Assert.AreEqual(v0 * v1, v1 * v0);
     }
     {
         var v0 = new long2(2L, 3L);
         var v1 = new long2(-8L, -1L);
         Assert.AreEqual(v0 * v1, v1 * v0);
     }
     {
         var v0 = new long2(-1L, -5L);
         var v1 = new long2(9L, 5L);
         Assert.AreEqual(v0 * v1, v1 * v0);
     }
     {
         var v0 = new long2(-5L, -5L);
         var v1 = new long2(3L, 0);
         Assert.AreEqual(v0 * v1, v1 * v0);
     }
     {
         var v0 = new long2(2L, 4L);
         var v1 = new long2(6L, 7L);
         Assert.AreEqual(v0 * v1, v1 * v0);
     }
     {
         var v0 = new long2(3L, -4L);
         var v1 = new long2(4L, 1);
         Assert.AreEqual(v0 * v1, v1 * v0);
     }
     {
         var v0 = new long2(-2L, -6L);
         var v1 = new long2(-4L, -7L);
         Assert.AreEqual(v0 * v1, v1 * v0);
     }
     {
         var v0 = new long2(7L, -5L);
         var v1 = new long2(-6L, -8L);
         Assert.AreEqual(v0 * v1, v1 * v0);
     }
     {
         var v0 = new long2(4L, 6L);
         var v1 = new long2(3L, 6L);
         Assert.AreEqual(v0 * v1, v1 * v0);
     }
     {
         var v0 = new long2(-3L, 6L);
         var v1 = new long2(5L, -1L);
         Assert.AreEqual(v0 * v1, v1 * v0);
     }
 }
コード例 #16
0
 public void InvariantCommutativeNeg()
 {
     {
         var v0 = new long2(-7L, -9L);
         var v1 = new long2(-4L, 0);
         Assert.AreEqual(v0 - v1, -(v1 - v0));
     }
     {
         var v0 = new long2(-3L, -5L);
         var v1 = new long2(3L, -1L);
         Assert.AreEqual(v0 - v1, -(v1 - v0));
     }
     {
         var v0 = new long2(9L, -6L);
         var v1 = new long2(9L, 8L);
         Assert.AreEqual(v0 - v1, -(v1 - v0));
     }
     {
         var v0 = new long2(3L, 3L);
         var v1 = new long2(-8L, 5L);
         Assert.AreEqual(v0 - v1, -(v1 - v0));
     }
     {
         var v0 = new long2(4L, -2L);
         var v1 = new long2(-6L, 2L);
         Assert.AreEqual(v0 - v1, -(v1 - v0));
     }
     {
         var v0 = new long2(7L, -3L);
         var v1 = new long2(7L, 5L);
         Assert.AreEqual(v0 - v1, -(v1 - v0));
     }
     {
         var v0 = new long2(7L, -2L);
         var v1 = new long2(-2L, -7L);
         Assert.AreEqual(v0 - v1, -(v1 - v0));
     }
     {
         var v0 = new long2(8L, -5L);
         var v1 = new long2(3L, -4L);
         Assert.AreEqual(v0 - v1, -(v1 - v0));
     }
     {
         var v0 = new long2(-5L, -6L);
         var v1 = new long2(3L, 0);
         Assert.AreEqual(v0 - v1, -(v1 - v0));
     }
     {
         var v0 = new long2(0, 2L);
         var v1 = new long2(8L, -1L);
         Assert.AreEqual(v0 - v1, -(v1 - v0));
     }
 }
コード例 #17
0
 /// <summary>
 /// Constructs this matrix from a series of column vectors. Non-overwritten fields are from an Identity matrix.
 /// </summary>
 public long3x3(long2 c0, long2 c1, long2 c2)
 {
     this.m00 = c0.x;
     this.m01 = c0.y;
     this.m02 = 0;
     this.m10 = c1.x;
     this.m11 = c1.y;
     this.m12 = 0;
     this.m20 = c2.x;
     this.m21 = c2.y;
     this.m22 = 1;
 }
コード例 #18
0
        public void Operators()
        {
            var v1 = new long2(9L, -8L);
            var v2 = new long2(9L, -8L);
            var v3 = new long2(-8L, 9L);

            Assert.That(v1 == new long2(v1));
            Assert.That(v2 == new long2(v2));
            Assert.That(v3 == new long2(v3));
            Assert.That(v1 == v2);
            Assert.That(v1 != v3);
            Assert.That(v2 != v3);
        }
コード例 #19
0
ファイル: sign.cs プロジェクト: csritter/MaxMath
        public static void Long2()
        {
            bool result = true;

            for (int i = 0; i < Tests.Long2.NUM_TESTS; i++)
            {
                long2 t = maxmath.sign(Tests.Long2.TestData_LHS[i]);

                result &= t.x == ((Tests.Long2.TestData_LHS[i].x == 0) ? 0 : ((Tests.Long2.TestData_LHS[i].x < 0) ? -1 : 1));
                result &= t.y == ((Tests.Long2.TestData_LHS[i].y == 0) ? 0 : ((Tests.Long2.TestData_LHS[i].y < 0) ? -1 : 1));
            }

            Assert.AreEqual(true, result);
        }
コード例 #20
0
ファイル: test_uint2.cs プロジェクト: csritter/MaxMath
        public static void Cast_ToLong()
        {
            bool result = true;

            for (uint i = 0; i < NUM_TESTS; i++)
            {
                long2 x = TestData_LHS[i];

                result &= x.x == (long)TestData_LHS[i].x &
                          x.y == (long)TestData_LHS[i].y;
            }

            Assert.AreEqual(true, result);
        }
コード例 #21
0
ファイル: test_long2.cs プロジェクト: csritter/MaxMath
        public static void Subtract()
        {
            bool result = true;

            for (int i = 0; i < NUM_TESTS; i++)
            {
                long2 x = TestData_LHS[i] - TestData_RHS[i];

                result &= x.x == (long)(TestData_LHS[i].x - TestData_RHS[i].x) &
                          x.y == (long)(TestData_LHS[i].y - TestData_RHS[i].y);
            }

            Assert.AreEqual(true, result);
        }
コード例 #22
0
        public static void Long2()
        {
            bool result = true;

            for (int i = 0; i < Tests.Long2.NUM_TESTS; i++)
            {
                long2 x = maxmath.abs(Tests.Long2.TestData_LHS[i]);

                result &= x.x == math.abs(Tests.Long2.TestData_LHS[i].x) &
                          x.y == math.abs(Tests.Long2.TestData_LHS[i].y);
            }

            Assert.AreEqual(true, result);
        }
コード例 #23
0
ファイル: test_long2.cs プロジェクト: csritter/MaxMath
        public static void NOT()
        {
            bool result = true;

            for (int i = 0; i < NUM_TESTS; i++)
            {
                long2 x = ~TestData_LHS[i];

                result &= x.x == (long)(~TestData_LHS[i].x) &
                          x.y == (long)(~TestData_LHS[i].y);
            }

            Assert.AreEqual(true, result);
        }
コード例 #24
0
ファイル: test_long2.cs プロジェクト: csritter/MaxMath
        public static void Remainder()
        {
            bool result = true;

            for (int i = 0; i < NUM_TESTS; i++)
            {
                long2 x = TestData_LHS[i] % TestData_RHS[i];

                result &= x.x == (long)(TestData_LHS[i].x % TestData_RHS[i].x) &
                          x.y == (long)(TestData_LHS[i].y % TestData_RHS[i].y);
            }

            Assert.AreEqual(true, result);
        }
コード例 #25
0
ファイル: test_long2.cs プロジェクト: csritter/MaxMath
        public static void ShuffleSetter()
        {
            bool result = true;

            for (int i = 0; i < NUM_TESTS; i++)
            {
                long2 yx = TestData_LHS[i];
                yx.yx   = TestData_RHS[i];
                result &= yx.x == TestData_RHS[i].y;
                result &= yx.y == TestData_RHS[i].x;
            }

            Assert.AreEqual(true, result);
        }
コード例 #26
0
        public void StringInterop()
        {
            var v = new long2(0, -3L);

            var s0 = v.ToString();
            var s1 = v.ToString("#");

            var v0 = long2.Parse(s0);
            var v1 = long2.Parse(s1, "#");

            Assert.AreEqual(v, v0);
            Assert.AreEqual(v, v1);

            var b0 = long2.TryParse(s0, out v0);
            var b1 = long2.TryParse(s1, "#", out v1);

            Assert.That(b0);
            Assert.That(b1);
            Assert.AreEqual(v, v0);
            Assert.AreEqual(v, v1);

            b0 = long2.TryParse(null, out v0);
            Assert.False(b0);
            b0 = long2.TryParse("", out v0);
            Assert.False(b0);
            b0 = long2.TryParse(s0 + ", 0", out v0);
            Assert.False(b0);

            Assert.Throws <NullReferenceException>(() => { long2.Parse(null); });
            Assert.Throws <FormatException>(() => { long2.Parse(""); });
            Assert.Throws <FormatException>(() => { long2.Parse(s0 + ", 0"); });

            var s2 = v.ToString(";", CultureInfo.InvariantCulture);

            Assert.That(s2.Length > 0);

            var s3 = v.ToString("; ", "G");
            var s4 = v.ToString("; ", "G", CultureInfo.InvariantCulture);
            var v3 = long2.Parse(s3, "; ", NumberStyles.Number);
            var v4 = long2.Parse(s4, "; ", NumberStyles.Number, CultureInfo.InvariantCulture);

            Assert.AreEqual(v, v3);
            Assert.AreEqual(v, v4);

            var b4 = long2.TryParse(s4, "; ", NumberStyles.Number, CultureInfo.InvariantCulture, out v4);

            Assert.That(b4);
            Assert.AreEqual(v, v4);
        }
コード例 #27
0
 /// <summary>
 /// Constructs this matrix from a series of column vectors. Non-overwritten fields are from an Identity matrix.
 /// </summary>
 public long3x4(long2 c0, long2 c1)
 {
     this.m00 = c0.x;
     this.m01 = c0.y;
     this.m02 = 0;
     this.m03 = 0;
     this.m10 = c1.x;
     this.m11 = c1.y;
     this.m12 = 0;
     this.m13 = 0;
     this.m20 = 0;
     this.m21 = 0;
     this.m22 = 1;
     this.m23 = 0;
 }
コード例 #28
0
        public static void Long2()
        {
            bool     result = true;
            Random32 x      = new Random32(47);

            for (int i = 0; i < Tests.Long2.NUM_TESTS; i++)
            {
                bool2 b = x.NextBool2();
                long2 a = maxmath.negate(Tests.Long2.TestData_LHS[i], b);

                result &= math.all(a == (maxmath.select(Tests.Long2.TestData_LHS[i], -Tests.Long2.TestData_LHS[i], b)));
            }

            Assert.AreEqual(true, result);
        }
コード例 #29
0
ファイル: long4x3.cs プロジェクト: xposure/Atma.Math
 /// <summary>
 /// Constructs this matrix from a series of column vectors. Non-overwritten fields are from an Identity matrix.
 /// </summary>
 public long4x3(long2 c0, long2 c1)
 {
     this.m00 = c0.x;
     this.m01 = c0.y;
     this.m02 = 0;
     this.m10 = c1.x;
     this.m11 = c1.y;
     this.m12 = 0;
     this.m20 = 0;
     this.m21 = 0;
     this.m22 = 1;
     this.m30 = 0;
     this.m31 = 0;
     this.m32 = 0;
 }
コード例 #30
0
ファイル: long4x3.cs プロジェクト: xposure/Atma.Math
 /// <summary>
 /// Constructs this matrix from a series of column vectors. Non-overwritten fields are from an Identity matrix.
 /// </summary>
 public long4x3(long2 c0, long2 c1, long2 c2, long2 c3)
 {
     this.m00 = c0.x;
     this.m01 = c0.y;
     this.m02 = 0;
     this.m10 = c1.x;
     this.m11 = c1.y;
     this.m12 = 0;
     this.m20 = c2.x;
     this.m21 = c2.y;
     this.m22 = 1;
     this.m30 = c3.x;
     this.m31 = c3.y;
     this.m32 = 0;
 }
コード例 #31
0
ファイル: DriverAPI.cs プロジェクト: lvaleriu/managedCuda
 public static extern CUResult cuMemcpyDtoH_v2(ref long2 dstHost, CUdeviceptr srcDevice, SizeT ByteCount);