Examples of Decimal128


Examples of macromedia.asc.util.Decimal128

  private NumberConstant getDecimalValueOrInt(String str, boolean force, TypeValue[] ppType) {
        // convert str into a decimal128 value. 
        // if force, return a decimal128 for sure, otherwise return int or uint if value will fit
        // check for NaN and Infinity
    Decimal128 dval;
        if (str.equals("NaN")) {
            ppType[0] = cx.decimalType();
            return new DecimalNumberConstant(Decimal128.NaN);
        }
        else if (str.equals("Infinity")){
            ppType[0] = cx.decimalType();
            return new DecimalNumberConstant(Decimal128.INFINITY);
        }
        else if (str.equals("-Infinity")){
            ppType[0] = cx.decimalType();
            return new DecimalNumberConstant(Decimal128.NEGINFINITY);
        }
            
        boolean isInt = false;
        if ((str.indexOf(".") > -1 || str.indexOf("e") > -1 ||
             str.indexOf("E") > -1 || str.length() > 10) &&
            !(str.indexOf("x") > -1 || str.indexOf("X") > -1)) {
            // looks like floating, and not hex
            dval = new Decimal128(str);
        }
        else {
            // looks like an integral value. It could be hex
            isInt = true;
            int base = 10;
            int startIndex = 0;
            int len = str.length();
            boolean negative = false;
            if (len > 1) {
                char c0 = str.charAt(startIndex);
                if ((c0 == '-') || (c0 == '+')) {
                    startIndex++;
                    if (c0 == '-')
                        negative = true;
                }
            }
            if (len > 2) {
                if ( str.charAt(startIndex) == '0') {
                    startIndex++;
                    char c0 = str.charAt(startIndex);
                    if ((c0 == 'x') || (c0 == 'X')) {
                        base = 16;
                        startIndex++;
                    }
                }
            }
            // skip leading zeros, but not the last one
            while (startIndex < (len-1) && str.charAt(startIndex) == '0')
                startIndex++;
            if (base == 10) {
                String str2 = str.substring(startIndex, len);
                dval = new Decimal128(str2);
            }
            else { // base == 16
                // can we really have hex constants for type decimal?
                int end, newDigit;
                if (D128_HEXDIGIT == null) {
                    // wow, somebody is creating a hex Decimal128 value.  We'll need digits
                    D128_HEXDIGIT = new Decimal128[16];
                    for (int ndx = 0; ndx < 16; ndx++) {
                        D128_HEXDIGIT[ndx] = new Decimal128(ndx);
                    }
                    D128_SIXTEEN = new Decimal128(16);
                }
                dval = Decimal128.ZERO;
                for (end = startIndex; end < len; end++) {
                    newDigit = unHex(str.charAt(end));
                    dval = D128_SIXTEEN.multiply(dval).add(D128_HEXDIGIT[newDigit]);
                }
             
            }
            // negate if needed
            if (negative) {
                if (dval.equals(Decimal128.ZERO)) {
                    dval = Decimal128.NEGZERO;
                    isInt = false;
                }
                else
                    dval = Decimal128.ZERO.subtract(dval);
            }
        }
        if (!force && isInt) {
            // value is integral.  See if it fits in a smaller type
            long ival = dval.longValue();
            if ((Integer.MIN_VALUE <= ival) && (ival <= Integer.MAX_VALUE)) {
                ppType[0] = cx.intType();
                return new IntNumberConstant((int)ival);
            }
            else if ((0 <= ival) && (ival <= MAXUINT)) {
                ppType[0] = cx.uintType();
                return new UintNumberConstant(ival);
            }
        }
        // either not integral or not small enough to fit in uint or int
        ppType[0] = cx.decimalType();
        // canonicalize NaN and Infinity
        if (dval.isNaN())
            dval = Decimal128.NaN;
        else if (!dval.isFinite()) {
            if (str.charAt(0) == '-')
                dval = Decimal128.NEGINFINITY;
            else
                dval = Decimal128.INFINITY;
        }
View Full Code Here

Examples of macromedia.asc.util.Decimal128

                Pushdouble( ab.code, index);
          }
        }
        else if (type_id == TYPE_decimal)
        {
          Decimal128 dval = val.decimalValue();
            int index = ab.addDecimalConstant(bytecodeFactory.ConstantDecimalInfo(dval));
            Pushdecimal( ab.code, index);
        }

        if (show_instructions)
View Full Code Here

Examples of macromedia.asc.util.Decimal128

        int pos = decimalpositions[index];
        int originalPos = in.pos();
        in.seek(pos);
        byte[] valbytes = in.readBytes(16);
        in.seek(originalPos);
        return new Decimal128(valbytes); // perhaps need to change endian
    }
View Full Code Here

