Beispiel #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));
        }
Beispiel #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.
         }
     }
 }
Beispiel #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))));
 }
Beispiel #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)));
 }
 public static F64Vec3 Sqrt(F64Vec3 a)
 {
     return(new F64Vec3(Fixed64.Sqrt(a.RawX), Fixed64.Sqrt(a.RawY), Fixed64.Sqrt(a.RawZ)));
 }
Beispiel #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));
 }
Beispiel #7
0
 public static F64 Sqrt(F64 a)
 {
     return(FromRaw(Fixed64.Sqrt(a.Raw)));
 }
 public static F64Vec2 Sqrt(F64Vec2 a)
 {
     return(new F64Vec2(Fixed64.Sqrt(a.RawX), Fixed64.Sqrt(a.RawY)));
 }
Beispiel #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))); }
Beispiel #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)));
 }