MCPcopy Create free account
hub / github.com/dynjs/dynjs / add

Method add

src/main/java/org/dynjs/ir/Interpreter.java:221–246  ·  view source on GitHub ↗
(ExecutionContext context, Object lhs, Object rhs)

Source from the content-addressed store, hash-verified

219
220 // FIXME: This breaks for non-numeric uses if isSubtraction
221 private static Object add(ExecutionContext context, Object lhs, Object rhs) {
222 if (lhs instanceof String || rhs instanceof String) {
223 return(Types.toString(context, lhs) + Types.toString(context, rhs));
224 }
225
226 Number lhsNum = Types.toNumber(context, lhs);
227 Number rhsNum = Types.toNumber(context, rhs);
228
229 if (Double.isNaN(lhsNum.doubleValue()) || Double.isNaN(rhsNum.doubleValue())) {
230 return(Double.NaN);
231 }
232
233 if (lhsNum instanceof Double || rhsNum instanceof Double) {
234 if (lhsNum.doubleValue() == 0.0 && rhsNum.doubleValue() == 0.0) {
235 if (Double.compare(lhsNum.doubleValue(), 0.0) < 0 && Double.compare(rhsNum.doubleValue(), 0.0) < 0) {
236 return(-0.0);
237 } else {
238 return(0.0);
239 }
240 }
241
242 return(lhsNum.doubleValue() - rhsNum.doubleValue());
243 }
244
245 return(lhsNum.longValue() + rhsNum.longValue());
246 }
247
248 private static Object sub(ExecutionContext context, Object lhs, Object rhs) {
249 if (lhs instanceof String || rhs instanceof String) {

Callers 1

executeMethod · 0.95

Calls 4

toStringMethod · 0.95
toNumberMethod · 0.95
compareMethod · 0.80
isNaNMethod · 0.45

Tested by

no test coverage detected