nd4j-common/src/main/java/org/nd4j/linalg/util/BigDecimalMath.java
static public BigDecimal subtractRound(final BigDecimal x, final BigDecimal y) {
        BigDecimal resul = x.subtract(y);
        /* The estimation of the absolute error in the result is |err(y)|+|err(x)|
         */


        double errR = Math.abs(y.ulp().doubleValue() / 2.) + Math.abs(x.ulp().doubleValue() / 2.);
        MathContext mc = new MathContext(err2prec(resul.doubleValue(), errR));


        return resul.round(mc);


    }
static public BigDecimal subtractRound(final BigDecimal x, final BigDecimal y) {
        BigDecimal resul = x.subtract(y);
        /* The estimation of the absolute error in the result is |err(y)|+|err(x)|
         */


        double errR = Math.abs(y.ulp().doubleValue() / 2.) + Math.abs(x.ulp().doubleValue() / 2.);
        MathContext mc = new MathContext(err2prec(resul.doubleValue(), errR));


        return resul.round(mc);


    }
static public BigDecimal subtractRound ( final BigDecimal x , final BigDecimal y ) { BigDecimal resul = x . subtract ( y ) ; /* The estimation of the absolute error in the result is |err(y)|+|err(x)|
         */ double errR = Math . abs ( y . ulp ( ) . doubleValue ( ) / 2. ) + Math . abs ( x . ulp ( ) . doubleValue ( ) / 2. ) ; MathContext mc = new MathContext ( err2prec ( resul . doubleValue ( ) , errR ) ) ; return resul . round ( mc ) ; }
Subtract and round according to the larger of the two ulp’s.

@param x The left term.
@param y The right term.
@return The difference x-y.
Subtract and round according to the larger of the two ulp’s .