@Test public void testMaxWithAllIntegers() throws Exception { final Max max = new Max(); final Symbol result = max.execute(rhsFuncContext, Symbols.asList(syms, 2, 1, -40, 99)); assertEquals(99, result.asInteger().getValue()); }
@Override public Symbol execute(RhsFunctionContext context, List<Symbol> arguments) throws RhsFunctionException { RhsFunctions.checkAllArgumentsAreNumeric(getName(), arguments); long maxInt = Long.MIN_VALUE; double maxDouble = Double.MIN_VALUE; boolean useDouble = false; for(Symbol s : arguments) { final IntegerSymbol i = s.asInteger(); if(i != null) { if(useDouble) { if(i.getValue() > maxDouble) { maxInt = i.getValue(); useDouble = false; } } else { maxInt = Math.max(maxInt, i.getValue()); } } else { final DoubleSymbol d = s.asDouble(); if(useDouble) { maxDouble = Math.max(maxDouble, d.getValue()); } else { if(d.getValue() > maxInt) { maxDouble = d.getValue(); useDouble = true; } } } } return useDouble ? context.getSymbols().createDouble(maxDouble) : context.getSymbols().createInteger(maxInt); }
Max extends AbstractRhsFunctionHandler { @Override public Symbol execute(RhsFunctionContext context, List<Symbol> arguments) throws RhsFunctionException { RhsFunctions.checkAllArgumentsAreNumeric(getName(), arguments); long maxInt = Long.MIN_VALUE; double maxDouble = Double.MIN_VALUE; boolean useDouble = false; for(Symbol s : arguments) { final IntegerSymbol i = s.asInteger(); if(i != null) { if(useDouble) { if(i.getValue() > maxDouble) { maxInt = i.getValue(); useDouble = false; } } else { maxInt = Math.max(maxInt, i.getValue()); } } else { final DoubleSymbol d = s.asDouble(); if(useDouble) { maxDouble = Math.max(maxDouble, d.getValue()); } else { if(d.getValue() > maxInt) { maxDouble = d.getValue(); useDouble = true; } } } } return useDouble ? context.getSymbols().createDouble(maxDouble) : context.getSymbols().createInteger(maxInt); } }
Max extends AbstractRhsFunctionHandler { @Override public Symbol execute(RhsFunctionContext context, List<Symbol> arguments) throws RhsFunctionException { RhsFunctions.checkAllArgumentsAreNumeric(getName(), arguments); long maxInt = Long.MIN_VALUE; double maxDouble = Double.MIN_VALUE; boolean useDouble = false; for(Symbol s : arguments) { final IntegerSymbol i = s.asInteger(); if(i != null) { if(useDouble) { if(i.getValue() > maxDouble) { maxInt = i.getValue(); useDouble = false; } } else { maxInt = Math.max(maxInt, i.getValue()); } } else { final DoubleSymbol d = s.asDouble(); if(useDouble) { maxDouble = Math.max(maxDouble, d.getValue()); } else { if(d.getValue() > maxInt) { maxDouble = d.getValue(); useDouble = true; } } } } return useDouble ? context.getSymbols().createDouble(maxDouble) : context.getSymbols().createInteger(maxInt); } Max(); }
Max extends AbstractRhsFunctionHandler { @Override public Symbol execute(RhsFunctionContext context, List<Symbol> arguments) throws RhsFunctionException { RhsFunctions.checkAllArgumentsAreNumeric(getName(), arguments); long maxInt = Long.MIN_VALUE; double maxDouble = Double.MIN_VALUE; boolean useDouble = false; for(Symbol s : arguments) { final IntegerSymbol i = s.asInteger(); if(i != null) { if(useDouble) { if(i.getValue() > maxDouble) { maxInt = i.getValue(); useDouble = false; } } else { maxInt = Math.max(maxInt, i.getValue()); } } else { final DoubleSymbol d = s.asDouble(); if(useDouble) { maxDouble = Math.max(maxDouble, d.getValue()); } else { if(d.getValue() > maxInt) { maxDouble = d.getValue(); useDouble = true; } } } } return useDouble ? context.getSymbols().createDouble(maxDouble) : context.getSymbols().createInteger(maxInt); } Max(); @Override Symbol execute(RhsFunctionContext context, List<Symbol> arguments); }
Max extends AbstractRhsFunctionHandler { @Override public Symbol execute(RhsFunctionContext context, List<Symbol> arguments) throws RhsFunctionException { RhsFunctions.checkAllArgumentsAreNumeric(getName(), arguments); long maxInt = Long.MIN_VALUE; double maxDouble = Double.MIN_VALUE; boolean useDouble = false; for(Symbol s : arguments) { final IntegerSymbol i = s.asInteger(); if(i != null) { if(useDouble) { if(i.getValue() > maxDouble) { maxInt = i.getValue(); useDouble = false; } } else { maxInt = Math.max(maxInt, i.getValue()); } } else { final DoubleSymbol d = s.asDouble(); if(useDouble) { maxDouble = Math.max(maxDouble, d.getValue()); } else { if(d.getValue() > maxInt) { maxDouble = d.getValue(); useDouble = true; } } } } return useDouble ? context.getSymbols().createDouble(maxDouble) : context.getSymbols().createInteger(maxInt); } Max(); @Override Symbol execute(RhsFunctionContext context, List<Symbol> arguments);  }