@Test public void testOneLargeIntArg() throws Exception { Minus minus = new Minus(); assertEquals(-33000000000L, minus.execute(rhsFuncContext, Symbols.asList(syms, 33000000000L)).asInteger().getValue()); }
@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(); return i != null ? syms.createInteger(-i.getValue()) : syms.createDouble(-arg.asDouble().getValue()); } long i = 0; double f = 0; boolean float_found = false; IntegerSymbol ic = arg.asInteger(); if(ic != null) { i = ic.getValue(); } else { float_found = true; f = arg.asDouble().getValue(); } for(int index = 1; index < arguments.size(); ++index) { arg = arguments.get(index); ic = arg.asInteger(); if(ic != null) { if(float_found) { f -= ic.getValue(); } else { i -= ic.getValue(); } } else { if(float_found) { f -= arg.asDouble().getValue(); } else { float_found = true; f = i - arg.asDouble().getValue(); } } } return float_found ? syms.createDouble(f) : syms.createInteger(i); }
Minus 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(); return i != null ? syms.createInteger(-i.getValue()) : syms.createDouble(-arg.asDouble().getValue()); } long i = 0; double f = 0; boolean float_found = false; IntegerSymbol ic = arg.asInteger(); if(ic != null) { i = ic.getValue(); } else { float_found = true; f = arg.asDouble().getValue(); } for(int index = 1; index < arguments.size(); ++index) { arg = arguments.get(index); ic = arg.asInteger(); if(ic != null) { if(float_found) { f -= ic.getValue(); } else { i -= ic.getValue(); } } else { if(float_found) { f -= arg.asDouble().getValue(); } else { float_found = true; f = i - arg.asDouble().getValue(); } } } return float_found ? syms.createDouble(f) : syms.createInteger(i); } }
Minus 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(); return i != null ? syms.createInteger(-i.getValue()) : syms.createDouble(-arg.asDouble().getValue()); } long i = 0; double f = 0; boolean float_found = false; IntegerSymbol ic = arg.asInteger(); if(ic != null) { i = ic.getValue(); } else { float_found = true; f = arg.asDouble().getValue(); } for(int index = 1; index < arguments.size(); ++index) { arg = arguments.get(index); ic = arg.asInteger(); if(ic != null) { if(float_found) { f -= ic.getValue(); } else { i -= ic.getValue(); } } else { if(float_found) { f -= arg.asDouble().getValue(); } else { float_found = true; f = i - arg.asDouble().getValue(); } } } return float_found ? syms.createDouble(f) : syms.createInteger(i); } Minus(); }
Minus 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(); return i != null ? syms.createInteger(-i.getValue()) : syms.createDouble(-arg.asDouble().getValue()); } long i = 0; double f = 0; boolean float_found = false; IntegerSymbol ic = arg.asInteger(); if(ic != null) { i = ic.getValue(); } else { float_found = true; f = arg.asDouble().getValue(); } for(int index = 1; index < arguments.size(); ++index) { arg = arguments.get(index); ic = arg.asInteger(); if(ic != null) { if(float_found) { f -= ic.getValue(); } else { i -= ic.getValue(); } } else { if(float_found) { f -= arg.asDouble().getValue(); } else { float_found = true; f = i - arg.asDouble().getValue(); } } } return float_found ? syms.createDouble(f) : syms.createInteger(i); } Minus(); @Override Symbol execute(RhsFunctionContext context, List<Symbol> arguments); }
Minus 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(); return i != null ? syms.createInteger(-i.getValue()) : syms.createDouble(-arg.asDouble().getValue()); } long i = 0; double f = 0; boolean float_found = false; IntegerSymbol ic = arg.asInteger(); if(ic != null) { i = ic.getValue(); } else { float_found = true; f = arg.asDouble().getValue(); } for(int index = 1; index < arguments.size(); ++index) { arg = arguments.get(index); ic = arg.asInteger(); if(ic != null) { if(float_found) { f -= ic.getValue(); } else { i -= ic.getValue(); } } else { if(float_found) { f -= arg.asDouble().getValue(); } else { float_found = true; f = i - arg.asDouble().getValue(); } } } return float_found ? syms.createDouble(f) : syms.createInteger(i); } Minus(); @Override Symbol execute(RhsFunctionContext context, List<Symbol> arguments);  }