Example #1
0
  // there might be a straightforward one-line way to do the below
  // that's portable and totally safe against roundoff, but I haven't
  // thought of it.  Therefore, we opt on the side of caution
  private int maptype1_quantvals() {
    int vals = (int) (Math.floor(Math.pow(entries, 1. / dim)));

    // the above *should* be reliable, but we'll not assume that FP is
    // ever reliable when bitstream sync is at stake; verify via integer
    // means that vals really is the greatest value of dim for which
    // vals^b->bim <= b->entries
    // treat the above as an initial guess
    while (true) {
      int acc = 1;
      int acc1 = 1;
      for (int i = 0; i < dim; i++) {
        acc *= vals;
        acc1 *= vals + 1;
      }
      if (acc <= entries && acc1 > entries) {
        return (vals);
      } else {
        if (acc > entries) {
          vals--;
        } else {
          vals++;
        }
      }
    }
  }
Example #2
0
 // doesn't currently guard under/overflow
 static long float32_pack(float val) {
   int sign = 0;
   int exp;
   int mant;
   if (val < 0) {
     sign = 0x80000000;
     val = -val;
   }
   exp = (int) Math.floor(Math.log(val) / Math.log(2));
   mant = (int) Math.rint(Math.pow(val, (VQ_FMAN - 1) - exp));
   exp = (exp + VQ_FEXP_BIAS) << VQ_FMAN;
   return (sign | exp | mant);
 }