public static FloatToSortableInt ( float val ) : int | ||
val | float | |
Résultat | int |
public virtual void TestSortableFloatNaN() { int plusInf = NumericUtils.FloatToSortableInt(float.PositiveInfinity); foreach (float nan in FLOAT_NANs) { Assert.IsTrue(float.IsNaN(nan)); uint sortable = (uint)NumericUtils.FloatToSortableInt(nan); Assert.IsTrue(sortable > plusInf, "Float not sorted correctly: " + nan + ", int repr: " + sortable + ", positive inf.: " + plusInf); } }
public virtual void TestFloats() { float[] vals = new float[] { float.NegativeInfinity, -2.3E25f, -1.0E15f, -1.0f, -1.0E-1f, -1.0E-2f, -0.0f, +0.0f, 1.0E-2f, 1.0E-1f, 1.0f, 1.0E15f, 2.3E25f, float.PositiveInfinity, float.NaN }; int[] intVals = new int[vals.Length]; // check forward and back conversion for (int i = 0; i < vals.Length; i++) { intVals[i] = NumericUtils.FloatToSortableInt(vals[i]); Assert.IsTrue(vals[i].CompareTo(NumericUtils.SortableIntToFloat(intVals[i])) == 0, "forward and back conversion should generate same double"); } // check sort order (prefixVals should be ascending) for (int i = 1; i < intVals.Length; i++) { Assert.IsTrue(intVals[i - 1] < intVals[i], "check sort order"); } }