Example usage for java.lang Float intBitsToFloat

List of usage examples for java.lang Float intBitsToFloat

Introduction

In this page you can find the example usage for java.lang Float intBitsToFloat.

Prototype

@HotSpotIntrinsicCandidate
public static native float intBitsToFloat(int bits);

Source Link

Document

Returns the float value corresponding to a given bit representation.

Usage

From source file:org.apache.jcs.engine.memory.mru.LRUvsMRUPerformanceTest.java

/**
 * Runs the test/*from  ww w .j av a  2  s.  co m*/
 */
public void doWork() {

    long start = 0;
    long end = 0;
    long time = 0;
    float tPer = 0;

    long putTotalLRU = 0;
    long getTotalLRU = 0;
    long putTotalMRU = 0;
    long getTotalMRU = 0;

    try {

        JCS.setConfigFilename("/TestMRUCache.ccf");
        JCS cache = JCS.getInstance("lruDefined");
        JCS mru = JCS.getInstance("mruDefined");

        System.out.println("LRU = " + cache);

        for (int j = 0; j < loops; j++) {

            System.out.println("Beginning loop " + j);

            String name = "LRU      ";
            start = System.currentTimeMillis();
            for (int i = 0; i < tries; i++) {
                cache.put("key:" + i, "data" + i);
            }
            end = System.currentTimeMillis();
            time = end - start;
            putTotalLRU += time;
            tPer = Float.intBitsToFloat((int) time) / Float.intBitsToFloat(tries);
            System.out.println(name + " put time for " + tries + " = " + time + "; millis per = " + tPer);

            start = System.currentTimeMillis();
            for (int i = 0; i < tries; i++) {
                cache.get("key:" + i);
            }
            end = System.currentTimeMillis();
            time = end - start;
            getTotalLRU += time;
            tPer = Float.intBitsToFloat((int) time) / Float.intBitsToFloat(tries);
            System.out.println(name + " get time for " + tries + " = " + time + "; millis per = " + tPer);

            // /////////////////////////////////////////////////////////////
            name = "MRU";
            start = System.currentTimeMillis();
            for (int i = 0; i < tries; i++) {
                mru.put("key:" + i, "data" + i);
            }
            end = System.currentTimeMillis();
            time = end - start;
            putTotalMRU += time;
            tPer = Float.intBitsToFloat((int) time) / Float.intBitsToFloat(tries);
            System.out.println(name + " put time for " + tries + " = " + time + "; millis per = " + tPer);

            start = System.currentTimeMillis();
            for (int i = 0; i < tries; i++) {
                mru.get("key:" + i);
            }
            end = System.currentTimeMillis();
            time = end - start;
            getTotalMRU += time;
            tPer = Float.intBitsToFloat((int) time) / Float.intBitsToFloat(tries);
            System.out.println(name + " get time for " + tries + " = " + time + "; millis per = " + tPer);

            System.out.println("\n");
        }

    } catch (Exception e) {
        e.printStackTrace(System.out);
        System.out.println(e);
    }

    long putAvJCS = putTotalLRU / loops;
    long getAvJCS = getTotalLRU / loops;
    long putAvHashtable = putTotalMRU / loops;
    long getAvHashtable = getTotalMRU / loops;

    System.out.println("Finished " + loops + " loops of " + tries + " gets and puts");

    System.out.println("\n");
    System.out.println("Put average for JCS       = " + putAvJCS);
    System.out.println("Put average for MRU = " + putAvHashtable);
    ratioPut = Float.intBitsToFloat((int) putAvJCS) / Float.intBitsToFloat((int) putAvHashtable);
    System.out.println("JCS puts took " + ratioPut + " times the Hashtable, the goal is <" + target + "x");

    System.out.println("\n");
    System.out.println("Get average for JCS       = " + getAvJCS);
    System.out.println("Get average for MRU = " + getAvHashtable);
    ratioGet = Float.intBitsToFloat((int) getAvJCS) / Float.intBitsToFloat((int) getAvHashtable);
    System.out.println("JCS gets took " + ratioGet + " times the Hashtable, the goal is <" + target + "x");

}

