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