Examples of macromedia.asc.util.Decimal128

            this.decimals = new Decimal128[size];

            for (int i = 1; i < size; i++)
            {
               byte[] rep = buf.readBytes(16);
               decimals[i] = new Decimal128(rep);
            }
        }

        size = buf.readU32();
        this.strings = new String[size];
View Full Code Here

Examples of org.apache.hadoop.hive.common.type.Decimal128

      assertEquals("checking long " + i, i, longColumn.vector[i]);
      assertEquals("checking float " + i, i, floatColumn.vector[i], 0.0001);
      assertEquals("checking double " + i, i, doubleCoulmn.vector[i], 0.0001);
      assertEquals("checking string " + i, new Text(Long.toHexString(i)),
          stringColumn.getWritableObject(i));
      assertEquals("checking decimal " + i, new Decimal128(i),
          decimalColumn.vector[i]);
      assertEquals("checking date " + i, i, dateColumn.vector[i]);
      long millis = (long) i * MILLIS_IN_DAY;
      millis -= LOCAL_TIMEZONE.getOffset(millis);
      assertEquals("checking timestamp " + i, millis * 1000000L,
 
View Full Code Here

Examples of org.apache.hadoop.hive.common.type.Decimal128

      scratch = new Decimal128FastBuffer();
    }

    private void doTestFastStreamForHiveDecimal(String valueString) {
      BigDecimal value = new BigDecimal(valueString);
      Decimal128 dec = new Decimal128();
      dec.update(value);

      HiveDecimalWritable witness = new HiveDecimalWritable();
      witness.set(HiveDecimal.create(value));

      int bufferUsed = dec.fastSerializeForHiveDecimal(scratch);
      HiveDecimalWritable hdw = new HiveDecimalWritable();
      hdw.set(scratch.getBytes(bufferUsed), dec.getScale());

      HiveDecimal hd = hdw.getHiveDecimal();

      BigDecimal readValue = hd.bigDecimalValue();

      Assert.assertEquals(value, readValue);

      // Now test fastUpdate from the same serialized HiveDecimal
      Decimal128 decRead = new Decimal128().fastUpdateFromInternalStorage(
              witness.getInternalStorage(), (short) witness.getScale());

      Assert.assertEquals(dec, decRead);

      // Test fastUpdate from it's own (not fully compacted) serialized output
      Decimal128 decReadSelf = new Decimal128().fastUpdateFromInternalStorage(
              hdw.getInternalStorage(), (short) hdw.getScale());
      Assert.assertEquals(dec, decReadSelf);
    }
View Full Code Here

Examples of org.apache.hadoop.hive.common.type.Decimal128

              int[] pos = new int[] {1, 0, 0, 0, 0};
              int[] neg = new int[] {0xff, 0, 0, 0, 0};

              pos[i+1] = neg[i+1] = value;

              doTestDecimalWithBoundsCheck(new Decimal128().update32(pos, 0));
              doTestDecimalWithBoundsCheck(new Decimal128().update32(neg, 0));
              doTestDecimalWithBoundsCheck(new Decimal128().update64(pos, 0));
              doTestDecimalWithBoundsCheck(new Decimal128().update64(neg, 0));
              doTestDecimalWithBoundsCheck(new Decimal128().update96(pos, 0));
              doTestDecimalWithBoundsCheck(new Decimal128().update96(neg, 0));
              doTestDecimalWithBoundsCheck(new Decimal128().update128(pos, 0));
              doTestDecimalWithBoundsCheck(new Decimal128().update128(neg, 0));
          }
      }
    }
View Full Code Here

Examples of org.apache.hadoop.hive.common.type.Decimal128

    public void testHive6594() {
      String[] vs = new String[] {
          "-4033.445769230769",
          "6984454.211097692"};

      Decimal128 d = new Decimal128(0L, (short) 14);
      for (String s:vs) {
        Decimal128 p = new Decimal128(s, (short) 14);
        d.addDestructive(p, (short) (short) 14);
      }

      int bufferUsed = d.fastSerializeForHiveDecimal(scratch);
      HiveDecimalWritable hdw = new HiveDecimalWritable();
View Full Code Here

Examples of org.apache.hadoop.hive.common.type.Decimal128

        int[] selected) {

      for (int j=0; j< batchSize; ++j) {
        int i = selected[j];
        if (!isNull[i]) {
          Decimal128 value = vector[i];
          myagg.sumValueWithCheck(value, this.sumScale);
        }
      }
    }
View Full Code Here

Examples of org.apache.hadoop.hive.common.type.Decimal128

        myagg.sum.zeroClear();
        myagg.count = 0;
      }

      for (int i=0; i< batchSize; ++i) {
        Decimal128 value = vector[selected[i]];
        myagg.sumValueNoCheck(value, this.sumScale);
      }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.