From source file:org.apache.jcs.utils.struct.JCSvsCommonsLRUMapPerformanceTest.java

/**
 *
 *//*from  w w w  . jav a2s  .  co m*/
public void doWork() {

    long start = 0;
    long end = 0;
    long time = 0;
    float tPer = 0;

    long putTotalJCS = 0;
    long getTotalJCS = 0;
    long putTotalHashtable = 0;
    long getTotalHashtable = 0;

    String name = "LRUMap";
    String cache2Name = "";

    try {

        Map cache = new LRUMap(tries);

        for (int j = 0; j < loops; j++) {

            name = "JCS      ";
            start = System.currentTimeMillis();
            for (int i = 0; i < tries; i++) {
                cache.put("key:" + i, "data" + i);
            }
            end = System.currentTimeMillis();
            time = end - start;
            putTotalJCS += time;
            tPer = Float.intBitsToFloat((int) time) / Float.intBitsToFloat(tries);
            System.out.println(name + " put time for " + tries + " = " + time + "; millis per = " + tPer);

            start = System.currentTimeMillis();
            for (int i = 0; i < tries; i++) {
                cache.get("key:" + i);
            }
            end = System.currentTimeMillis();
            time = end - start;
            getTotalJCS += time;
            tPer = Float.intBitsToFloat((int) time) / Float.intBitsToFloat(tries);
            System.out.println(name + " get time for " + tries + " = " + time + "; millis per = " + tPer);

            // /////////////////////////////////////////////////////////////
            cache2Name = "Commons  ";
            // or LRUMapJCS
            Map cache2 = new org.apache.commons.collections.map.LRUMap(tries);
            // cache2Name = "Hashtable";
            // Hashtable cache2 = new Hashtable();
            start = System.currentTimeMillis();
            for (int i = 0; i < tries; i++) {
                cache2.put("key:" + i, "data" + i);
            }
            end = System.currentTimeMillis();
            time = end - start;
            putTotalHashtable += time;
            tPer = Float.intBitsToFloat((int) time) / Float.intBitsToFloat(tries);
            System.out.println(cache2Name + " put time for " + tries + " = " + time + "; millis per = " + tPer);

            start = System.currentTimeMillis();
            for (int i = 0; i < tries; i++) {
                cache2.get("key:" + i);
            }
            end = System.currentTimeMillis();
            time = end - start;
            getTotalHashtable += time;
            tPer = Float.intBitsToFloat((int) time) / Float.intBitsToFloat(tries);
            System.out.println(cache2Name + " get time for " + tries + " = " + time + "; millis per = " + tPer);

            System.out.println("\n");
        }

    } catch (Exception e) {
        e.printStackTrace(System.out);
        System.out.println(e);
    }

    long putAvJCS = putTotalJCS / loops;
    long getAvJCS = getTotalJCS / loops;
    long putAvHashtable = putTotalHashtable / loops;
    long getAvHashtable = getTotalHashtable / loops;

    System.out.println("Finished " + loops + " loops of " + tries + " gets and puts");

    System.out.println("\n");
    System.out.println("Put average for LRUMap       = " + putAvJCS);
    System.out.println("Put average for " + cache2Name + " = " + putAvHashtable);
    ratioPut = Float.intBitsToFloat((int) putAvJCS) / Float.intBitsToFloat((int) putAvHashtable);
    System.out.println(
            name + " puts took " + ratioPut + " times the " + cache2Name + ", the goal is <" + target + "x");

    System.out.println("\n");
    System.out.println("Get average for LRUMap       = " + getAvJCS);
    System.out.println("Get average for " + cache2Name + " = " + getAvHashtable);
    ratioGet = Float.intBitsToFloat((int) getAvJCS) / Float.intBitsToFloat((int) getAvHashtable);
    System.out.println(
            name + " gets took " + ratioGet + " times the " + cache2Name + ", the goal is <" + target + "x");

}

