Example usage for java.lang Math ceil

List of usage examples for java.lang Math ceil

Introduction

In this page you can find the example usage for java.lang Math ceil.

Prototype

public static double ceil(double a) 

Source Link

Document

Returns the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer.

Usage

From source file:Main.java

public static int nextExp2(int n) {

    double e = Math.log((double) n) / Math.log(2.0);
    int p = (int) Math.ceil(e);
    double f = n / Math.pow(2.0, (double) p);
    if (f == 0.5) {
        p = p - 1;/*from  w  w  w. j av a 2 s  . c  o m*/
    }
    return p;
}

From source file:com.websystique.springmvc.dao.ChapterDAO.java

@SuppressWarnings("unchecked")
public SearchPair<Chapter> getChapters(int page, String orderby, String sorter) {
    String sql = "SELECT * FROM chapters ORDER BY " + orderby + " " + sorter;
    Query query = getSession().createSQLQuery(sql).addEntity(Chapter.class);

    query.setFirstResult(page * Parameters.maxChaptersInResult);
    query.setMaxResults(Parameters.maxChaptersInResult);
    List<Chapter> list = query.list();

    sql = "SELECT COUNT(id) FROM chapters";
    query = getSession().createSQLQuery(sql);
    int total = (int) Math.ceil((Integer) query.uniqueResult() / Parameters.maxChaptersInResult);

    return new <Chapter>SearchPair(list, total);
}

From source file:com.linkedin.pinot.perf.ForwardIndexWriterBenchmark.java

public static void convertRawToForwardIndex(File rawFile) throws Exception {
    List<String> lines = IOUtils.readLines(new FileReader(rawFile));
    int totalDocs = lines.size();
    int max = Integer.MIN_VALUE;
    int maxNumberOfMultiValues = Integer.MIN_VALUE;
    int totalNumValues = 0;
    int data[][] = new int[totalDocs][];
    for (int i = 0; i < lines.size(); i++) {
        String line = lines.get(i);
        String[] split = line.split(",");
        totalNumValues = totalNumValues + split.length;
        if (split.length > maxNumberOfMultiValues) {
            maxNumberOfMultiValues = split.length;
        }/* w w  w . j  a  va2s .  c  o  m*/
        data[i] = new int[split.length];
        for (int j = 0; j < split.length; j++) {
            String token = split[j];
            int val = Integer.parseInt(token);
            data[i][j] = val;
            if (val > max) {
                max = val;
            }
        }
    }
    int maxBitsNeeded = (int) Math.ceil(Math.log(max) / Math.log(2));
    int size = 2048;
    int[] offsets = new int[size];
    int bitMapSize = 0;
    File outputFile = new File("output.mv.fwd");

    FixedBitMultiValueWriter fixedBitSkipListSCMVWriter = new FixedBitMultiValueWriter(outputFile, totalDocs,
            totalNumValues, maxBitsNeeded);

    for (int i = 0; i < totalDocs; i++) {
        fixedBitSkipListSCMVWriter.setIntArray(i, data[i]);
        if (i % size == size - 1) {
            MutableRoaringBitmap rr1 = MutableRoaringBitmap.bitmapOf(offsets);
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            DataOutputStream dos = new DataOutputStream(bos);
            rr1.serialize(dos);
            dos.close();
            // System.out.println("Chunk " + i / size + " bitmap size:" + bos.size());
            bitMapSize += bos.size();
        } else if (i == totalDocs - 1) {
            MutableRoaringBitmap rr1 = MutableRoaringBitmap.bitmapOf(Arrays.copyOf(offsets, i % size));
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            DataOutputStream dos = new DataOutputStream(bos);
            rr1.serialize(dos);
            dos.close();
            // System.out.println("Chunk " + i / size + " bitmap size:" + bos.size());
            bitMapSize += bos.size();
        }
    }
    fixedBitSkipListSCMVWriter.close();
    System.out.println("Output file size:" + outputFile.length());
    System.out.println("totalNumberOfDoc\t\t\t:" + totalDocs);
    System.out.println("totalNumberOfValues\t\t\t:" + totalNumValues);
    System.out.println("chunk size\t\t\t\t:" + size);
    System.out.println("Num chunks\t\t\t\t:" + totalDocs / size);
    int numChunks = totalDocs / size + 1;
    int totalBits = (totalNumValues * maxBitsNeeded);
    int dataSizeinBytes = (totalBits + 7) / 8;

    System.out.println("Raw data size with fixed bit encoding\t:" + dataSizeinBytes);
    System.out.println("\nPer encoding size");
    System.out.println();
    System.out.println("size (offset + length)\t\t\t:" + ((totalDocs * (4 + 4)) + dataSizeinBytes));
    System.out.println();
    System.out.println("size (offset only)\t\t\t:" + ((totalDocs * (4)) + dataSizeinBytes));
    System.out.println();
    System.out.println("bitMapSize\t\t\t\t:" + bitMapSize);
    System.out.println("size (with bitmap)\t\t\t:" + (bitMapSize + (numChunks * 4) + dataSizeinBytes));

    System.out.println();
    System.out.println("Custom Bitset\t\t\t\t:" + (totalNumValues + 7) / 8);
    System.out.println("size (with custom bitset)\t\t\t:"
            + (((totalNumValues + 7) / 8) + (numChunks * 4) + dataSizeinBytes));
}

