예제 #1
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);
    }
예제 #2
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)));
    }
예제 #3
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 == tb) {
        if (ta == YMD) {
          final BigDecimal bd = BigDecimal.valueOf(((YMd) b).ymd());
          if (bd.equals(BigDecimal.ZERO)) DATEZERO.thrw(ii, info());
          return Dec.get(
              BigDecimal.valueOf(((YMd) a).ymd()).divide(bd, 20, BigDecimal.ROUND_HALF_EVEN));
        }
        if (ta == DTD) {
          final BigDecimal bd = ((DTd) b).dtd();
          if (bd.equals(BigDecimal.ZERO)) DATEZERO.thrw(ii, info());
          return Dec.get(((DTd) a).dtd().divide(bd, 20, BigDecimal.ROUND_HALF_EVEN));
        }
      }
      if (ta == YMD) {
        if (!tb.isNumber()) errNum(ii, b);
        return new YMd((Dur) a, b.dbl(ii), false, ii);
      }
      if (ta == DTD) {
        if (!tb.isNumber()) errNum(ii, b);
        return new DTd((Dur) a, b.dbl(ii), false, ii);
      }

      checkNum(ii, a, b);
      final Type t = type(ta, tb);
      if (t == DBL) return Dbl.get(a.dbl(ii) / b.dbl(ii));
      if (t == FLT) return Flt.get(a.flt(ii) / b.flt(ii));

      final BigDecimal b1 = a.dec(ii);
      final BigDecimal b2 = b.dec(ii);
      if (b2.signum() == 0) DIVZERO.thrw(ii, a);
      final int s = Math.max(18, Math.max(b1.scale(), b2.scale()));
      return Dec.get(b1.divide(b2, s, BigDecimal.ROUND_HALF_EVEN));
    }