From source file:uk.co.modularaudio.mads.base.soundfile_player.mu.SoundfilePlayerIOQueueBridge.java

@Override
public void receiveQueuedEventsToInstance(final SoundfilePlayerMadInstance instance,
        final ThreadSpecificTemporaryEventStorage tses, final long periodTimestamp,
        final IOQueueEvent queueEntry) {
    switch (queueEntry.command) {
    case COMMAND_IN_ACTIVE: {
        instance.active = queueEntry.value == 1;
        break;/*w  w  w. j a  v  a2s.  c  om*/
    }
    case COMMAND_IN_PLAYING_STATE: {
        final int value = (int) queueEntry.value;
        final SoundfilePlayerMadInstance.PlayingState desiredState = SoundfilePlayerMadInstance.PlayingState
                .values()[value];
        instance.setDesiredState(desiredState);
        break;
    }
    case COMMAND_IN_PLAY_SPEED: {
        final float value = Float.intBitsToFloat(((int) queueEntry.value));
        instance.setDesiredPlaySpeed(value);
        break;
    }
    case COMMAND_IN_GAIN: {
        final float value = Float.intBitsToFloat(((int) queueEntry.value));
        instance.setDesiredGain(value);
        break;
    }
    case COMMAND_IN_RESAMPLED_SAMPLE: {
        final BlockResamplingClient prevSample = instance.getResampledSample();
        final BlockResamplingClient resampledSample = (BlockResamplingClient) queueEntry.object;
        instance.setResampledSample(resampledSample);
        if (prevSample != null) {
            // Get the UI to clean up the previously used one
            queueCommandEventToUi(tses, COMMAND_OUT_RECYCLE_SAMPLE, 0, prevSample);
        }
        break;
    }
    case COMMAND_IN_SHUTTLE_REWIND_TO_START: {
        final BlockResamplingClient curSample = instance.getResampledSample();
        if (curSample != null) {
            instance.resetFramePosition(0);
            instance.addJobForSampleCachingService();

            queueTemporalEventToUi(tses, periodTimestamp, COMMAND_OUT_FRAME_POSITION_ABS, 0, curSample);
        }
        break;
    }
    case COMMAND_IN_SHUTTLE_FFWD_TO_END: {
        final BlockResamplingClient curSample = instance.getResampledSample();
        if (curSample != null) {
            final long lastFrameNum = curSample.getTotalNumFrames() - 1;
            instance.resetFramePosition(lastFrameNum);
            instance.addJobForSampleCachingService();

            queueTemporalEventToUi(tses, periodTimestamp, COMMAND_OUT_FRAME_POSITION_ABS, lastFrameNum,
                    curSample);
        }
        break;
    }
    case COMMAND_IN_POSITION_JUMP: {
        final long newPosition = queueEntry.value;
        final BlockResamplingClient curSample = instance.getResampledSample();
        if (curSample != null) {
            instance.resetFramePosition(newPosition);
            instance.addJobForSampleCachingService();

            queueTemporalEventToUi(tses, periodTimestamp, COMMAND_OUT_FRAME_POSITION_ABS_WAIT_FOR_CACHE,
                    newPosition, curSample);
        }
        break;
    }
    default: {
        final String msg = "Unknown command passed on incoming queue: " + queueEntry.command;
        log.error(msg);
        break;
    }
    }
}

From source file:eu.eexcess.domaindetection.wordnet.XwndReader.java