From source file:Main.java

/**
 * Function: arcToCurves// w  w  w.java2s  .com
 * 
 * Converts the given arc to a series of curves.
 */
public static double[] arcToCurves(double x0, double y0, double r1, double r2, double angle,
        double largeArcFlag, double sweepFlag, double x, double y) {
    x -= x0;
    y -= y0;

    if (r1 == 0 || r2 == 0) {
        return new double[0];
    }

    double fS = sweepFlag;
    double psai = angle;
    r1 = Math.abs(r1);
    r2 = Math.abs(r2);
    double ctx = -x / 2;
    double cty = -y / 2;
    double cpsi = Math.cos(psai * Math.PI / 180);
    double spsi = Math.sin(psai * Math.PI / 180);
    double rxd = cpsi * ctx + spsi * cty;
    double ryd = -1 * spsi * ctx + cpsi * cty;
    double rxdd = rxd * rxd;
    double rydd = ryd * ryd;
    double r1x = r1 * r1;
    double r2y = r2 * r2;
    double lamda = rxdd / r1x + rydd / r2y;
    double sds;

    if (lamda > 1) {
        r1 = Math.sqrt(lamda) * r1;
        r2 = Math.sqrt(lamda) * r2;
        sds = 0;
    } else {
        double seif = 1;

        if (largeArcFlag == fS) {
            seif = -1;
        }

        sds = seif * Math.sqrt((r1x * r2y - r1x * rydd - r2y * rxdd) / (r1x * rydd + r2y * rxdd));
    }

    double txd = sds * r1 * ryd / r2;
    double tyd = -1 * sds * r2 * rxd / r1;
    double tx = cpsi * txd - spsi * tyd + x / 2;
    double ty = spsi * txd + cpsi * tyd + y / 2;
    double rad = Math.atan2((ryd - tyd) / r2, (rxd - txd) / r1) - Math.atan2(0, 1);
    double s1 = (rad >= 0) ? rad : 2 * Math.PI + rad;
    rad = Math.atan2((-ryd - tyd) / r2, (-rxd - txd) / r1) - Math.atan2((ryd - tyd) / r2, (rxd - txd) / r1);
    double dr = (rad >= 0) ? rad : 2 * Math.PI + rad;

    if (fS == 0 && dr > 0) {
        dr -= 2 * Math.PI;
    } else if (fS != 0 && dr < 0) {
        dr += 2 * Math.PI;
    }

    double sse = dr * 2 / Math.PI;
    int seg = (int) Math.ceil(sse < 0 ? -1 * sse : sse);
    double segr = dr / seg;
    double t = 8 / 3 * Math.sin(segr / 4) * Math.sin(segr / 4) / Math.sin(segr / 2);
    double cpsir1 = cpsi * r1;
    double cpsir2 = cpsi * r2;
    double spsir1 = spsi * r1;
    double spsir2 = spsi * r2;
    double mc = Math.cos(s1);
    double ms = Math.sin(s1);
    double x2 = -t * (cpsir1 * ms + spsir2 * mc);
    double y2 = -t * (spsir1 * ms - cpsir2 * mc);
    double x3 = 0;
    double y3 = 0;

    double[] result = new double[seg * 6];

    for (int n = 0; n < seg; ++n) {
        s1 += segr;
        mc = Math.cos(s1);
        ms = Math.sin(s1);

        x3 = cpsir1 * mc - spsir2 * ms + tx;
        y3 = spsir1 * mc + cpsir2 * ms + ty;
        double dx = -t * (cpsir1 * ms + spsir2 * mc);
        double dy = -t * (spsir1 * ms - cpsir2 * mc);

        // CurveTo updates x0, y0 so need to restore it
        int index = n * 6;
        result[index] = x2 + x0;
        result[index + 1] = y2 + y0;
        result[index + 2] = x3 - dx + x0;
        result[index + 3] = y3 - dy + y0;
        result[index + 4] = x3 + x0;
        result[index + 5] = y3 + y0;

        x2 = x3 + dx;
        y2 = y3 + dy;
    }

    return result;
}

