Class Numerics

java.lang.Object
com.quantfinlib.stats.Numerics

public final class Numerics extends Object
Small array and scalar helpers: clamping, NaN-filled arrays, the half-life decay factor and an allocation-free paired sort.

Added in 2.4.0 as the home of these helpers from util.MathUtils (removed in 3.0); behaviour is unchanged.

Since:
2.4.0
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    clamp(double v, double lo, double hi)
    max(lo, min(hi, v)); NaN in gives NaN out, and lo > hi is not checked.
    static double
    decayFactor(long dtNanos, long halfLifeNanos)
    Exponential decay factor for a half-life over an elapsed interval: exp(-dt·ln2/halfLife); 1.0 for non-positive dt.
    static double[]
    nanArray(int n)
    A new array of length n filled with NaN.
    static void
    pairSort(double[] keys, int[] values)
    Sorts keys ascending while permuting values identically — the primitive replacement for boxing an Integer[] index array through a comparator sort (no allocation beyond the caller's arrays, no boxed compares).

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • pairSort

      public static void pairSort(double[] keys, int[] values)
      Sorts keys ascending while permuting values identically — the primitive replacement for boxing an Integer[] index array through a comparator sort (no allocation beyond the caller's arrays, no boxed compares). Quicksort with median-of-three pivots and an insertion cutoff; NaN keys are not supported (callers filter NaN before ranking/selecting).
    • clamp

      public static double clamp(double v, double lo, double hi)
      max(lo, min(hi, v)); NaN in gives NaN out, and lo > hi is not checked.
    • nanArray

      public static double[] nanArray(int n)
      A new array of length n filled with NaN.
    • decayFactor

      public static double decayFactor(long dtNanos, long halfLifeNanos)
      Exponential decay factor for a half-life over an elapsed interval: exp(-dt·ln2/halfLife); 1.0 for non-positive dt. The single home for the half-life→decay conversion the streaming estimators use — the ln2 factor is exactly the constant that goes missing when this is re-spelled per class.