Example usage for java.lang Double doubleToRawLongBits

List of usage examples for java.lang Double doubleToRawLongBits

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static native long doubleToRawLongBits(double value);

Source Link

Document

Returns a representation of the specified floating-point value according to the IEEE 754 floating-point "double format" bit layout, preserving Not-a-Number (NaN) values.

Usage

From source file:com.tlongdev.bktf.util.Utility.java

/**
 * Convenient method for storing double values in shared preferences.
 *
 * @param edit  shared preferences editor
 * @param key   preference key/*from w w  w.  j  a  v  a 2s .c o m*/
 * @param value preference value
 * @return shared preference editor
 */
public static SharedPreferences.Editor putDouble(final SharedPreferences.Editor edit, final String key,
        final double value) {
    return edit.putLong(key, Double.doubleToRawLongBits(value));
}

From source file:org.eclipse.january.metadata.internal.StatisticsMetadataImpl.java

/**
 * Calculate summary statistics for a dataset
 * @param mm/*from  w w w .  j  av a  2  s .c  o  m*/
 * @param ignoreNaNs if true, ignore NaNs
 * @param ignoreInfs if true, ignore infinities
 */
@SuppressWarnings("unchecked")
private void setMaxMin(final MaxMin<T> mm, final boolean ignoreNaNs, final boolean ignoreInfs) {
    final IndexIterator iter = dataset.getIterator();

    if (!DTypeUtils.isDTypeNumerical(dtype)) { // TODO FIXME for strings
        // treat non-numerical as strings in lexicographic order
        String smax = dataset.getStringAbs(0);
        String smin = smax;
        while (iter.hasNext()) {
            final String val = dataset.getStringAbs(iter.index);
            hash = (int) (hash * 19 + val.hashCode());
            if (val.compareTo(smax) > 0) {
                smax = val;
            }
            if (val.compareTo(smin) < 0) {
                smin = val;
            }
        }

        hash = hash * 19 + dtype * 17 + isize;
        mm.maximum = (T) smax;
        mm.minimum = (T) smin;
        mm.maximumPositions = null;
        mm.minimumPositions = null;
        return;
    }

    if (isize == 1) {
        double amax = Double.NEGATIVE_INFINITY;
        double amin = Double.POSITIVE_INFINITY;

        boolean hasNaNs = false;
        if (dataset.hasFloatingPointElements() && (ignoreNaNs || ignoreInfs)) {
            while (iter.hasNext()) {
                final double val = dataset.getElementDoubleAbs(iter.index);
                hash = (int) (hash * 19 + Double.doubleToRawLongBits(val));
                if (Double.isNaN(val)) {
                    if (ignoreNaNs)
                        continue;
                    hasNaNs = true;
                } else if (Double.isInfinite(val)) {
                    if (ignoreInfs)
                        continue;
                }
                if (val > amax) {
                    amax = val;
                }
                if (val < amin) {
                    amin = val;
                }
            }
        } else if (dataset.hasFloatingPointElements()) {
            while (iter.hasNext()) {
                final double val = dataset.getElementDoubleAbs(iter.index);
                hash = (int) (hash * 19 + Double.doubleToRawLongBits(val));
                if (Double.isNaN(val)) {
                    hasNaNs = true;
                    continue;
                }
                if (val > amax) {
                    amax = val;
                }
                if (val < amin) {
                    amin = val;
                }
            }
        } else {
            while (iter.hasNext()) {
                final long val = dataset.getElementLongAbs(iter.index);
                hash = (int) (hash * 19 + val);
                if (val > amax) {
                    amax = val;
                }
                if (val < amin) {
                    amin = val;
                }
            }
        }

        mm.maximum = (T) (hasNaNs ? Double.NaN : DTypeUtils.fromDoubleToBiggestNumber(amax, dtype));
        mm.minimum = (T) (hasNaNs ? Double.NaN : DTypeUtils.fromDoubleToBiggestNumber(amin, dtype));
    } else {
        while (iter.hasNext()) {
            for (int j = 0; j < isize; j++) {
                final double val = dataset.getElementDoubleAbs(iter.index + j);
                hash = (int) (hash * 19 + Double.doubleToRawLongBits(val));
            }
        }

        mm.maximum = null;
        mm.minimum = null;
    }

    hash = hash * 19 + dtype * 17 + isize;
    mm.maximumPositions = null;
    mm.minimumPositions = null;
}

From source file:gdsc.core.utils.DoubleEquality.java

