Class RoundingUtils

java.lang.Object
ubic.gemma.core.util.RoundingUtils

public final class RoundingUtils extends Object
Rounding of floating-point payloads on their way into JSON.

Gemma's expression data descends from 16-bit measurements, and these are values that get plotted, not values anything recomputes from. The digits this drops are also incompressible, which makes them costliest exactly where the payload is largest: measured on gemma2, /datasets/1/mean-variance goes from 883 KB to 346 KB decompressed, and from 382.6 KB to 101.0 KB gzipped. Say which of the two you mean whenever you quote a size here — conflating them has already produced one wrong conclusion.

Significant digits, not decimal places: expression values, p-values and t-statistics span orders of magnitude, and a p-value of 1e-300 has to survive. That rules out the Math.round(v * 1000) / 1000 shape used for the bounded [-1, 1] sample-correlation matrix.

This is the JSON counterpart of TsvUtils.format(double), which emits the same four significant digits for every file writer. File output does not route through here.

Author:
paul
  • Field Details

    • JSON_SIGNIFICANT_DIGITS

      public static final int JSON_SIGNIFICANT_DIGITS
      Significant digits kept in JSON responses.
      See Also:
  • Method Details

    • round

      public static double round(double v)
      Round to JSON_SIGNIFICANT_DIGITS significant digits.

      NaN and the infinities are returned untouched: they have no BigDecimal representation, and the 0.0 that a naive rounding puts in their place reads as a measured zero rather than "not known". Signed zero keeps its sign.

    • round

      @Nullable public static Double round(@Nullable Double v)
      Null-tolerant round(double), for boxed value-object fields.
    • roundedCopy

      @Nullable public static double[] roundedCopy(@Nullable double[] src)
      Round every element into a new array.

      Copies rather than rounding in place: the arrays handed to value objects are frequently the loaded entity's or the cached matrix's own backing store, and rounding those corrupts what the next reader sees.

    • roundedCopy

      @Nullable public static double[][] roundedCopy(@Nullable double[][] src)
      Row-by-row roundedCopy(double[]); see it for why this copies.