package poly.op; import poly.*; import poly.factory.*; /** * Evaluates the host polynomial at a double input. Returns a Double. * @author Dung X. Nguyen * @since Copyright 2002 - DXN - All rights reserved */ public class EvalOp implements IPolyOp { public final static EvalOp Singleton = new EvalOp (); private EvalOp() { } /** * @param poly * @param inp an Double * @return the constant Double value of poly. */ public Object forConst(IConstPoly poly, Object inp) { return new Double(poly.getLeadCoef()); } /** * @param poly * @param inp an Double * @return the Double value of poly evaluated at inp. */ public Object forNonConst (INCPoly poly, Object inp) { double x = ((Double)inp).doubleValue(); double leadVal = poly.getLeadCoef() * Math.pow (x, poly.getOrder()); Double lowerVal = (Double)poly.getLowerPoly().execute(this, inp); return new Double(leadVal + lowerVal.doubleValue()); } }