/**
 * Compute the number of representable doubles until a difference in significant digits
 * <p>/*w w  w. j av  a 2 s.co  m*/
 * The number of doubles are computed between Math.power(10, sig) and 1 + Math.power(10, sig)
 * 
 * @param significantDigits
 *            The significant digits
 * @return The number of representable doubles (Units in the Last Place)
 */
public static long getUlps(long significantDigits) {
    long value1 = (long) Math.pow(10.0, significantDigits - 1);
    long value2 = value1 + 1;
    long ulps = Double.doubleToRawLongBits((double) value2) - Double.doubleToRawLongBits((double) value1);
    return (ulps < 0) ? 0 : ulps;
}

From source file:r.lang.DoubleVector.java

public static boolean isNA(double input) {
    long bits = Double.doubleToRawLongBits(input);
    return bits == NA_BITS;
}

From source file:gdsc.core.utils.DoubleEquality.java

/**
 * Compute the number of bits variation using long comparisons.
 * /* ww w  .  j a  va2  s  .  com*/
 * @param A
 * @param B
 *            
 * @return How many representable doubles we are between A and B
 */
public static long complement(double A, double B) {
    long aInt = Double.doubleToRawLongBits(A);
    // Make aInt lexicographically ordered as a twos-complement long
    if (aInt < 0)
        aInt = 0x8000000000000000L - aInt;
    // Make bInt lexicographically ordered as a twos-complement long
    long bInt = Double.doubleToRawLongBits(B);
    if (bInt < 0)
        bInt = 0x8000000000000000L - bInt;
    return Math.abs(aInt - bInt);
}

From source file:com.nextgis.forestinspector.fragment.MapFragment.java

@Override
public void onPause() {
    if (null != mCurrentLocationOverlay) {
        mCurrentLocationOverlay.stopShowingCurrentLocation();
    }//  w  ww  .  j a  v a  2 s . c om
    if (null != mGpsEventSource) {
        mGpsEventSource.removeListener(this);
    }

    final SharedPreferences.Editor edit = PreferenceManager.getDefaultSharedPreferences(getActivity()).edit();
    if (null != mMap) {
        edit.putFloat(SettingsConstants.KEY_PREF_ZOOM_LEVEL, mMap.getZoomLevel());
        GeoPoint point = mMap.getMapCenter();
        edit.putLong(SettingsConstants.KEY_PREF_SCROLL_X, Double.doubleToRawLongBits(point.getX()));
        edit.putLong(SettingsConstants.KEY_PREF_SCROLL_Y, Double.doubleToRawLongBits(point.getY()));

        mMap.removeListener(this);
    }
    edit.commit();

    super.onPause();
}

From source file:gdsc.core.utils.DoubleEquality.java

/**
 * Compute the number of bits variation using long comparisons.
 * /*from  w ww  .  j a v  a 2s  .  c o m*/
 * @param A
 * @param B
 *            
 * @return How many representable doubles we are between A and B
 */
public static long signedComplement(double A, double B) {
    long aInt = Double.doubleToRawLongBits(A);
    // Make aInt lexicographically ordered as a twos-complement long
    if (aInt < 0)
        aInt = 0x8000000000000000L - aInt;
    // Make bInt lexicographically ordered as a twos-complement long
    long bInt = Double.doubleToRawLongBits(B);
    if (bInt < 0)
        bInt = 0x8000000000000000L - bInt;
    return aInt - bInt;
}

From source file:io.github.gsantner.opoc.util.AppSettingsBase.java

public void setDouble(SharedPreferences pref, @StringRes int keyResId, double value) {
    prefApp.edit().putLong(rstr(keyResId), Double.doubleToRawLongBits(value)).apply();
}

From source file:org.eclipse.january.metadata.internal.StatisticsMetadataImpl.java

/**
 * Calculate summary statistics for a dataset
 * @param ignoreNaNs if true, ignore NaNs
 * @param ignoreInfs if true, ignore infinities
 *///from  w  w w . j ava 2s .com
