@Test(expected=RhsFunctionException.class) public void testZeroArgs() throws Exception { FloatingPointDivide divide = new FloatingPointDivide(); divide.execute(rhsFuncContext, Symbols.asList(syms)); }
@Override public Symbol execute(RhsFunctionContext context, List<Symbol> arguments) throws RhsFunctionException { RhsFunctions.checkAllArgumentsAreNumeric(getName(), arguments); RhsFunctions.checkArgumentCount(this, arguments); final SymbolFactory syms = context.getSymbols(); Symbol arg = arguments.get(0); if(arguments.size() == 1) { IntegerSymbol i = arg.asInteger(); double f = i != null ? i.getValue() : arg.asDouble().getValue(); if(f == 0.0) { throw new RhsFunctionException("Attempt to divide ('/') by zero"); } return syms.createDouble(1.0 / f); } double f = RhsFunctions.asDouble(arg); for(int index = 1; index < arguments.size(); ++index) { arg = arguments.get(index); double nextf = RhsFunctions.asDouble(arg); if(nextf == 0.0) { throw new RhsFunctionException("Attempt to divide ('/') by zero"); } f /= nextf; } return syms.createDouble(f); }
FloatingPointDivide extends AbstractRhsFunctionHandler { @Override public Symbol execute(RhsFunctionContext context, List<Symbol> arguments) throws RhsFunctionException { RhsFunctions.checkAllArgumentsAreNumeric(getName(), arguments); RhsFunctions.checkArgumentCount(this, arguments); final SymbolFactory syms = context.getSymbols(); Symbol arg = arguments.get(0); if(arguments.size() == 1) { IntegerSymbol i = arg.asInteger(); double f = i != null ? i.getValue() : arg.asDouble().getValue(); if(f == 0.0) { throw new RhsFunctionException("Attempt to divide ('/') by zero"); } return syms.createDouble(1.0 / f); } double f = RhsFunctions.asDouble(arg); for(int index = 1; index < arguments.size(); ++index) { arg = arguments.get(index); double nextf = RhsFunctions.asDouble(arg); if(nextf == 0.0) { throw new RhsFunctionException("Attempt to divide ('/') by zero"); } f /= nextf; } return syms.createDouble(f); } }
FloatingPointDivide extends AbstractRhsFunctionHandler { @Override public Symbol execute(RhsFunctionContext context, List<Symbol> arguments) throws RhsFunctionException { RhsFunctions.checkAllArgumentsAreNumeric(getName(), arguments); RhsFunctions.checkArgumentCount(this, arguments); final SymbolFactory syms = context.getSymbols(); Symbol arg = arguments.get(0); if(arguments.size() == 1) { IntegerSymbol i = arg.asInteger(); double f = i != null ? i.getValue() : arg.asDouble().getValue(); if(f == 0.0) { throw new RhsFunctionException("Attempt to divide ('/') by zero"); } return syms.createDouble(1.0 / f); } double f = RhsFunctions.asDouble(arg); for(int index = 1; index < arguments.size(); ++index) { arg = arguments.get(index); double nextf = RhsFunctions.asDouble(arg); if(nextf == 0.0) { throw new RhsFunctionException("Attempt to divide ('/') by zero"); } f /= nextf; } return syms.createDouble(f); } FloatingPointDivide(); }
FloatingPointDivide extends AbstractRhsFunctionHandler { @Override public Symbol execute(RhsFunctionContext context, List<Symbol> arguments) throws RhsFunctionException { RhsFunctions.checkAllArgumentsAreNumeric(getName(), arguments); RhsFunctions.checkArgumentCount(this, arguments); final SymbolFactory syms = context.getSymbols(); Symbol arg = arguments.get(0); if(arguments.size() == 1) { IntegerSymbol i = arg.asInteger(); double f = i != null ? i.getValue() : arg.asDouble().getValue(); if(f == 0.0) { throw new RhsFunctionException("Attempt to divide ('/') by zero"); } return syms.createDouble(1.0 / f); } double f = RhsFunctions.asDouble(arg); for(int index = 1; index < arguments.size(); ++index) { arg = arguments.get(index); double nextf = RhsFunctions.asDouble(arg); if(nextf == 0.0) { throw new RhsFunctionException("Attempt to divide ('/') by zero"); } f /= nextf; } return syms.createDouble(f); } FloatingPointDivide(); @Override Symbol execute(RhsFunctionContext context, List<Symbol> arguments); }
FloatingPointDivide extends AbstractRhsFunctionHandler { @Override public Symbol execute(RhsFunctionContext context, List<Symbol> arguments) throws RhsFunctionException { RhsFunctions.checkAllArgumentsAreNumeric(getName(), arguments); RhsFunctions.checkArgumentCount(this, arguments); final SymbolFactory syms = context.getSymbols(); Symbol arg = arguments.get(0); if(arguments.size() == 1) { IntegerSymbol i = arg.asInteger(); double f = i != null ? i.getValue() : arg.asDouble().getValue(); if(f == 0.0) { throw new RhsFunctionException("Attempt to divide ('/') by zero"); } return syms.createDouble(1.0 / f); } double f = RhsFunctions.asDouble(arg); for(int index = 1; index < arguments.size(); ++index) { arg = arguments.get(index); double nextf = RhsFunctions.asDouble(arg); if(nextf == 0.0) { throw new RhsFunctionException("Attempt to divide ('/') by zero"); } f /= nextf; } return syms.createDouble(f); } FloatingPointDivide(); @Override Symbol execute(RhsFunctionContext context, List<Symbol> arguments);  }