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

Method sub

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

Source from the content-addressed store, hash-verified

246 }
247
248 private static Object sub(ExecutionContext context, Object lhs, Object rhs) {
249 if (lhs instanceof String || rhs instanceof String) {
250 return(Double.NaN);
251 }
252
253 Number lhsNum = Types.toNumber(context, lhs);
254 Number rhsNum = Types.toNumber(context, rhs);
255
256 if (Double.isNaN(lhsNum.doubleValue()) || Double.isNaN(rhsNum.doubleValue())) {
257 return(Double.NaN);
258 }
259
260 if (lhsNum instanceof Double || rhsNum instanceof Double) {
261 if (lhsNum.doubleValue() == 0.0 && rhsNum.doubleValue() == 0.0) {
262 if (Double.compare(lhsNum.doubleValue(), 0.0) < 0 && Double.compare(rhsNum.doubleValue(), 0.0) < 0) {
263 return(-0.0);
264 } else {
265 return(0.0);
266 }
267 }
268
269 return(lhsNum.doubleValue() - rhsNum.doubleValue());
270 }
271
272 return(lhsNum.longValue() - rhsNum.longValue());
273 }
274}

Callers 1

executeMethod · 0.95

Calls 3

toNumberMethod · 0.95
compareMethod · 0.80
isNaNMethod · 0.45

Tested by

no test coverage detected