Ejemplo n.º 1
0
        public static int Acos(int x)
        {
            // Return 0 for invalid values
            if (x < -One || x > One)
            {
                FixedUtil.InvalidArgument("Fixed32.Acos", "x", x);
                return(0);
            }

            // Compute Atan2(Sqrt((1+x) * (1-x)), x), using s32.32.
            long xx = (long)(One + x) * (long)(One - x);
            long y  = Fixed64.Sqrt(xx);

            return((int)(Fixed64.Atan2(y, (long)x << 16) >> 16));
        }
Ejemplo n.º 2
0
 public void TestSqrt()
 {
     for (int i = 0; i < d_test_values.Length; ++i)
     {
         Fixed64 fi       = d_test_values[i];
         Fixed64 fs       = fi; Fixed64.Sqrt(ref fs, out fs);
         Double  result   = fs.ToDouble();
         Double  expected = Math.Sqrt(d_test_values[i]);
         if (Double.IsNaN(expected))
         {
             Assert.That(result, Is.EqualTo(0));
         }
         else
         {
             Fixed64 f = expected;
             Assert.That(f.ToDouble(), Is.EqualTo(expected).Within(MathsTests.TestTolerance));            // double check storage
             Assert.That(result,
                         Is.EqualTo(expected).Within(MathsTests.TestTolerance).                           // Check that result is within test tolerance for Fixed64
                         Or.EqualTo(expected).Within(MathsTests.PercentageTolerance * Math.Abs(result))); // or that result is within test percentage for Fixed64.
         }
     }
 }
Ejemplo n.º 3
0
 public static F64 Length(F64Vec4 a)
 {
     return(F64.FromRaw(Fixed64.Sqrt(Fixed64.Mul(a.RawX, a.RawX) + Fixed64.Mul(a.RawY, a.RawY) + Fixed64.Mul(a.RawZ, a.RawZ) + Fixed64.Mul(a.RawW, a.RawW))));
 }
Ejemplo n.º 4
0
 public static F64Vec4 Sqrt(F64Vec4 a)
 {
     return(new F64Vec4(Fixed64.Sqrt(a.RawX), Fixed64.Sqrt(a.RawY), Fixed64.Sqrt(a.RawZ), Fixed64.Sqrt(a.RawW)));
 }
Ejemplo n.º 5
0
 public static F64Vec3 Sqrt(F64Vec3 a)
 {
     return(new F64Vec3(Fixed64.Sqrt(a.RawX), Fixed64.Sqrt(a.RawY), Fixed64.Sqrt(a.RawZ)));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Gets the square root.
 /// </summary>
 /// <param name="number">The number to get the square root from.</param>
 /// <returns></returns>
 public static Fixed64 Sqrt(Fixed64 number)
 {
     return(Fixed64.Sqrt(number));
 }
Ejemplo n.º 7
0
 public static F64 Sqrt(F64 a)
 {
     return(FromRaw(Fixed64.Sqrt(a.Raw)));
 }
Ejemplo n.º 8
0
 public static F64Vec2 Sqrt(F64Vec2 a)
 {
     return(new F64Vec2(Fixed64.Sqrt(a.RawX), Fixed64.Sqrt(a.RawY)));
 }
Ejemplo n.º 9
0
 public static F64 Length(F64Vec2 a) { return F64.FromRaw(Fixed64.Sqrt(Fixed64.Mul(a.RawX, a.RawX) + Fixed64.Mul(a.RawY, a.RawY))); }
Ejemplo n.º 10
0
 public static F32 Length(F32Vec3 a)
 {
     return(F32.FromRaw((int)(Fixed64.Sqrt((long)a.RawX * (long)a.RawX + (long)a.RawY * (long)a.RawY + (long)a.RawZ * (long)a.RawZ) >> 16)));
 }