public static uint _mfvc_impl(CpuThreadState cpuThreadState, VfpuControlRegistersEnum vfpuControlRegister) { Console.Error.WriteLine("Warning: _mfvc_impl"); switch (vfpuControlRegister) { case VfpuControlRegistersEnum.VfpuPfxs: return(cpuThreadState.PrefixSource.Value); case VfpuControlRegistersEnum.VfpuPfxt: return(cpuThreadState.PrefixTarget.Value); case VfpuControlRegistersEnum.VfpuPfxd: return(cpuThreadState.PrefixDestination.Value); case VfpuControlRegistersEnum.VfpuCc: return(cpuThreadState.VfrCcValue); case VfpuControlRegistersEnum.VfpuRcx0: return((uint)MathFloat.ReinterpretFloatAsInt((float)new Random().NextDouble())); case VfpuControlRegistersEnum.VfpuRcx1: case VfpuControlRegistersEnum.VfpuRcx2: case VfpuControlRegistersEnum.VfpuRcx3: case VfpuControlRegistersEnum.VfpuRcx4: case VfpuControlRegistersEnum.VfpuRcx5: case VfpuControlRegistersEnum.VfpuRcx6: case VfpuControlRegistersEnum.VfpuRcx7: return((uint)MathFloat.ReinterpretFloatAsInt(1.0f)); default: throw new NotImplementedException("_mfvc_impl: " + vfpuControlRegister); } }
public static int _vf2iz(float value, int imm5) { var scalabValue = MathFloat.Scalb(value, imm5); var doubleValue = value >= 0 ? MathFloat.Floor(scalabValue) : MathFloat.Ceil(scalabValue); return(double.IsNaN(doubleValue) ? 0x7FFFFFFF : doubleValue); }
public float getConcentration(float x, float z) //"based" on the model from the article that Gustav sent us { float distPow2 = MathFloat.Pow(x - xCord, 2) + MathFloat.Pow(z - zCord, 2); //calculates the dist^2 just to make the next row more readable float c = i_0 + max * MathFloat.Exp(-distPow2 / d); //calculatates c return(c); }
void HandleWallCollision() { Vector2 direction = new Vector2(mDeltaVelocity.x > 0f ? 1f : -1f, 0f); RaycastHit2D[] collisionResults = new RaycastHit2D[5]; int collisionCount = Physics2D.BoxCastNonAlloc(mPosition, mPlayerSize, 0f, direction, collisionResults, Mathf.Abs(mDeltaVelocity.x), CollisionLayer); bool collisionHappened = false; if (collisionCount > 0) { for (int index = 0; index < collisionCount; index++) { float yDistance = collisionResults[index].point.y - mPosition.y; float xSign = collisionResults[index].point.x < mPosition.x ? -1f : 1f; if ((Mathf.Abs(yDistance) < (mHalfPlayerSize.y - 0.0001f)) && (xSign == direction.x)) { mWallDirection = (int)xSign; collisionHappened = mWallCollision = true; mDeltaVelocity.x = mVelocity.x = 0f; mPosition.x = MathFloat.Round(collisionResults[index].point.x - (mHalfPlayerSize.x * direction.x), 2); break; } } } if (!collisionHappened) { mWallCollision = false; } }
public static void CheckVfpuRegister(string opcode, int regIndex, uint pc, float value) { //if (float.IsNaN(Value)) { Console.WriteLine("VFPU_SET:{0:X4}:{1}:VR{2}:{3:X8}:{4},", pc, opcode, regIndex, MathFloat.ReinterpretFloatAsUInt(value), value); } }
protected void CalculateNextLocation(IPointAdapter location) { float dX = v * dT * MathFloat.Cos(angle), dZ = v * dT * MathFloat.Sin(angle); while (location.GetX() + dX > 14 || location.GetX() + dX < -14 || location.GetZ() + dZ > 14 || location.GetZ() + dZ < -14) { angle = CalculateTumbleAngle(); dX = v * dT * MathFloat.Cos(angle); dZ = v * dT * MathFloat.Sin(angle); } location.Add(dX, dZ); }
static public void _cvt_w_s_impl(CpuThreadState CpuThreadState, int FD, int FS) { //Console.WriteLine("_cvt_w_s_impl: {0}", CpuThreadState.FPR[FS]); switch (CpuThreadState.Fcr31.RM) { case CpuThreadState.FCR31.TypeEnum.Rint: CpuThreadState.FPR_I[FD] = (int)MathFloat.Rint(CpuThreadState.FPR[FS]); break; case CpuThreadState.FCR31.TypeEnum.Cast: CpuThreadState.FPR_I[FD] = (int)CpuThreadState.FPR[FS]; break; case CpuThreadState.FCR31.TypeEnum.Ceil: CpuThreadState.FPR_I[FD] = (int)MathFloat.Ceil(CpuThreadState.FPR[FS]); break; case CpuThreadState.FCR31.TypeEnum.Floor: CpuThreadState.FPR_I[FD] = (int)MathFloat.Floor(CpuThreadState.FPR[FS]); break; } }
static Quaternion() { if (typeof(T) == typeof(float)) { math = new MathFloat() as Math <T>; } else if (typeof(T) == typeof(double)) { math = new MathDouble() as Math <T>; } if (math == null) { throw new InvalidOperationException("Type " + typeof(T) + " is not supported by Quaternion."); } }
static Transform() { if (typeof(T) == typeof(float)) { math = new MathFloat() as Math <T>; } if (typeof(T) == typeof(double)) { math = new MathDouble() as Math <T>; } if (math == null) { throw new InvalidOperationException("Type " + typeof(T) + " is not supported by Transform."); } }
public void SendControllerFrame() { SceCtrlData.X = 0; SceCtrlData.Y = 0; bool AnalogXUpdated = false; bool AnalogYUpdated = false; if (AnalogUp) { AnalogY -= 0.4f; AnalogYUpdated = true; } if (AnalogDown) { AnalogY += 0.4f; AnalogYUpdated = true; } if (AnalogLeft) { AnalogX -= 0.4f; AnalogXUpdated = true; } if (AnalogRight) { AnalogX += 0.4f; AnalogXUpdated = true; } if (!AnalogXUpdated) { AnalogX /= 2.0f; } if (!AnalogYUpdated) { AnalogY /= 2.0f; } AnalogX = MathFloat.Clamp(AnalogX, -1.0f, 1.0f); AnalogY = MathFloat.Clamp(AnalogY, -1.0f, 1.0f); //Console.WriteLine("{0}, {1}", AnalogX, AnalogY); SceCtrlData.X = AnalogX; SceCtrlData.Y = AnalogY; PspController.InsertSceCtrlData(SceCtrlData); //Console.WriteLine("CommonGuiInput.SendControllerFrame()"); }
private Vector3Adapter CalculateNextPoint(float x, float z, AbstractEnvironment environment) { //calculates the angle that the cell should move towards based on the ligand gradient float alfa = MathFloat.Atan2(environment.GradZ(x, z), environment.GradX(x, z)); float factor = 1 - smartnessFactor; //calculates the x and z delta based on the angle and the sampled value float dx = MathFloat.Cos(alfa) * dT * v + (float)Normal.Sample(0.0, v * dT * factor); float dz = MathFloat.Sin(alfa) * dT * v + (float)Normal.Sample(0.0, v * dT * factor); //adds the delta to the x and z cords while making sure that it does not move outside the dish x = MathFloat.Clamp(x + dx, -14, 14); z = MathFloat.Clamp(z + dz, -14, 14); //create the new point return(new Vector3Adapter(x, z)); }
public static int _cvt_w_s_impl(CpuThreadState cpuThreadState, float fs) { //Console.WriteLine("_cvt_w_s_impl: {0}", CpuThreadState.FPR[FS]); switch (cpuThreadState.Fcr31.Rm) { case CpuThreadState.Fcr31Struct.TypeEnum.Rint: return((int)MathFloat.Rint(fs)); case CpuThreadState.Fcr31Struct.TypeEnum.Cast: return((int)MathFloat.Cast(fs)); case CpuThreadState.Fcr31Struct.TypeEnum.Ceil: return((int)MathFloat.Ceil(fs)); case CpuThreadState.Fcr31Struct.TypeEnum.Floor: return((int)MathFloat.Floor(fs)); } throw new InvalidCastException("RM has an invalid value!!"); //case CpuThreadState.FCR31.TypeEnum.Floor: CpuThreadState.FPR_I[FD] = (int)MathFloat.Floor(CpuThreadState.FPR[FS]); break; }
public void SendControllerFrame() { if (IGuiExternalInterface.IsInitialized()) { SceCtrlData.X = 0; SceCtrlData.Y = 0; bool AnalogXUpdated = false; bool AnalogYUpdated = false; if (AnalogUp) { AnalogY -= 0.1f; AnalogYUpdated = true; } if (AnalogDown) { AnalogY += 0.1f; AnalogYUpdated = true; } if (AnalogLeft) { AnalogX -= 0.1f; AnalogXUpdated = true; } if (AnalogRight) { AnalogX += 0.1f; AnalogXUpdated = true; } if (!AnalogXUpdated) { AnalogX /= 2.0f; } if (!AnalogYUpdated) { AnalogY /= 2.0f; } AnalogX = MathFloat.Clamp(AnalogX, -1.0f, 1.0f); AnalogY = MathFloat.Clamp(AnalogY, -1.0f, 1.0f); //Console.WriteLine("{0}, {1}", AnalogX, AnalogY); SceCtrlData.X = AnalogX; SceCtrlData.Y = AnalogY; this.PspController.InsertSceCtrlData(SceCtrlData); } }
static void DelegatesMath() { OverMath math = new OverMath(); MathInt mathInt = math.Plus; Console.WriteLine(n1 + " + " + n2 + " = " + mathInt(n1, n2)); mathInt = math.Minus; Console.WriteLine(n1 + " - " + n2 + " = " + mathInt(n1, n2)); mathInt = math.Gange; Console.WriteLine(n1 + " * " + n2 + " = " + mathInt(n1, n2)); mathInt = math.Dividere; Console.WriteLine(n1 + " / " + n2 + " = " + mathInt(n1, n2)); mathInt = math.Potens; Console.WriteLine(n1 + "^" + n2 + " = " + mathInt(n1, n2)); MathFloat mathFloat = math.Plus; Console.WriteLine(n3 + " + " + n4 + " = " + mathFloat(n3, n4)); mathFloat = math.Minus; Console.WriteLine(n3 + " - " + n4 + " = " + mathFloat(n3, n4)); mathFloat = math.Gange; Console.WriteLine(n3 + " * " + n4 + " = " + mathFloat(n3, n4)); mathFloat = math.Dividere; Console.WriteLine(n3 + " / " + n4 + " = " + mathFloat(n3, n4)); mathFloat = math.Potens; Console.WriteLine(n3 + "^" + n4 + " = " + mathFloat(n3, n4)); MathString mathString = math.Plus; Console.WriteLine(n5 + " + " + n6 + " = " + mathString(n5, n6)); mathString = math.Minus; Console.WriteLine(n5 + " - " + n6 + " = " + mathString(n5, n6)); mathString = math.Gange; Console.WriteLine(n5 + " * " + n6 + " = " + mathString(n5, n6)); mathString = math.Dividere; Console.WriteLine(n5 + " / " + n6 + " = " + mathString(n5, n6)); mathString = math.Potens; Console.WriteLine(n5 + "^" + n6 + " = " + mathString(n5, n6)); Math1Int math1Int = math.Kvadratrod; Math1Float math1Float = math.Kvadratrod; Math1String math1String = math.Kvadratrod; Console.WriteLine("Kvadratroden af 64 = " + math1Int((int)64)); Console.WriteLine("Kvadratroden af 9 = " + math1Float((float)9)); Console.WriteLine("Kvadratroden af 625 = " + math1String("625")); }
//Method that returns the number of cells that are within a given distance of the given location //only to be used with cells that have a ForwardsInternals as their internals (since iteration does not make sense otherwise) public int GetNumOfCloseCells(int iteration, float distance, IPointAdapter location) { int num = 0; distance *= distance; //removes the need for sqrt operation foreach (Cell cell in cells[iteration]) { if (!(cell.GetInternals() is ForwardInternals)) { continue; } IPointAdapter cellLocation = ((ForwardInternals)cell.GetInternals()).GetPosition(iteration); if (MathFloat.Pow(cellLocation.GetX() - location.GetX(), 2) + MathFloat.Pow(cellLocation.GetZ() - location.GetZ(), 2) <= distance) { num++; } } return(num); }
public static float ToFloat(int imm16) { var s = (imm16 >> 15) & 0x00000001; // Sign var e = (imm16 >> 10) & 0x0000001f; // Exponent var f = (imm16 >> 0) & 0x000003ff; // Fraction // Need to handle 0x7C00 INF and 0xFC00 -INF? if (e == 0) { // Need to handle +-0 case f==0 or f=0x8000? if (f == 0) { // Plus or minus zero return(MathFloat.ReinterpretIntAsFloat(s << 31)); } // Denormalized number -- renormalize it while ((f & 0x00000400) == 0) { f <<= 1; e -= 1; } e += 1; f &= ~0x00000400; } else if (e == 31) { if (f == 0) { // Inf return(MathFloat.ReinterpretIntAsFloat((s << 31) | 0x7f800000)); } // NaN return(MathFloat.ReinterpretIntAsFloat((s << 31) | 0x7f800000 | (f << 13))); } e = e + (127 - 15); f = f << 13; return(MathFloat.ReinterpretIntAsFloat((s << 31) | (e << 23) | f)); }
//public ushort Value; // //public bool Sign { get { return BitUtils.Extract(Value, 15, 1) != 0; } } //public uint Exponent { get { return BitUtils.Extract(Value, 10, 5); } } //public uint Fraction { get { return BitUtils.Extract(Value, 0, 10); } } //public static ushort FloatToHalfFloat(float f) //{ // return FloatToHalfFloat(MathFloat.ReinterpretFloatAsUInt(f)); //} // //public static ushort FloatToHalfFloat(uint f) //{ // const uint f32infty = 255 << 23; // const uint f16infty = 31 << 23; // const uint magic = 15 << 23; // // const uint round_mask = ~0xfffu; // const uint sign_mask = 0x80000000u; // // ushort o; // // uint sign = f & sign_mask; // f ^= sign; // // // Inf or NaN (all exponent bits set) // if (f >= f32infty) // { // o = (ushort)((f > f32infty) ? 0x7e00 : 0x7c00); // NaN->qNaN and Inf->Inf // } // // (De)normalized number or zero // else // { // f &= round_mask; // f = MathFloat.ReinterpretFloatAsUInt(MathFloat.ReinterpretUIntAsFloat(f) * MathFloat.ReinterpretUIntAsFloat(magic)); // f -= round_mask; // if (f > f16infty) f = f16infty; // Clamp to signed infinity if overflowed // // o = (ushort)(f >> 13); // Take the bits! // } // // o |= (ushort)(sign >> 16); // return o; //} public static int FloatToHalfFloat(float Float) { var i = MathFloat.ReinterpretFloatAsInt(Float); var s = ((i >> 16) & 0x00008000); // sign var e = ((i >> 23) & 0x000000ff) - (127 - 15); // exponent var f = ((i >> 0) & 0x007fffff); // fraction // need to handle NaNs and Inf? if (e <= 0) { if (e < -10) { if (s != 0) { // handle -0.0 return(0x8000); } return(0); } f = (f | 0x00800000) >> (1 - e); return(s | (f >> 13)); } else if (e == 0xff - (127 - 15)) { if (f == 0) { // Inf return(s | 0x7c00); } // NAN f >>= 13; return(s | 0x7c00 | f | ((f == 0) ? 1 : 0)); } if (e > 30) { // Overflow return(s | 0x7c00); } return(s | (e << 10) | (f >> 13)); }
void HandleGroundCollisions() { float ySpeed = mVelocity.y < 0f ? mDeltaVelocity.y : -0.02f; Vector2 direction = new Vector2(0f, mDeltaVelocity.y > 0f ? 1f : -1f); RaycastHit2D[] collisionResults = new RaycastHit2D[5]; int collisionCount = Physics2D.BoxCastNonAlloc(mPosition, mPlayerSize, 0f, direction, collisionResults, Mathf.Abs(ySpeed), CollisionLayer); bool collisionHappened = false; if (collisionCount > 0) { RaycastHit2D collision; mGrounded = true; for (int index = 0; index < collisionCount; index++) { collision = collisionResults[index]; float xDistance = collision.point.x - mPosition.x; if (Mathf.Abs(xDistance) < (mHalfPlayerSize.x - 0.0001f)) { collisionHappened = mGrounded = true; mDeltaVelocity.y = mVelocity.y = 0f; mPosition.y = MathFloat.Round(collision.collider.bounds.max.y + mHalfPlayerSize.y, 2); break; } } if ((false == collisionHappened) && (mVelocity.y < 0f)) { mGrounded = false; } } else { mGrounded = false; } }
public void floor_w_s() => AdvancePC().SetFD_I(MathFloat.Floor(FS));
public void ceil_w_s() => AdvancePC().SetFD_I(MathFloat.Ceil(FS));
public void round_w_s() => AdvancePC().SetFD_I(MathFloat.Round(FS));
public void trunc_w_s() => AdvancePC().SetFD_I(MathFloat.Cast(FS));
public void abs_s() => AdvancePC().SetFD(MathFloat.Abs(FS));
public void sqrt_s() => AdvancePC().SetFD(MathFloat.Sqrt(FS));
public void SetSmartnessFactor(float smartnessFactor) { this.smartnessFactor = MathFloat.Clamp(smartnessFactor, 0, 1); }
public float GradZ(float x, float z) { float dist = -MathFloat.Pow(x - xCord, 2) - MathFloat.Pow(z - zCord, 2); return(-2 * MathFloat.Exp(dist / d) * (z - zCord) / d); }