public Object divide ( Object left , Object right ) { if ( left == null && right == null ) { return 0 ; } // if either are floating point (double or float) use double if ( isFloatingPointNumber ( left ) || isFloatingPointNumber ( right ) ) { double l = toDouble ( left ) ; double r = toDouble ( right ) ; if ( r == 0.0 ) { throw new ArithmeticException ( "/" ) ; } return new Double ( l / r ) ; } // if either are bigdecimal use that type if ( left instanceof BigDecimal || right instanceof BigDecimal ) { BigDecimal l = toBigDecimal ( left ) ; BigDecimal r = toBigDecimal ( right ) ; if ( BigDecimal . ZERO . equals ( r ) ) { throw new ArithmeticException ( "/" ) ; } BigDecimal result = l . divide ( r , getMathContext ( ) ) ; return narrowBigDecimal ( left , right , result ) ; } // otherwise treat as integers BigInteger l = toBigInteger ( left ) ; BigInteger r = toBigInteger ( right ) ; if ( BigInteger . ZERO . equals ( r ) ) { throw new ArithmeticException ( "/" ) ; } BigInteger result = l . divide ( r ) ; return narrowBigInteger ( left , right , result ) ; }
Divide the left value by the right .