From source file:Main.java

private static boolean unprotectedTest(long l) {
    for (int n = 2, max = (int) Math.ceil(Math.sqrt(l)); n <= max; n++) {
        if (l % n == 0) {
            return false;
        }//from  w w w  . ja va 2  s  . c  o m
    }
    return true;
}

From source file:edu.asu.ca.kaushik.algorithms.permvector.utils.CPHF.java

/**
 * A covering perfect hash family CPHF(n;k,v^t,t).
 * @param n/* ww  w  . j a v a2s . co  m*/
 * @param k
 * @param v
 * @param t
 */
public static int CPHF_LLL(int t, int k, int v) {
    double vTot = Math.pow(v, t);
    double nume = 1.0d;
    for (int i = 1; i < t; i++) {
        nume = nume * (vTot - Math.pow(v, i));
    }

    double dnom = Math.pow(vTot - 1.0d, t - 1);

    double q = 1.0d - nume / dnom;

    double d = CombinatoricsUtils.binomialCoefficientDouble(k, t)
            - CombinatoricsUtils.binomialCoefficientDouble(k - t, t);

    return (int) Math.ceil((1 + Math.log(d)) / (-Math.log(q)));
}

From source file:io.seldon.vw.VwFeatureHash.java

public VwFeatureHash(int bits, int oaa) {
    mask = Math.round((float) Math.pow(2, bits) - 1);
    stride = Math.round((float) Math.pow(2, Math.ceil(log2(oaa, 2))));
    System.out.println("Stide is " + stride);
}

From source file:com.ormanli.duplicatefinder.util.FileUtil.java

public FileUtil(String path) {
    List<File> fileList = getFileList(path);
    queue = Queues.newConcurrentLinkedQueue(Lists.partition(fileList,
            (int) Math.ceil(fileList.size() / (double) Runtime.getRuntime().availableProcessors())));
}

From source file:com.ning.hfind.primary.SizePrimary.java

@Override
public boolean passesFilter(FileAttributes attributes) {
    if (blockMode) {
        return operandModifier.evaluate(size, Math.ceil(attributes.getLength() / 512.0));
    } else {//from  ww w  . j  av a  2 s  .  com
        return operandModifier.evaluate(size, attributes.getLength());
    }
}

From source file:Main.java

private static <T> List<List<T>> getChunkList(List<T> unpartitionedList, int splitCount) {
    int totalProblemSize = unpartitionedList.size();
    int chunkSize = (int) Math.ceil((double) totalProblemSize / splitCount);

    List<List<T>> chunkList = new ArrayList<List<T>>(splitCount);

    int offset = 0;
    int limit = 0;
    for (int x = 0; x < splitCount; x++) {
        limit = offset + chunkSize;//from  w  ww  .j a  va 2  s.c  o m
        if (limit > totalProblemSize)
            limit = totalProblemSize;
        List<T> subList = unpartitionedList.subList(offset, limit);
        chunkList.add(subList);
        offset = limit;
    }
    return chunkList;
}