public void read(File file) throws IOException {
    String domain = FilenameUtils.getBaseName(file.getName());

    File cacheFile = new File(file.getPath() + ".cache");
    if (!cacheFile.exists()) {
        BinaryOutputStream bos = new BinaryOutputStream(new FileOutputStream(cacheFile));
        System.out.println("Read in the Extended WordNet Domains file: " + file);
        LineIterator iterator = new LineIterator(new FileReader(file));
        while (iterator.hasNext()) {
            String line = iterator.nextLine();
            String[] tokens = line.split("\t");
            String synset = tokens[0];
            double weight = Double.parseDouble(tokens[1]);
            String[] ssid = synset.split("-");
            int nr = Integer.parseInt(ssid[0]);
            POS pos = POS.getPOSForKey(ssid[1]);
            bos.writeInt(nr);/*from   w w w .  j a v  a  2  s.co  m*/
            bos.writeSmallInt(pos.getId());
            bos.writeInt(Float.floatToIntBits((float) weight));
        }
        iterator.close();
        bos.close();
    }

    System.out.println("Read in the Extended WordNet Domains cache file: " + file);
    FileInputStream fStream = new FileInputStream(cacheFile);
    BinaryInputStream bis = new BinaryInputStream(fStream);
    while (bis.available() > 0) {
        int nr = bis.readInt();
        int key = bis.readSmallInt();
        POS pos = POS.getPOSForId(key);
        String synset = String.format("%08d-%s", nr, pos.getKey());
        double weight = Float.intBitsToFloat(bis.readInt());
        DomainAssignment assignment = new DomainAssignment(domain, weight);
        Set<DomainAssignment> domains = synsetToDomains.get(synset);
        if (domains == null) {
            domains = new TreeSet<DomainAssignment>();
            synsetToDomains.put(synset, domains);
        }
        domains.add(assignment);
    }
    fStream.close();
    bis.close();
}

From source file:org.apache.jcs.JCSvsHashtablePerformanceTest.java

/**
 *
 *///from www. j av a  2  s . com
public void doWork() {

    long start = 0;
    long end = 0;
    long time = 0;
    float tPer = 0;

    long putTotalJCS = 0;
    long getTotalJCS = 0;
    long putTotalHashtable = 0;
    long getTotalHashtable = 0;

    try {

        JCS.setConfigFilename("/TestJCSvHashtablePerf.ccf");
        JCS cache = JCS.getInstance("testCache1");

        for (int j = 0; j < loops; j++) {

            String name = "JCS      ";
            start = System.currentTimeMillis();
            for (int i = 0; i < tries; i++) {
                cache.put("key:" + i, "data" + i);
            }
            end = System.currentTimeMillis();
            time = end - start;
            putTotalJCS += time;
            tPer = Float.intBitsToFloat((int) time) / Float.intBitsToFloat(tries);
            System.out.println(name + " put time for " + tries + " = " + time + "; millis per = " + tPer);

            start = System.currentTimeMillis();
            for (int i = 0; i < tries; i++) {
                cache.get("key:" + i);
            }
            end = System.currentTimeMillis();
            time = end - start;
            getTotalJCS += time;
            tPer = Float.intBitsToFloat((int) time) / Float.intBitsToFloat(tries);
            System.out.println(name + " get time for " + tries + " = " + time + "; millis per = " + tPer);

            // /////////////////////////////////////////////////////////////
            name = "Hashtable";
            Hashtable cache2 = new Hashtable();
            start = System.currentTimeMillis();
            for (int i = 0; i < tries; i++) {
                cache2.put("key:" + i, "data" + i);
            }
            end = System.currentTimeMillis();
            time = end - start;
            putTotalHashtable += time;
            tPer = Float.intBitsToFloat((int) time) / Float.intBitsToFloat(tries);
            System.out.println(name + " put time for " + tries + " = " + time + "; millis per = " + tPer);

            start = System.currentTimeMillis();
            for (int i = 0; i < tries; i++) {
                cache2.get("key:" + i);
            }
            end = System.currentTimeMillis();
            time = end - start;
            getTotalHashtable += time;
            tPer = Float.intBitsToFloat((int) time) / Float.intBitsToFloat(tries);
            System.out.println(name + " get time for " + tries + " = " + time + "; millis per = " + tPer);

            System.out.println("\n");
        }

    } catch (Exception e) {
        e.printStackTrace(System.out);
        System.out.println(e);
    }

    long putAvJCS = putTotalJCS / loops;
    long getAvJCS = getTotalJCS / loops;
    long putAvHashtable = putTotalHashtable / loops;
    long getAvHashtable = getTotalHashtable / loops;

    System.out.println("Finished " + loops + " loops of " + tries + " gets and puts");

    System.out.println("\n");
    System.out.println("Put average for JCS       = " + putAvJCS);
    System.out.println("Put average for Hashtable = " + putAvHashtable);
    ratioPut = Float.intBitsToFloat((int) putAvJCS) / Float.intBitsToFloat((int) putAvHashtable);
    System.out.println("JCS puts took " + ratioPut + " times the Hashtable, the goal is <" + target + "x");

    System.out.println("\n");
    System.out.println("Get average for JCS       = " + getAvJCS);
    System.out.println("Get average for Hashtable = " + getAvHashtable);
    ratioGet = Float.intBitsToFloat((int) getAvJCS) / Float.intBitsToFloat((int) getAvHashtable);
    System.out.println("JCS gets took " + ratioGet + " times the Hashtable, the goal is <" + target + "x");

}

