| 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) { |