public static DoubleToSortableLong ( double val ) : long | ||
val | double | |
return | long |
public virtual void TestSortableDoubleNaN() { long plusInf = NumericUtils.DoubleToSortableLong(double.PositiveInfinity); foreach (double nan in DOUBLE_NANs) { Assert.IsTrue(double.IsNaN(nan)); long sortable = NumericUtils.DoubleToSortableLong(nan); Assert.IsTrue((ulong)sortable > (ulong)plusInf, "Double not sorted correctly: " + nan + ", long repr: " + sortable + ", positive inf.: " + plusInf); } }
public virtual void TestDoubles() { double[] vals = new double[] { double.NegativeInfinity, -2.3E25, -1.0E15, -1.0, -1.0E-1, -1.0E-2, -0.0, +0.0, 1.0E-2, 1.0E-1, 1.0, 1.0E15, 2.3E25, double.PositiveInfinity, double.NaN }; long[] longVals = new long[vals.Length]; // check forward and back conversion for (int i = 0; i < vals.Length; i++) { longVals[i] = NumericUtils.DoubleToSortableLong(vals[i]); Assert.IsTrue(vals[i].CompareTo(NumericUtils.SortableLongToDouble(longVals[i])) == 0, "forward and back conversion should generate same double"); } // check sort order (prefixVals should be ascending) for (int i = 1; i < longVals.Length; i++) { Assert.IsTrue(longVals[i - 1] < longVals[i], "check sort order"); } }