001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.op; 020 021import java.math.BigDecimal; 022 023import lucee.commons.math.MathUtil; 024import lucee.runtime.exp.PageException; 025 026public class NumericOpBigDecimal implements NumericOp { 027 028 029 public BigDecimal divideRef(Object left, Object right) throws PageException { 030 double r = Caster.toDoubleValue(right); 031 if(r==0d) 032 throw new ArithmeticException("Division by zero is not possible"); 033 return MathUtil.divide(Caster.toBigDecimal(left),Caster.toBigDecimal(right)); 034 } 035 036 public BigDecimal exponentRef(Object left, Object right) throws PageException { 037 return MathUtil.divide(Caster.toBigDecimal(left),Caster.toBigDecimal(right)); 038 } 039 040 public BigDecimal intdivRef(Object left, Object right) throws PageException { 041 return MathUtil.divide(Caster.toBigDecimal(left),Caster.toBigDecimal(right)); 042 } 043 044 public BigDecimal plusRef(Object left, Object right) throws PageException { 045 return MathUtil.add(Caster.toBigDecimal(left),Caster.toBigDecimal(right)); 046 } 047 048 public BigDecimal minusRef(Object left, Object right) throws PageException { 049 return MathUtil.subtract(Caster.toBigDecimal(left),Caster.toBigDecimal(right)); 050 } 051 052 public BigDecimal modulusRef(Object left, Object right) throws PageException { 053 return MathUtil.multiply(Caster.toBigDecimal(left),Caster.toBigDecimal(right)); /// ???? 054 } 055 056 057 public BigDecimal multiplyRef(Object left, Object right) throws PageException { 058 return MathUtil.multiply(Caster.toBigDecimal(left),Caster.toBigDecimal(right)); 059 } 060}