public static float ReinterpretAsFloat(this int value) { IntFloat converter = default; converter.intValue = value; return(converter.floatValue); }
public static int ToInt(float value) { IntFloat uf = new IntFloat(); uf.FloatValue = value; return(uf.IntValue); }
public void SubtractionTest() { IntFloat two = FromInt(2); IntFloat threeHalf = FromFloat(3.5f); Assert.Equal(-1.5f, (two - threeHalf).toFloat); }
/* * public void InitMonsterStat(string name, float mass, float defense, float speed) * { * MonsterStat stat = new MonsterStat(); * stat.defense = defense; * stat.speed = speed; * stat.mass = mass; * * if (!monster_list.ContainsKey(name)) monster_list.Add(name, stat); * * } */ public void CalcStatsByWavelet(bool summary) { List <wave> waves = Moon.Instance.Waves; stats = new List <WaveStat>(); for (int wave_number = 0; wave_number < waves.Count; wave_number++) { wave w = waves[wave_number]; for (int wavelet_number = 0; wavelet_number < w.wavelets.Count; wavelet_number++) { InitWavelet wlet = w.wavelets[wavelet_number]; Dictionary <string, IntFloat> wavelet_count = new Dictionary <string, IntFloat>(); foreach (InitEnemyCount e in wlet.enemies) { IntFloat count = null; wavelet_count.TryGetValue(e.name, out count); if (count == null) { wavelet_count.Add(e.name, new IntFloat(e.c, wlet.interval * e.c)); } else { count.myInt += e.c; count.myFloat += wlet.interval * e.c; } } AssignWaveStat(wavelet_count, wave_number, wavelet_number); } } PrintStats(summary, true); }
public void MultiplicationTest() { IntFloat a = FromInt(10); IntFloat b = FromFloat(0.2f); Assert.Equal(2f, (a * b).toFloat); }
public static float ToSingle(int value) { IntFloat uf = new IntFloat(); uf.IntValue = value; return(uf.FloatValue); }
void IBinarySerializable.Read(ObjectBinaryReader reader, object context) { Field00 = reader.ReadInt32(); Field04 = reader.ReadInt32(); Field08 = reader.ReadInt32(); Field0C = reader.ReadInt32(); }
public void DivisionTestFour() { IntFloat a = new IntFloat(2125); IntFloat b = new IntFloat(98143); AreEqualWithinPrecision(0.212f / 9.8143f, a / b); }
public void AdditionTest() { IntFloat two = FromInt(2); IntFloat threeHalf = FromFloat(3.5f); Assert.Equal(5.5f, (two + threeHalf).toFloat); }
public void PlusPlusTest() { IntFloat a = One; a++; Assert.True(a == 2 * One); }
public void VectorMagnitudeTest() { IntFloat a = 3 * One; IntFloat b = 4 * One; Assert.True(Magnitude(a, b) == 5 * One); }
public void Pow() { IntFloat x = new BigInteger(2); IntFloat y = new BigInteger(600); if ( IntFloat.Pow(x, y) != BigInteger.Parse("41495155688809929585124078636911611510124462322424368999956573296906528114129" + "08146399707048947103794288197886611300789182395151075411775307886874834113963687061181803401509523685376") ) { Assert.Fail(); } x = 2.3; y = 333.4; IntFloat p = IntFloat.Pow(x, y); if (!p.IsFloat) { Assert.Fail(); } if (p != 3.981626592064194E+120) { Assert.Fail(); } }
/** * Reads floating point type stored in little endian (see readFloat() for * big endian) * <p/> * @return float value translated from little endian * <p/> * @throws IOException if an IO error occurs */ public float readLittleFloat() { IntFloat a = new IntFloat(); a.IntValue = readLittleInt(); return(a.FloatValue); }
public void DivisionTestOne() { IntFloat three = FromInt(3); IntFloat two = FromInt(2); Assert.Equal(1.5f, (three / two).toFloat); }
public void MultiplicationTestTwo() { IntFloat a = new IntFloat(365004); IntFloat b = new IntFloat(2012); AreEqualWithinPrecision(36.5004f * 0.2012f, a * b); }
public void DivisionTestThree() { IntFloat a = FromInt(10); IntFloat b = FromFloat(0.2f); Assert.Equal(50f, (a / b).toFloat); }
public void DivisionTestFive() { IntFloat a = new IntFloat(120000); IntFloat b = new IntFloat(20001); AreEqualWithinPrecision(12f / 2.0001f, a / b); }
private Single ToFloat(UInt32 x) { var intFloat = new IntFloat { UintValue = x }; return(intFloat.FloatValue); }
public void CosTestFour() { IntFloat y = new IntFloat(1732); // root 3 IntFloat x = FromInt(2); _outputHelper.WriteLine(Cos(-Pi + Pi / 6).ToString()); _outputHelper.WriteLine((-y / x).ToString()); AreEqualWithinPrecision(Cos(-Pi + Pi / 6), -y / x); }
public void Atan2TestOne() { IntFloat y = new IntFloat(1732); // root 3 IntFloat x = FromInt(3); _outputHelper.WriteLine((Pi / 6).ToString()); _outputHelper.WriteLine(Atan2(y, x).ToString()); AreEqualWithinPrecision(Pi / 6, Atan2(y, x)); }
public void Atan2TestThree() { IntFloat y = FromInt(3); IntFloat x = FromRaw(1732); _outputHelper.WriteLine((Pi / 3).ToString()); _outputHelper.WriteLine(Atan2(y, x).ToString()); AreEqualWithinPrecision(Pi / 3, Atan2(y, x)); }
public void Atan2TestFour() { IntFloat y = FromInt(-3); IntFloat x = FromInt(-3); _outputHelper.WriteLine((-3 * Pi / 4).ToString()); _outputHelper.WriteLine(Atan2(y, x).ToString()); AreEqualWithinPrecision(-3 * Pi / 4, Atan2(y, x)); }
public void SinTestThree() { IntFloat y = new IntFloat(1732); // root 3 IntFloat x = FromInt(2); _outputHelper.WriteLine(Sin(Pi / 3).ToString()); _outputHelper.WriteLine((y / x).ToString()); AreEqualWithinPrecision(Sin(Pi / 3), y / x); }
public void OverflowCheck() { IntFloat a = new IntFloat(202050365); IntFloat b = new IntFloat(200002012); Assert.Throws <OverflowException>(() => { IntFloat c = a * b; }); }
//Implementation based on: https://en.wikipedia.org/wiki/Fast_inverse_square_root public static float FastInvSqrRoot(float number) { var conv = new IntFloat { FloatValue = number }; float x2 = number * .5f; conv.IntValue = 0x5f3759df - (conv.IntValue >> 1); conv.FloatValue = conv.FloatValue * (1.5f - (x2 * conv.FloatValue * conv.FloatValue)); return(conv.FloatValue); }
private IntFloat IntFloatParse(string if2) { IntFloat intFloat = new IntFloat(); if2 = if2.Trim('(', ')'); string[] farray = if2.Split(','); if (farray.Length == 2) { intFloat.intValue = int.Parse(farray[0]); intFloat.floatValue = float.Parse(farray[1]); } return(intFloat); }
public static double BitsStringToDouble(string bits) { if (bits.Length != 4) return 0.0; IntFloat value = new IntFloat(); value.Byte1 = (byte)bits[0]; value.Byte2 = (byte)bits[1]; value.Byte3 = (byte)bits[2]; value.Byte4 = (byte)bits[3]; return (double)value.Float; }
//Implementation based on: https://en.wikipedia.org/wiki/Fast_inverse_square_root public static float FastInvSqrRoot(float number) { const float threehalfs = 1.5f; IntFloat conv = new IntFloat { FloatValue = number }; float x2 = number * .5f; conv.IntValue = 0x5f3759df - (conv.IntValue >> 1); conv.FloatValue = conv.FloatValue * (threehalfs - (x2 * conv.FloatValue * conv.FloatValue)); return(conv.FloatValue); }
public float[] readPackedFloats(int count, int size) { float[] data = new float[count * size]; byte[] tmp = readCompressedData(count * size * 4); //a Float is 4 bytes // Convert interleaved array to floats for (int i = 0; i < count; ++i) { for (int k = 0; k < size; ++k) { IntFloat a = new IntFloat(); a.IntValue = interleavedRetrive(tmp, i + k * count, count * size); data [i * size + k] = a.FloatValue; } } return(data); }
/** * Reads floating point type stored in little endian (see readFloat() for * big endian) * <p/> * @return float value translated from little endian * <p/> * @throws IOException if an IO error occurs */ public float readLittleFloat() { IntFloat a = new IntFloat (); a.IntValue = readLittleInt (); return a.FloatValue; }
public float[] readPackedFloats(int count, int size) { float[] data = new float[count * size]; byte[] tmp = readCompressedData (count * size * 4);//a Float is 4 bytes // Convert interleaved array to floats for (int i = 0; i < count; ++i) { for (int k = 0; k < size; ++k) { IntFloat a = new IntFloat (); a.IntValue = interleavedRetrive (tmp, i + k * count, count * size); data [i * size + k] = a.FloatValue; } } return data; }
private static float Noise(float x) { var intFloat = new IntFloat { FloatValue = x }; int xInt = intFloat.IntValue; x = (xInt << 13) ^ xInt; return 0.5f + (1f - ((xInt * (xInt * xInt * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824f) / 2f; }
/// <summary> /// Gets the binary representation of the specified single-precision floating point value. /// </summary> /// <param name="value">The value to convert to bytes.</param> /// <returns>The array that stores the binary representation.</returns> public static byte[] GetBytes( float value ) { var converter = new IntFloat(); converter.FloatValue = value; return GetBytes(converter.IntValue); }
/// <summary> /// Gets the single-precision floating point value from the binary representation. /// </summary> /// <param name="array">The array that stores the binary representation.</param> /// <param name="startIndex">The starting position within <paramref name="array"/>.</param> /// <returns>The value found.</returns> public static float ToSingle( byte[] array, int startIndex ) { var converter = new IntFloat(); converter.IntValue = ToInt32(array, startIndex); return converter.FloatValue; }
public static void AreEqualWithinPrecision(double f, IntFloat i) { Assert.True(Math.Abs(i.toDouble - f) < Epsilon); }
public static void AreEqualWithinPrecision(IntFloat a, IntFloat b) { Assert.True(Abs(a - b).rawValue <= 1); }
/// <summary> /// Gets the binary representation of the specified single-precision floating point value. /// </summary> /// <param name="value">The value to convert to bytes.</param> /// <param name="array">The array that stores the binary representation.</param> /// <param name="startIndex">The starting position within <paramref name="array"/>.</param> public static void GetBytes( float value, byte[] array, int startIndex ) { var converter = new IntFloat(); converter.FloatValue = value; GetBytes(converter.IntValue, array, startIndex); }