예제 #1
0
        public Object call(Scope sc, Object pointsInt, Object fo00000o[]) {
          Number n = (Number) (sc.getThis());
          int num = 0;
          if (pointsInt != null && pointsInt instanceof Number)
            num = ((Number) pointsInt).intValue();

          double mult = Math.pow(10, num);

          long foo = Math.round(n.doubleValue() * mult);
          double d = foo;
          d = d / mult;

          String s = String.valueOf(d);
          int idx = s.indexOf(".");

          if (idx < 0) {
            if (num > 0) {
              s += ".";
              while (num > 0) {
                s += "0";
                num--;
              }
            }
            return new JSString(s);
          }

          if (s.length() - idx <= num) { // need more
            int toAdd = (num + 1) - (s.length() - idx);
            for (int i = 0; i < toAdd; i++) s += "0";
            return new JSString(s);
          }

          if (num == 0) return s.substring(0, idx);
          return new JSString(s.substring(0, idx + 1 + num));
        }
예제 #2
0
  public static long toUintX(Object o, int size) {
    double d = getDouble(o);
    if (d == 0 || Double.isNaN(d) || Double.isInfinite(d)) return 0;

    int sign = o.toString().startsWith("-") ? -1 : 1;
    return (sign * (long) Math.floor(Math.abs(d))) % (long) Math.pow(2, size);
  }
예제 #3
0
 public static long toInt64(final Object o) {
   long preint = toUintX(o, 64);
   if (preint < (long) Math.pow(2, 63)) return preint;
   return preint - (long) Math.pow(2, 64);
 }
예제 #4
0
 public static int toInt32(final Object o) {
   long preint = toUintX(o, 32);
   if (preint < (long) Math.pow(2, 31)) return (int) preint;
   return (int) (preint - (long) Math.pow(2, 32));
 }
예제 #5
0
 long _getScopeTime() {
   long last = 0;
   for (File f : _initFlies) if (f.exists()) last = Math.max(last, f.lastModified());
   return last;
 }