Example usage for java.lang Double longBitsToDouble

List of usage examples for java.lang Double longBitsToDouble

Introduction

In this page you can find the example usage for java.lang Double longBitsToDouble.

Prototype

@HotSpotIntrinsicCandidate
public static native double longBitsToDouble(long bits);

Source Link

Document

Returns the double value corresponding to a given bit representation.

Usage

From source file:cn.iie.haiep.hbase.value.Bytes.java

/**
 * @param bytes byte array/*from  w w  w .j  a va2s . com*/
 * @param offset offset where double is
 * @return Return double made from passed bytes.
 */
public static double toDouble(final byte[] bytes, final int offset) {
    return Double.longBitsToDouble(toLong(bytes, offset, SIZEOF_LONG));
}

From source file:org.apache.hadoop.hive.serde2.thrift.TBinarySortableProtocol.java

@Override
public double readDouble() throws TException {
    if (readIsNull()) {
        return 0;
    }/*from  ww w. j ava  2 s.  c om*/
    readRawAll(i64rd, 0, 8);
    long v = 0;
    if ((i64rd[0] & 0x80) != 0) {
        // Positive number
        v = ((long) ((i64rd[0] ^ 0x80) & 0xff) << 56) | ((long) (i64rd[1] & 0xff) << 48)
                | ((long) (i64rd[2] & 0xff) << 40) | ((long) (i64rd[3] & 0xff) << 32)
                | ((long) (i64rd[4] & 0xff) << 24) | ((long) (i64rd[5] & 0xff) << 16)
                | ((long) (i64rd[6] & 0xff) << 8) | ((i64rd[7] & 0xff));
    } else {
        // Negative number
        v = ((long) ((i64rd[0] ^ 0xff) & 0xff) << 56) | ((long) ((i64rd[1] ^ 0xff) & 0xff) << 48)
                | ((long) ((i64rd[2] ^ 0xff) & 0xff) << 40) | ((long) ((i64rd[3] ^ 0xff) & 0xff) << 32)
                | ((long) ((i64rd[4] ^ 0xff) & 0xff) << 24) | ((long) ((i64rd[5] ^ 0xff) & 0xff) << 16)
                | ((long) ((i64rd[6] ^ 0xff) & 0xff) << 8) | (((i64rd[7] ^ 0xff) & 0xff));
    }
    return Double.longBitsToDouble(v);
}

From source file:com.spotify.heroic.metric.bigtable.BigtableBackend.java

static double deserializeValue(ByteString value) {
    return Double.longBitsToDouble(ByteBuffer.wrap(value.toByteArray()).getLong());
}

From source file:com.sm.store.hessian.HessianReader.java

private double parseDouble() {
    long bits = parseLong();
    return Double.longBitsToDouble(bits);
}

From source file:sphericalGeo.SphericalDiffusionModel.java

/** Fast approximation of 1.0 / sqrt(x).
   * See <a href="http://www.beyond3d.com/content/articles/8/">http://www.beyond3d.com/content/articles/8/</a>
   * @param x Positive value to estimate inverse of square root of
   * @return Approximately 1.0 / sqrt(x)
   **//*from w w  w.j a  v a2  s.c  o  m*/
public static double invSqrt(double x) {
    double xhalf = 0.5 * x;
    long i = Double.doubleToRawLongBits(x);
    i = 0x5FE6EB50C7B537AAL - (i >> 1);
    x = Double.longBitsToDouble(i);
    x = x * (1.5 - xhalf * x * x);
    return x;
}

From source file:de.tum.frm2.nicos_android.gui.MainActivity.java