From source file:Main.java

/**
 * Returns the first floating-point argument with the sign of the
 * second floating-point argument.  Note that unlike the {@link
 * FpUtils#copySign(float, float) copySign} method, this method
 * does not require NaN <code>sign</code> arguments to be treated
 * as positive values; implementations are permitted to treat some
 * NaN arguments as positive and other NaN arguments as negative
 * to allow greater performance.//from www.j  a v a  2 s .c om
 *
 * @param magnitude  the parameter providing the magnitude of the result
 * @param sign   the parameter providing the sign of the result
 * @return a value with the magnitude of <code>magnitude</code>
 * and the sign of <code>sign</code>.
 * @author Joseph D. Darcy
 */
public static float rawCopySign(float magnitude, float sign) {
    return Float.intBitsToFloat((Float.floatToRawIntBits(sign) & (FloatConsts.SIGN_BIT_MASK))
            | (Float.floatToRawIntBits(magnitude) & (FloatConsts.EXP_BIT_MASK | FloatConsts.SIGNIF_BIT_MASK)));
}

From source file:Encdec.java

public static float dec_floatle(byte[] src, int si) {
    return Float.intBitsToFloat(dec_uint32le(src, si));
}

From source file:resources.common.MathUtilities.java

public float fastInverseSqrt(float x) {
    float xHalf = 0.5F * x;
    int temp = Float.floatToRawIntBits(x);
    temp = 0x5F3759DF - (temp >> 1); // magic
    float newX = Float.intBitsToFloat(temp);
    newX = newX * (1.5F - xHalf * newX * newX);
    return newX;/*from   w w  w .jav  a2 s .co  m*/
}

From source file:Encdec.java

public static float dec_floatbe(byte[] src, int si) {
    return Float.intBitsToFloat(dec_uint32be(src, si));
}

From source file:uk.co.modularaudio.mads.base.djeq.ui.DJEQMadUiInstance.java

@Override
public void consumeQueueEntry(final DJEQMadInstance instance, final IOQueueEvent nextOutgoingEntry) {
    switch (nextOutgoingEntry.command) {
    case DJEQIOQueueBridge.COMMAND_OUT_METER_READINGS: {
        final long timestamp = nextOutgoingEntry.frameTime;
        final long val = nextOutgoingEntry.value;
        final int lower32 = (int) (val & 0xFFFFFFFF);
        final int upper32 = (int) ((val >> 32) & 0xFFFFFFFF);
        final float rMeter = Float.intBitsToFloat(lower32);
        final float lMeter = Float.intBitsToFloat(upper32);
        final float lMeterDb = AudioMath.levelToDbF(lMeter);
        final float rMeterDb = AudioMath.levelToDbF(rMeter);
        meter.receiveMeterReadingInDb(timestamp, 0, lMeterDb);
        meter.receiveMeterReadingInDb(timestamp, 1, rMeterDb);
        break;//from w  w  w  .j  av a  2  s . c  o m
    }
    default: {
        final String msg = "Unknown command to guI: " + nextOutgoingEntry.command;
        log.error(msg);
    }
    }
}