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:com.asburymotors.android.disneysocal.common.Utils.java

/**
 * Fetch the location from app preferences.
 *///from   w ww.j a  v a  2 s  .  co m
public static LatLng getLocation(Context context) {
    if (!checkFineLocationPermission(context)) {
        return null;
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Long lat = prefs.getLong(PREFERENCES_LAT, Long.MAX_VALUE);
    Long lng = prefs.getLong(PREFERENCES_LNG, Long.MAX_VALUE);
    if (lat != Long.MAX_VALUE && lng != Long.MAX_VALUE) {
        Double latDbl = Double.longBitsToDouble(lat);
        Double lngDbl = Double.longBitsToDouble(lng);
        return new LatLng(latDbl, lngDbl);
    }
    return null;
}

From source file:dbs_project.util.Utils.java

public static double generateRandomDouble() {
    double d;//from  www  . j a  va  2s .c o m
    do {
        d = Double.longBitsToDouble(randomLong());
    } while (Double.isNaN(d) || Double.isInfinite(d));
    return d;
}

From source file:com.asalfo.wiulgi.util.Utils.java

/**
 * Fetch the location from app preferences.
 *//*from  w  w  w. j ava2s .com*/
public static LatLng getLocation(@NonNull Context context) {
    if (!checkFineLocationPermission(context)) {
        return null;
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Long lat = prefs.getLong(PREFERENCES_LAT, Long.MAX_VALUE);
    Long lng = prefs.getLong(PREFERENCES_LNG, Long.MAX_VALUE);
    if (lat != Long.MAX_VALUE && lng != Long.MAX_VALUE) {
        Double latDbl = Double.longBitsToDouble(lat);
        Double lngDbl = Double.longBitsToDouble(lng);
        return new LatLng(latDbl, lngDbl);
    }
    return null;
}

From source file:Encdec.java

public static double dec_doublele(byte[] src, int si) {
    return Double.longBitsToDouble(dec_uint64le(src, si));
}

From source file:Encdec.java

public static double dec_doublebe(byte[] src, int si) {
    return Double.longBitsToDouble(dec_uint64be(src, si));
}

From source file:Main.java

/**
 * Returns the floating-point number adjacent to the first
 * argument in the direction of the second argument.  If both
 * arguments compare as equal the second argument is returned.
 *
 * <p>//from   www . j ava2 s .com
 * Special cases:
 * <ul>
 * <li> If either argument is a NaN, then NaN is returned.
 *
 * <li> If both arguments are signed zeros, <code>direction</code>
 * is returned unchanged (as implied by the requirement of
 * returning the second argument if the arguments compare as
 * equal).
 *
 * <li> If <code>start</code> is
 * &plusmn;<code>Double.MIN_VALUE</code> and <code>direction</code>
 * has a value such that the result should have a smaller
 * magnitude, then a zero with the same sign as <code>start</code>
 * is returned.
 *
 * <li> If <code>start</code> is infinite and
 * <code>direction</code> has a value such that the result should
 * have a smaller magnitude, <code>Double.MAX_VALUE</code> with the
 * same sign as <code>start</code> is returned.
 *
 * <li> If <code>start</code> is equal to &plusmn;
 * <code>Double.MAX_VALUE</code> and <code>direction</code> has a
 * value such that the result should have a larger magnitude, an
 * infinity with same sign as <code>start</code> is returned.
 * </ul>
 *
 * @param start     starting floating-point value
 * @param direction value indicating which of
 * <code>start</code>'s neighbors or <code>start</code> should
 * be returned
 * @return The floating-point number adjacent to <code>start</code> in the
 * direction of <code>direction</code>.
 * @author Joseph D. Darcy
 */
public static double nextAfter(double start, double direction) {
    /*
     * The cases:
     *
     * nextAfter(+infinity, 0)  == MAX_VALUE
     * nextAfter(+infinity, +infinity)  == +infinity
     * nextAfter(-infinity, 0)  == -MAX_VALUE
     * nextAfter(-infinity, -infinity)  == -infinity
     *
     * are naturally handled without any additional testing
     */

    // First check for NaN values
    if (isNaN(start) || isNaN(direction)) {
        // return a NaN derived from the input NaN(s)
        return start + direction;
    } else if (start == direction) {
        return direction;
    } else { // start > direction or start < direction
        // Add +0.0 to get rid of a -0.0 (+0.0 + -0.0 => +0.0)
        // then bitwise convert start to integer.
        long transducer = Double.doubleToRawLongBits(start + 0.0d);

        /*
         * IEEE 754 floating-point numbers are lexicographically
         * ordered if treated as signed- magnitude integers .
         * Since Java's integers are two's complement,
         * incrementing" the two's complement representation of a
         * logically negative floating-point value *decrements*
         * the signed-magnitude representation. Therefore, when
         * the integer representation of a floating-point values
         * is less than zero, the adjustment to the representation
         * is in the opposite direction than would be expected at
         * first .
         */
        if (direction > start) { // Calculate next greater value
            transducer = transducer + (transducer >= 0L ? 1L : -1L);
        } else { // Calculate next lesser value
            assert direction < start;
            if (transducer > 0L)
                --transducer;
            else if (transducer < 0L)
                ++transducer;
            /*
             * transducer==0, the result is -MIN_VALUE
             *
             * The transition from zero (implicitly
             * positive) to the smallest negative
             * signed magnitude value must be done
             * explicitly.
             */
            else
                transducer = DoubleConsts.SIGN_BIT_MASK | 1L;
        }

        return Double.longBitsToDouble(transducer);
    }
}

From source file:com.analog.lyric.dimple.solvers.gibbs.samplers.generic.CDFSampler.java

public final static double expApprox(double value) {
    // Convert input to base2 log, then convert integer part into IEEE754 exponent
    final long expValue = (long) ((int) (1512775.395195186 * value) + 0x3FF00000) << 32; // 1512775.395195186 = 2^20/log(2)
    return Double.longBitsToDouble(expValue & ~(expValue >> 63)); // Clip result if negative and convert to a double
}

From source file:TypeConversionHelper.java

/**
 * Convert a byte[] into an instance of our value class.
 *
 * @param buf byte array to be converted
 *
 * @return converted double array as object
 *//*from w  w  w .  ja  va2  s. com*/
public static Object getDoubleArrayFromByteArray(byte[] buf) {
    int n = buf.length / 8;
    double[] a = new double[n];
    int i = 0;
    int j = 0;

    for (; i < n;) {
        a[i++] = Double.longBitsToDouble(((long) (buf[j++] & 0xFF) << 56) + ((long) (buf[j++] & 0xFF) << 48)
                + ((long) (buf[j++] & 0xFF) << 40) + ((long) (buf[j++] & 0xFF) << 32)
                + ((long) (buf[j++] & 0xFF) << 24) + ((buf[j++] & 0xFF) << 16) + ((buf[j++] & 0xFF) << 8)
                + (buf[j++] & 0xFF));
    }

    return a;
}

From source file:org.geotools.coverageio.jp2k.Utils.java

/**
 * Setup a double from an array of bytes.
 * @param bytes/*from   w  w  w . j  a v a2 s.co  m*/
 * @param start
 * @return
 */
public static double bytes2double(final byte[] bytes, final int start) {
    int i = 0;
    final int length = 8;
    int count = 0;
    final byte[] tmp = new byte[length];
    for (i = start; i < (start + length); i++) {
        tmp[count] = bytes[i];
        count++;
    }
    long accum = 0;
    i = 0;
    for (int shiftBy = 0; shiftBy < 64; shiftBy += 8) {
        accum |= ((long) (tmp[i] & 0xff)) << shiftBy;
        i++;
    }
    return Double.longBitsToDouble(accum);
}

From source file:ArrayByte.java

public double readDouble() throws IndexOutOfBoundsException {
    return Double.longBitsToDouble(readLong());
}