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.jfolson.hive.serde.RTypedBytesOutput.java

/**
 * Writes a double as a typed bytes sequence.
 *
 * @param d/*w ww .j av  a  2  s .com*/
 *          the double to be written
 * @throws IOException
 */
public void writeDouble(double d) throws IOException {
    out.write(RType.DOUBLE.code);
    out.writeLong(Double.doubleToRawLongBits(d));
}

From source file:net.gsantner.opoc.preference.SharedPreferencesPropertyBackend.java

public void setDouble(@StringRes int keyResourceId, double value, final SharedPreferences... pref) {
    setLong(rstr(keyResourceId), Double.doubleToRawLongBits(value));
}

From source file:net.gsantner.opoc.preference.SharedPreferencesPropertyBackend.java

public void setDouble(String key, double value, final SharedPreferences... pref) {
    setLong(key, Double.doubleToRawLongBits(value));
}

From source file:com.xingcloud.xa.hbase.util.ByteUtils.java

/**
 * Serialize a double as the IEEE 754 double format output. The resultant array will be 8 bytes long.
 *
 * @param d value/*from w w  w .ja v  a  2 s .c  o  m*/
 * @return the double represented as byte []
 */
public static byte[] toBytes(final double d) {
    // Encode it as a long
    return ByteUtils.toBytes(Double.doubleToRawLongBits(d));
}

From source file:net.gsantner.opoc.preference.SharedPreferencesPropertyBackend.java

public double getDouble(String key, double defaultValue, final SharedPreferences... pref) {
    return Double.longBitsToDouble(getLong(key, Double.doubleToRawLongBits(defaultValue), gp(pref)));
}

From source file:com.idylwood.utils.MathUtils.java

public static final double abs(final double d) {
    return Double.longBitsToDouble(Long.MAX_VALUE & Double.doubleToRawLongBits(d));
}

From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.util.StatHelper.java

/**
 * Converts a primitive double into an array of bytes
 *
 * @param data      a primitive double//w w  w. ja va2 s.  c o  m
 * @return          a byte array
 */
public static byte[] toByteArrays(double data) {
    return toByteArrays(Double.doubleToRawLongBits(data));
}

From source file:com.secupwn.aimsicd.ui.activities.MapViewerOsmDroid.java

/**
 * Description:    Loads Signal Strength Database details to plot on the map,
 * only entries which have a location (lon, lat) are used.
 *///  w w w.j  a  va 2  s .c  om