@SuppressWarnings("unchecked")
private SummaryStatistics[] createSummaryStats(final MaxMin<T> mm, final boolean ignoreNaNs,
        final boolean ignoreInfs) {
    final IndexIterator iter = dataset.getIterator();
    SummaryStatistics[] istats = new SummaryStatistics[isize];
    for (int i = 0; i < isize; i++) {
        istats[i] = new SummaryStatistics();
        // sum of logs is slow and we don't use it, so blocking its calculation here
        istats[i].setSumLogImpl(new NullStorelessUnivariateStatistic());
    }

    SummaryStatistics stats;
    if (isize == 1) {
        boolean hasNaNs = false;
        stats = istats[0];
        if (dataset.hasFloatingPointElements() && (ignoreNaNs || ignoreInfs)) {
            while (iter.hasNext()) {
                final double val = dataset.getElementDoubleAbs(iter.index);
                hash = (int) (hash * 19 + Double.doubleToRawLongBits(val));
                if (Double.isNaN(val)) {
                    if (ignoreNaNs)
                        continue;
                    hasNaNs = true;
                } else if (Double.isInfinite(val)) {
                    if (ignoreInfs)
                        continue;
                }
                stats.addValue(val);
            }
        } else if (dataset.hasFloatingPointElements()) {
            while (iter.hasNext()) {
                final double val = dataset.getElementDoubleAbs(iter.index);
                hash = (int) (hash * 19 + Double.doubleToRawLongBits(val));
                if (Double.isNaN(val)) {
                    hasNaNs = true;
                }
                stats.addValue(val);
            }
        } else {
            while (iter.hasNext()) {
                final long val = dataset.getElementLongAbs(iter.index);
                hash = (int) (hash * 19 + val);
                stats.addValue(val);
            }
        }

        mm.maximum = (T) (hasNaNs ? Double.NaN : DTypeUtils.fromDoubleToBiggestNumber(stats.getMax(), dtype));
        mm.minimum = (T) (hasNaNs ? Double.NaN : DTypeUtils.fromDoubleToBiggestNumber(stats.getMin(), dtype));
    } else {
        double[] vals = new double[isize];
        while (iter.hasNext()) {
            boolean okay = true;
            for (int j = 0; j < isize; j++) {
                final double val = dataset.getElementDoubleAbs(iter.index + j);
                if (ignoreNaNs && Double.isNaN(val)) {
                    okay = false;
                    break;
                }
                if (ignoreInfs && Double.isInfinite(val)) {
                    okay = false;
                    break;
                }
                vals[j] = val;
            }
            if (okay) {
                for (int j = 0; j < isize; j++) {
                    double val = vals[j];
                    istats[j].addValue(val);
                    hash = (int) (hash * 19 + Double.doubleToRawLongBits(val));
                }
            }
        }

        double[] lmax = new double[isize];
        double[] lmin = new double[isize];
        for (int j = 0; j < isize; j++) {
            stats = istats[j];
            lmax[j] = stats.getMax();
            lmin[j] = stats.getMin();
        }
        mm.maximum = (T) lmax;
        mm.minimum = (T) lmin;
    }

    hash = hash * 19 + dtype * 17 + isize;
    mm.maximumPositions = null;
    mm.minimumPositions = null;
    return istats;
}

From source file:com.github.joulupunikki.math.random.BitsStreamGenerator64.java

/**
 * Seed with strictly positive long seed. The high and low 32 bits of seed
 * are converted to two doubles//w w w . j  a  va 2s.  co m
 * <code>cos_idx = 1 + (seed >> 32) * dim;</code> and
 * <code>sin_idx = 1 + ((seed & LSB32_MASK_LONG) - 1) * dim;</code> where
 * <code>dim = 2 * STATE_WORDS</code>. These doubles are used as indexes to
 * create an int array of length <code>dim<\code> like so
 * <pre>array[i] =
 * (int) (Double.doubleToRawLongBits(Math.sin(sin_idx + i)) ^
 * Double.doubleToRawLongBits(Math.cos(cos_idx + i)));</pre> so the 32 LSBs
 * of (sin(sin_idx + i) XOR cos(cos_idx + i)) are used. Since the period of
 * sin and cos is &Pi;, in theory these values should never repeat for
 * integer arguments. In practice this may not hold due to double
 * approximation of numbers in &reals;
 *
 * @param seed
 * @return
 */
public int[] sineSeed(long seed) {
    if (seed < 1) {
        throw new NotStrictlyPositiveException(seed);
    }
    int dim = STATE_WORDS * 2 + 1;
    int[] seed_array = new int[dim];
    double cos_idx = 1 + (seed >> 32) * dim;
    double sin_idx = 1 + ((seed & LSB32_MASK_LONG) - 1) * dim;
    for (int i = 0; i < seed_array.length; i++) {
        sin_idx += 1;
        cos_idx += 1;
        int a = (int) Double.doubleToRawLongBits(FastMath.sin(sin_idx));
        int b = (int) Double.doubleToRawLongBits(FastMath.cos(cos_idx));
        seed_array[i] = a ^ b;
    }
    for (int i = 0; i < seed_array.length - 1; i++) {
        seed_array[i] ^= seed_array[i + 1];
    }
    return seed_array;
}