Exemplo n.º 1
0
    @Override
    public Item ev(final InputInfo ii, final Item a, final Item b) throws QueryException {

      final Type ta = a.type, tb = b.type;
      final boolean t1 = ta.isNumber() || ta.isUntyped();
      final boolean t2 = tb.isNumber() || tb.isUntyped();
      if (t1 ^ t2) errNum(ii, !t1 ? a : b);
      if (t1 && t2) {
        final Type t = type(ta, tb);
        if (t == ITR) {
          final long l1 = a.itr(ii);
          final long l2 = b.itr(ii);
          checkRange(ii, l1 - (double) l2);
          return Int.get(l1 - l2);
        }
        if (t == DBL) return Dbl.get(a.dbl(ii) - b.dbl(ii));
        if (t == FLT) return Flt.get(a.flt(ii) - b.flt(ii));
        return Dec.get(a.dec(ii).subtract(b.dec(ii)));
      }

      if (ta == tb) {
        if (ta == DTM || ta == DAT || ta == TIM) return new DTd((Date) a, (Date) b);
        if (ta == YMD) return new YMd((YMd) a, (YMd) b, false);
        if (ta == DTD) return new DTd((DTd) a, (DTd) b, false);
        errNum(ii, !t1 ? a : b);
      }
      if (ta == DTM) return new Dtm((Date) a, checkDur(ii, b), false, ii);
      if (ta == DAT) return new Dat((Date) a, checkDur(ii, b), false, ii);
      if (ta == TIM) {
        if (tb != DTD) errType(ii, DTD, b);
        return new Tim((Tim) a, (DTd) b, false, ii);
      }
      errType(ii, ta, b);
      return null;
    }
Exemplo n.º 2
0
    @Override
    public Item ev(final InputInfo ii, final Item a, final Item b) throws QueryException {

      checkNum(ii, a, b);
      final double d1 = a.dbl(ii);
      final double d2 = b.dbl(ii);
      if (d2 == 0) DIVZERO.thrw(ii, a);
      final double d = d1 / d2;
      if (Double.isNaN(d) || Double.isInfinite(d)) DIVFLOW.thrw(ii, d1, d2);
      return Int.get(type(a.type, b.type) == ITR ? a.itr(ii) / b.itr(ii) : (long) d);
    }
Exemplo n.º 3
0
    @Override
    public Item ev(final InputInfo ii, final Item a, final Item b) throws QueryException {

      checkNum(ii, a, b);
      final Type t = type(a.type, b.type);
      if (t == DBL) return Dbl.get(a.dbl(ii) % b.dbl(ii));
      if (t == FLT) return Flt.get(a.flt(ii) % b.flt(ii));
      if (t == ITR) {
        final long b1 = a.itr(ii);
        final long b2 = b.itr(ii);
        if (b2 == 0) DIVZERO.thrw(ii, a);
        return Int.get(b1 % b2);
      }

      final BigDecimal b1 = a.dec(ii);
      final BigDecimal b2 = b.dec(ii);
      if (b2.signum() == 0) DIVZERO.thrw(ii, a);
      final BigDecimal q = b1.divide(b2, 0, BigDecimal.ROUND_DOWN);
      return Dec.get(b1.subtract(q.multiply(b2)));
    }
Exemplo n.º 4
0
    @Override
    public Item ev(final InputInfo ii, final Item a, final Item b) throws QueryException {

      final Type ta = a.type, tb = b.type;
      if (ta == YMD) {
        if (!tb.isNumber()) errNum(ii, b);
        return new YMd((Dur) a, b.dbl(ii), true, ii);
      }
      if (tb == YMD) {
        if (!ta.isNumber()) errNum(ii, a);
        return new YMd((Dur) b, a.dbl(ii), true, ii);
      }
      if (ta == DTD) {
        if (!tb.isNumber()) errNum(ii, b);
        return new DTd((Dur) a, b.dbl(ii), true, ii);
      }
      if (tb == DTD) {
        if (!ta.isNumber()) errNum(ii, a);
        return new DTd((Dur) b, a.dbl(ii), true, ii);
      }

      final boolean t1 = ta.isNumber() || ta.isUntyped();
      final boolean t2 = tb.isNumber() || tb.isUntyped();
      if (t1 ^ t2) errType(ii, ta, b);
      if (t1 && t2) {
        final Type t = type(ta, tb);
        if (t == ITR) {
          final long l1 = a.itr(ii);
          final long l2 = b.itr(ii);
          checkRange(ii, l1 * (double) l2);
          return Int.get(l1 * l2);
        }
        if (t == DBL) return Dbl.get(a.dbl(ii) * b.dbl(ii));
        if (t == FLT) return Flt.get(a.flt(ii) * b.flt(ii));
        return Dec.get(a.dec(ii).multiply(b.dec(ii)));
      }
      errNum(ii, !t1 ? a : b);
      return null;
    }