private void loadEntries() {

    new AsyncTask<Void, Void, GeoPoint>() {
        @Override
        protected GeoPoint doInBackground(Void... voids) {
            //int signal;

            mCellTowerGridMarkerClusterer.getItems().clear();

            loadOcidMarkersByNetwork();

            List<CellTowerMarker> items = new LinkedList<>();

            @Cleanup
            Realm realm = Realm.getDefaultInstance();

            RealmResults<BaseTransceiverStation> baseStations = realm.allObjects(BaseTransceiverStation.class);
            if (baseStations.size() > 0) {
                for (BaseTransceiverStation baseStation : baseStations) {
                    if (isCancelled()) {
                        return null;
                    }
                    // The indexing here is that of DB table
                    final int cellID = baseStation.getCellId();
                    final int lac = baseStation.getLocationAreaCode();
                    final int mcc = baseStation.getMobileCountryCode();
                    final int mnc = baseStation.getMobileNetworkCode();
                    final int psc = baseStation.getPrimaryScramblingCode();

                    final double dLat = baseStation.getGpsLocation().getLatitude();
                    final double dLng = baseStation.getGpsLocation().getLongitude();

                    if (Double.doubleToRawLongBits(dLat) == 0 && Double.doubleToRawLongBits(dLng) == 0) {
                        continue;
                    }
                    // TODO this (signal) is not in DBi_bts
                    // signal = 1;
                    //c.getInt(c.getColumnIndex(DBTableColumnIds.DBE_IMPORT_AVG_SIGNAL));  // signal
                    // In case of missing or negative signal, set a default fake signal,
                    // so that we can still draw signal circles.  ?
                    //if (signal <= 0) {
                    //    signal = 20;
                    //}

                    if (Double.doubleToRawLongBits(dLat) != 0 || Double.doubleToRawLongBits(dLng) != 0) {
                        loc = new GeoPoint(dLat, dLng);

                        CellTowerMarker ovm = new CellTowerMarker(MapViewerOsmDroid.this, mMap,
                                "Cell ID: " + cellID, "", loc,
                                new MarkerData(getApplicationContext(), String.valueOf(cellID),
                                        String.valueOf(loc.getLatitude()), String.valueOf(loc.getLongitude()),
                                        String.valueOf(lac), String.valueOf(mcc), String.valueOf(mnc),
                                        String.valueOf(psc), null, "", false));
                        // The pin of our current position
                        ovm.setIcon(getResources().getDrawable(R.drawable.ic_map_pin_blue));

                        items.add(ovm);
                    }

                }
            } else {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Helpers.msgLong(MapViewerOsmDroid.this, getString(R.string.no_tracked_locations_found));
                    }
                });
            }

            GeoPoint ret = new GeoPoint(0, 0);
            if (mBound) {
                try {
                    int mcc = mAimsicdService.getCell().getMobileCountryCode();
                    GpsLocation d = mDbHelper.getDefaultLocation(realm, mcc);
                    ret = new GeoPoint(d.getLatitude(), d.getLongitude());
                } catch (Exception e) {
                    log.error("Error getting default location!", e);
                }
            }
            // plot neighboring cells
            while (mAimsicdService == null) {
                try {
                    if (isCancelled()) {
                        return null;
                    }
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    log.warn("thread interrupted", e);
                }
            }
            List<Cell> nc = mAimsicdService.getCellTracker().updateNeighboringCells();
            for (Cell cell : nc) {
                if (isCancelled()) {
                    return null;
                }
                try {
                    loc = new GeoPoint(cell.getLat(), cell.getLon());
                    CellTowerMarker ovm = new CellTowerMarker(MapViewerOsmDroid.this, mMap,
                            getString(R.string.cell_id_label) + cell.getCellId(), "", loc,
                            new MarkerData(getApplicationContext(), String.valueOf(cell.getCellId()),
                                    String.valueOf(loc.getLatitude()), String.valueOf(loc.getLongitude()),
                                    String.valueOf(cell.getLocationAreaCode()),
                                    String.valueOf(cell.getMobileCountryCode()),
                                    String.valueOf(cell.getMobileNetworkCode()),
                                    String.valueOf(cell.getPrimaryScramblingCode()),
                                    String.valueOf(cell.getRat()), "", false));

                    // The pin of other BTS
                    ovm.setIcon(getResources().getDrawable(R.drawable.ic_map_pin_orange));
                    items.add(ovm);
                } catch (Exception e) {
                    log.error("Error plotting neighboring cells", e);
                }
            }

            mCellTowerGridMarkerClusterer.addAll(items);

            return ret;
        }

        /**
         *  TODO:  We need a manual way to add our own location in case:
         *          a) GPS is jammed or not working
         *          b) WiFi location is not used
         *          c) Default MCC is too far off
         *
         * @param defaultLoc Default location to open map on
         */
        @Override
        protected void onPostExecute(GeoPoint defaultLoc) {
            if (loc != null && (Double.doubleToRawLongBits(loc.getLatitude()) != 0
                    && Double.doubleToRawLongBits(loc.getLongitude()) != 0)) {
                mMap.getController().setZoom(16);
                mMap.getController().animateTo(new GeoPoint(loc.getLatitude(), loc.getLongitude()));
            } else {
                if (mBound) {
                    // Try and find last known location and zoom there
                    GeoLocation lastLoc = mAimsicdService.lastKnownLocation();
                    if (lastLoc != null) {
                        loc = new GeoPoint(lastLoc.getLatitudeInDegrees(), lastLoc.getLongitudeInDegrees());

                        mMap.getController().setZoom(16);
                        mMap.getController().animateTo(new GeoPoint(loc.getLatitude(), loc.getLongitude()));
                    } else {
                        //Use MCC to move camera to an approximate location near Countries Capital
                        loc = defaultLoc;

                        mMap.getController().setZoom(12);
                        mMap.getController().animateTo(new GeoPoint(loc.getLatitude(), loc.getLongitude()));
                    }
                }
            }
            if (mCellTowerGridMarkerClusterer != null) {
                if (BuildConfig.DEBUG && mCellTowerGridMarkerClusterer.getItems() != null) {
                    log.verbose("CellTowerMarkers.invalidate() markers.size():"
                            + mCellTowerGridMarkerClusterer.getItems().size());
                }
                //Drawing markers of cell tower immediately as possible
                mCellTowerGridMarkerClusterer.invalidate();
            }
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

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

private void saveSteps() {
    // Try saving the steps, if they are valid. Else, just ignore saving.
    SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
    try {//w  ww . ja v  a  2s .  co  m
        double coarse = Double.parseDouble(_coarseStepEditText.getText().toString());
        double fine = Double.parseDouble(_fineStepEditText.getText().toString());
        String coarseKey = _uniquePrefix + _currentDevice.getName() + "coarse";
        String fineKey = _uniquePrefix + _currentDevice.getName() + "fine";
        editor.putLong(coarseKey, Double.doubleToRawLongBits(coarse));
        editor.putLong(fineKey, Double.doubleToRawLongBits(fine));
        editor.apply();
    } catch (Exception e) {
        // Probably invalid steps
    }
}

From source file:be.brunoparmentier.openbikesharing.app.activities.StationsListActivity.java

private void upgradeAppToVersion13() {
    if (settings.contains(PREF_KEY_FAV_STATIONS)) {
        Set<String> favorites = settings.getStringSet(PREF_KEY_FAV_STATIONS, new HashSet<String>());

        for (String favorite : favorites) {
            stationsDataSource.addFavoriteStation(favorite);
        }//from ww  w . j  av a2  s .  com

        settings.edit().remove(PREF_KEY_FAV_STATIONS).apply();
    }

    if (!settings.contains(PREF_KEY_NETWORK_LATITUDE) || !settings.contains(PREF_KEY_NETWORK_LONGITUDE)) {
        settings.edit()
                .putLong(PREF_KEY_NETWORK_LATITUDE,
                        Double.doubleToRawLongBits(bikeNetwork.getLocation().getLatitude()))
                .putLong(PREF_KEY_NETWORK_LONGITUDE,
                        Double.doubleToRawLongBits(bikeNetwork.getLocation().getLongitude()))
                .apply();
    }
}