nd4j-common/src/main/java/org/nd4j/linalg/util/BigDecimalMath.java
static public BigDecimal addRound(final BigDecimal x, final BigDecimal y) {
        BigDecimal resul = x.add(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 addRound(final BigDecimal x, final BigDecimal y) {
        BigDecimal resul = x.add(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 addRound ( final BigDecimal x , final BigDecimal y ) { BigDecimal resul = x . add ( 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 ) ; }
Add and round according to the larger of the two ulp’s.

@param x The left summand
@param y The right summand
@return The sum x+y.
Add and round according to the larger of the two ulp’s .