private void onDeviceSelected(Device device) {
    Object limits = device.getParam("userlimits");
    Object mapping = device.getParam("mapping");
    if (limits == null && mapping == null) {
        Toast.makeText(getApplicationContext(), "Cannot move " + device.getName() + ": Limits unknown",
                Toast.LENGTH_SHORT).show();
        return;//www.j  ava  2 s .  c o  m
    }

    _currentDevice = device;
    _currentDeviceTextView.setText(device.getName());
    _currentDeviceValueTextView.setText(device.getFormattedValue());
    _currentDeviceStatusImageView.setImageResource(DeviceStatus.getStatusResource(device.getStatus()));

    if (limits != null) {
        Object o_max = ((Object[]) limits)[1];
        double max = (double) o_max;

        // Try to read a value from the preferences.
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        String coarseKey = _uniquePrefix + _currentDevice.getName() + "coarse";
        String fineKey = _uniquePrefix + _currentDevice.getName() + "fine";
        if (prefs.contains(coarseKey) && prefs.contains(fineKey)) {
            long dec_coarse = prefs.getLong(coarseKey, 0);
            long dec_fine = prefs.getLong(fineKey, 0);
            _coarseStepEditText.setText(String.valueOf(Double.longBitsToDouble(dec_coarse)));
            _fineStepEditText.setText(String.valueOf(Double.longBitsToDouble(dec_fine)));
        } else {
            // infer default steps from the max limit.
            _coarseStepEditText.setText(String.valueOf(max / 5));
            _fineStepEditText.setText(String.valueOf(max / 10));
        }
    } else {
        // TODO: Implement devices with mapping!
        return;
    }

    _coarseStepLeftButton.setEnabled(true);
    _fineStepLeftButton.setEnabled(true);
    _stopButton.setEnabled(true);
    _fineStepRightButton.setEnabled(true);
    _coarseStepRightButton.setEnabled(true);
    _slidingUpPanelLayout.setEnabled(true);
}

From source file:kx.c.java

double rf() {
    return Double.longBitsToDouble(rj());
}

From source file:com.continuent.tungsten.common.mysql.MySQLPacket.java

/**
 * Returns eight bytes from the buffer as a float
 */
public double getDouble() {
    return Double.longBitsToDouble(getLong());
}

From source file:com.comcast.cdn.traffic_control.traffic_router.core.router.TrafficRouter.java

/**
 * Utilizes the hashValues stored with each cache to select the cache that
 * the specified hash should map to.//  w ww . j  ava 2s. com
 * 
 * @param caches
 *            the list of caches to choose from
 * @param request
 *            the request string from which the hash will be generated
 * @return a cache or null if no cache can be found to map to
 */
protected SortedMap<Double, Cache> consistentHash(final List<Cache> caches, final String request) {
    double hash = 0;
    HashFunction hashFunction = null;
    try {
        hashFunction = (HashFunction) hashFunctionPool.borrowObject();
        try {
            hash = hashFunction.hash(request);
        } catch (final Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
        hashFunctionPool.returnObject(hashFunction);
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    if (hash == 0) {
        LOGGER.warn("Problem with hashFunctionPool, request: " + request);
        return null;
    }

    final SortedMap<Double, Cache> cacheMap = new TreeMap<Double, Cache>();

    for (final Cache cache : caches) {
        final double r = cache.getClosestHash(hash);
        if (r == 0) {
            LOGGER.warn("Error: getClosestHash returned 0: " + cache);
            return null;
        }

        double diff = Math.abs(r - hash);

        if (cacheMap.containsKey(diff)) {
            LOGGER.warn("Error: cacheMap contains diff " + diff + "; incrementing to avoid collision");
            long bits = Double.doubleToLongBits(diff);

            while (cacheMap.containsKey(diff)) {
                bits++;
                diff = Double.longBitsToDouble(bits);
            }
        }

        cacheMap.put(diff, cache);
    }

    return cacheMap;
}

From source file:org.orekit.bodies.JPLEphemeridesLoader.java

/** Extract a double from a record.
 * <p>Double numbers are stored according to IEEE 754 standard, with
 * most significant byte first.</p>
 * @param record record to parse/*from  w  w w .  j  a v  a  2  s  . com*/
 * @param offset offset of the double within the record
 * @return extracted double
 */
private double extractDouble(final byte[] record, final int offset) {
    final long l8 = ((long) record[offset + 0]) & 0xffl;
    final long l7 = ((long) record[offset + 1]) & 0xffl;
    final long l6 = ((long) record[offset + 2]) & 0xffl;
    final long l5 = ((long) record[offset + 3]) & 0xffl;
    final long l4 = ((long) record[offset + 4]) & 0xffl;
    final long l3 = ((long) record[offset + 5]) & 0xffl;
    final long l2 = ((long) record[offset + 6]) & 0xffl;
    final long l1 = ((long) record[offset + 7]) & 0xffl;
    long l;
    if (bigEndian) {
        l = (l8 << 56) | (l7 << 48) | (l6 << 40) | (l5 << 32) | (l4 << 24) | (l3 << 16) | (l2 << 8) | l1;
    } else {
        l = (l1 << 56) | (l2 << 48) | (l3 << 40) | (l4 << 32) | (l5 << 24) | (l6 << 16) | (l7 << 8) | l8;
    }
    return Double.longBitsToDouble(l);
}