/// <summary> /// Divides two quantities. The same operations as for multiplication are supported. /// </summary> /// <param name="obj1">The first object.</param> /// <param name="obj2">The second object.</param> /// <returns>Result cast into object.</returns> public static object Div(object obj1, object obj2) { if (obj1.GetType() != obj2.GetType()) { throw new ArgumentException("Object are not of the same type."); } if (obj1 is BigNum) { return((BigNum)obj1 + (BigNum)obj2); } // Float version: if (obj1 is float) { return((float)obj1 / (float)obj2); } if (obj1 is Vector2f) { return(Vector2f.ComponentDivision((Vector2f)obj1, (Vector2f)obj2)); } if (obj1 is Vector3f) { return(Vector3f.ComponentDivision((Vector3f)obj1, (Vector3f)obj2)); } if (obj1 is Vector4f) { return(Vector4f.ComponentDivision((Vector4f)obj1, (Vector4f)obj2)); } if (obj1 is Matrix.Matrix2x2f) { return((Matrix.Matrix2x2f)obj1 / (Matrix.Matrix2x2f)obj2); } if (obj1 is Matrix.Matrix3x3f) { return((Matrix.Matrix3x3f)obj1 / (Matrix.Matrix3x3f)obj2); } if (obj1 is Matrix.Matrix4x4f) { return((Matrix.Matrix4x4f)obj1 / (Matrix.Matrix4x4f)obj2); } if (obj1 is Complexf) { return((Complexf)obj1 / (Complexf)obj2); } if (obj1 is Quaternionf) { return((Quaternionf)obj1 / (Quaternionf)obj2); } // Double version: if (obj1 is double) { return((double)obj1 / (double)obj2); } if (obj1 is Vector2d) { return(Vector2d.ComponentDivision((Vector2d)obj1, (Vector2d)obj2)); } if (obj1 is Vector3d) { return(Vector3d.ComponentDivision((Vector3d)obj1, (Vector3d)obj2)); } if (obj1 is Vector4d) { return(Vector4d.ComponentDivision((Vector4d)obj1, (Vector4d)obj2)); } if (obj1 is Matrix.Matrix2x2d) { return((Matrix.Matrix2x2d)obj1 / (Matrix.Matrix2x2d)obj2); } if (obj1 is Matrix.Matrix3x3d) { return((Matrix.Matrix3x3d)obj1 / (Matrix.Matrix3x3d)obj2); } if (obj1 is Matrix.Matrix4x4d) { return((Matrix.Matrix4x4d)obj1 / (Matrix.Matrix4x4d)obj2); } if (obj1 is Complexd) { return((Complexd)obj1 / (Complexd)obj2); } if (obj1 is Quaterniond) { return((Quaterniond)obj1 / (Quaterniond)obj2); } // Integer version: if (obj1 is int) { return((int)obj1 / (int)obj2); } // Other types. if (obj1 is uint) { return((uint)obj1 / (uint)obj2); } if (obj1 is short) { return((short)obj1 / (short)obj2); } if (obj1 is ushort) { return((ushort)obj1 / (ushort)obj2); } if (obj1 is byte) { return((byte)obj1 / (byte)obj2); } if (obj1 is ulong) { return((ulong)obj1 / (ulong)obj2); } if (obj1 is long) { return((long)obj1 / (long)obj2); } throw new NotSupportedException("Unsupported type " + obj1.GetType()); }