public static IFloat Atan2(IFloat F1, IFloat F2) { if (F2.Value == 0 && F1.Value == 0) { return((IFloat)0); } IFloat result = (IFloat)0; if (F2 > 0) { result = Atan(F1 / F2); } else if (F2 < 0) { if (F1 >= 0) { result = (PI - Atan(Abs(F1 / F2))); } else { result = (PI - Atan(Abs(F1 / F2))).Inverse; } } else { result = (F1 >= 0 ? PI : PI.Inverse) / IFloat.Create(2, true); } return(result); }
/// <summary> /// Create a fixed-int number from parts. For example, to create 1.5 pass in 1 and 500. /// </summary> /// <param name="PreDecimal">The number above the decimal. For 1.5, this would be 1.</param> /// <param name="PostDecimal">The number below the decimal, to three digits. /// For 1.5, this would be 500. For 1.005, this would be 5.</param> /// <returns>A fixed-int representation of the number parts</returns> public static IFloat FromParts(int PreDecimal, int PostDecimal) { IFloat f = IFloat.Create(PreDecimal, true); if (PostDecimal != 0) { f.Value += (IFloat.Create(PostDecimal) / 1000).Value; } return(f); }
private static IFloat sin_lookup(IFloat i, IFloat j) { if (j > 0 && j < IFloat.Create(10, false) && i < IFloat.Create(90, false)) { return(IFloat.Create(SIN_TABLE[i.Value], false) + ((IFloat.Create(SIN_TABLE[i.Value + 1], false) - IFloat.Create(SIN_TABLE[i.Value], false)) / IFloat.Create(10, false)) * j); } else { return(IFloat.Create(SIN_TABLE[i.Value], false)); } }
public static IFloat Asin(IFloat F) { bool isNegative = F < 0; F = Abs(F); if (F > IFloat.OneF) { throw new ArithmeticException("Bad Asin Input:" + F.AsFloat()); } IFloat f1 = mul(mul(mul(mul(IFloat.Create(145103 >> IFloat.SHIFT_AMOUNT, false), F) - IFloat.Create(599880 >> IFloat.SHIFT_AMOUNT, false), F) + IFloat.Create(1420468 >> IFloat.SHIFT_AMOUNT, false), F) - IFloat.Create(3592413 >> IFloat.SHIFT_AMOUNT, false), F) + IFloat.Create(26353447 >> IFloat.SHIFT_AMOUNT, false); IFloat f2 = PI / IFloat.Create(2, true) - (Sqrt(IFloat.OneF - F) * f1); return(isNegative ? f2.Inverse : f2); }
public static IFloat Sin(IFloat i) { IFloat j = (IFloat)0; for (; i < 0; i += IFloat.Create(25736, false)) { ; } if (i > IFloat.Create(25736, false)) { i %= IFloat.Create(25736, false); } IFloat k = (i * IFloat.Create(10, false)) / IFloat.Create(714, false); if (i != 0 && i != IFloat.Create(6434, false) && i != IFloat.Create(12868, false) && i != IFloat.Create(19302, false) && i != IFloat.Create(25736, false)) { j = (i * IFloat.Create(100, false)) / IFloat.Create(714, false) - k * IFloat.Create(10, false); } if (k <= IFloat.Create(90, false)) { return(sin_lookup(k, j)); } if (k <= IFloat.Create(180, false)) { return(sin_lookup(IFloat.Create(180, false) - k, j)); } if (k <= IFloat.Create(270, false)) { return(sin_lookup(k - IFloat.Create(180, false), j).Inverse); } else { return(sin_lookup(IFloat.Create(360, false) - k, j).Inverse); } }
public static IFloat deg2Rad(IFloat inputValue) { return(inputValue * IFloat.Create(71487, false) / 1000);; }
public static IVector2 Create(float x, float y) { return(IVector2.Create(IFloat.Create(x), IFloat.Create(y))); }
public static IFloat Cos(IFloat i) { return(Sin(i + IFloat.Create(6435, false))); }
public static IVector3 Create(float x, float y, float z) { return(IVector3.Create(IFloat.Create(x), IFloat.Create(y), IFloat.Create(z))); }
public static IVector3 Create(Vector3 v) { return(IVector3.Create(IFloat.Create(v.x), IFloat.Create(v.y), IFloat.Create(v.z))); }