List of usage examples for java.lang Double doubleToRawLongBits
@HotSpotIntrinsicCandidate public static native long doubleToRawLongBits(double value);
From source file:com.asburymotors.android.disneysocal.common.Utils.java
/** * Store the location in the app preferences. *///from w w w.ja v a 2s.co m public static void storeLocation(Context context, LatLng location) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences.Editor editor = prefs.edit(); editor.putLong(PREFERENCES_LAT, Double.doubleToRawLongBits(location.latitude)); editor.putLong(PREFERENCES_LNG, Double.doubleToRawLongBits(location.longitude)); editor.apply(); }
From source file:com.idylwood.utils.MathUtils.java
public static final long sign(final double d) { return Double.doubleToRawLongBits(d) & Long.MIN_VALUE; }
From source file:com.aurel.track.fieldType.runtime.matchers.run.DoubleMatcherRT.java
/** * Whether the value matches or not/*from ww w.ja v a2 s .c om*/ * * @param attributeValue * @return */ @Override public boolean match(Object attributeValue) { Boolean nullMatch = nullMatcher(attributeValue); if (nullMatch != null) { return nullMatch.booleanValue(); } if (attributeValue == null || matchValue == null) { return false; } Double attributeValueDouble = null; Double matcherValueDouble = null; try { attributeValueDouble = (Double) attributeValue; } catch (Exception e) { LOGGER.error("Converting the attribute value " + attributeValue + " of type " + attributeValue.getClass().getName() + " to Double failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); return false; } try { matcherValueDouble = (Double) matchValue; } catch (Exception e) { LOGGER.warn("Converting the matcher value " + matchValue + " of type " + matchValue.getClass().getName() + " to Double failed with " + e.getMessage(), e); return false; } switch (relation) { case MatchRelations.EQUAL: return (Double.doubleToRawLongBits(attributeValueDouble.doubleValue()) - Double.doubleToRawLongBits(matcherValueDouble.doubleValue()) == 0); case MatchRelations.NOT_EQUAL: return (Double.doubleToRawLongBits(attributeValueDouble.doubleValue()) - Double.doubleToRawLongBits(matcherValueDouble.doubleValue()) != 0); case MatchRelations.GREATHER_THAN: return attributeValueDouble.doubleValue() > matcherValueDouble.doubleValue(); case MatchRelations.GREATHER_THAN_EQUAL: return attributeValueDouble.doubleValue() >= matcherValueDouble.doubleValue(); case MatchRelations.LESS_THAN: return attributeValueDouble.doubleValue() < matcherValueDouble.doubleValue(); case MatchRelations.LESS_THAN_EQUAL: return attributeValueDouble.doubleValue() <= matcherValueDouble.doubleValue(); default: return false; } }
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 w ww. j a va2s . c o m*/ * 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 * ±<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 ± * <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.asalfo.wiulgi.util.Utils.java
/** * Store the location in the app preferences. *//*from ww w . j a v a 2 s . c om*/ public static void storeLocation(Context context, @NonNull LatLng location) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences.Editor editor = prefs.edit(); editor.putLong(PREFERENCES_LAT, Double.doubleToRawLongBits(location.latitude)); editor.putLong(PREFERENCES_LNG, Double.doubleToRawLongBits(location.longitude)); editor.apply(); }
From source file:org.briljantframework.data.Is.java
/** * Check if value is NA//from w w w. ja v a2s. c o m * * @param value the value * @return true if value is NA */ public static boolean NA(double value) { return Double.isNaN(value) && (Double.doubleToRawLongBits(value) & Na.DOUBLE_NA_MASK) == Na.DOUBLE_NA_RES; }
From source file:es.udc.gii.common.eaf.stoptest.BitwiseConvergence.java
/** * Calculates the convergence rate between two individuals. */// w ww . jav a 2 s. com private double convergence(Individual i1, Individual i2) { double convergence = 0.0; /* Asume both individuals have the same number of genes !! */ int genes = i1.getChromosomeAt(0).length; /* For each pair of genes */ for (int i = 0; i < genes; i++) { /* Get the value of the genes. Note that only individuals which have * a double as an internal value are considered. */ double d1 = i1.getChromosomeAt(0)[i]; double d2 = i2.getChromosomeAt(0)[i]; /* Get the binary codification of the values. */ Long lg1 = new Long(Double.doubleToRawLongBits(d1)); Long lg2 = new Long(Double.doubleToRawLongBits(d2)); /* Perform a bitwise XOR operation. Bitpositions that are identical * will yield a 0 and bitpositions which differ will yield a 1. So * we are counting the bits in which the two individuals *differ* */ Long lg = new Long(lg1.longValue() ^ lg2.longValue()); /* Count the number of bits in which the two individuals differ. */ convergence += Long.bitCount(lg); } /* Get the average bitwise difference. */ convergence /= Long.SIZE * genes; /* Get the average convergence. */ convergence = 1 - convergence; return convergence; }
From source file:frk.gpssimulator.GpsSimulator.java
/** * Set new position of vehicle based on current position and vehicle speed. *//*from w w w . j a v a2s .co m*/ void moveVehicle() { Double distance = speedInMps * reportInterval / 1000.0; Double distanceFromStart = currentPosition.getDistanceFromStart() + distance; Double excess = 0.0; // amount by which next postion will exceed end // point of present leg for (int i = currentPosition.getLeg().getId(); i < legs.size(); i++) { Leg currentLeg = legs.get(i); excess = distanceFromStart > currentLeg.getLength() ? distanceFromStart - currentLeg.getLength() : 0.0; if (Double.doubleToRawLongBits(excess) == 0) { // this means new position falls within current leg currentPosition.setDistanceFromStart(distanceFromStart); currentPosition.setLeg(currentLeg); Point newPosition = NavUtils.getPosition(currentLeg.getStartPosition(), distanceFromStart, currentLeg.getHeading()); currentPosition.setPosition(newPosition); return; } distanceFromStart = excess; } // if we've reached here it means vehicle has moved beyond end of path // so go back to start of path setStartPosition(); }
From source file:com.nextgis.maplibui.activity.AttributesActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_attributes); setToolbar(R.id.main_toolbar);//from www . ja va 2s . c o m mTable = (TableFixHeaders) findViewById(R.id.attributes); mToolbar = (BottomToolbar) findViewById(R.id.bottom_toolbar); mToolbar.inflateMenu(R.menu.attributes_table); mToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { int i = item.getItemId(); if (i == R.id.menu_zoom) { IGISApplication application = (IGISApplication) getApplication(); MapDrawable map = (MapDrawable) application.getMap(); if (null != map) { if (mLayer.getGeometryType() == GeoConstants.GTPoint || mLayer.getGeometryType() == GeoConstants.GTMultiPoint) map.zoomToExtent(mLayer.getFeature(mId).getGeometry().getEnvelope(), 18); else map.zoomToExtent(mLayer.getFeature(mId).getGeometry().getEnvelope()); SharedPreferences.Editor edit = PreferenceManager .getDefaultSharedPreferences(AttributesActivity.this).edit(); edit.putFloat(SettingsConstantsUI.KEY_PREF_ZOOM_LEVEL, map.getZoomLevel()); GeoPoint point = map.getMapCenter(); edit.putLong(SettingsConstantsUI.KEY_PREF_SCROLL_X, Double.doubleToRawLongBits(point.getX())); edit.putLong(SettingsConstantsUI.KEY_PREF_SCROLL_Y, Double.doubleToRawLongBits(point.getY())); edit.commit(); } finish(); return true; } else if (i == R.id.menu_delete) { Snackbar snackbar = Snackbar.make(findViewById(R.id.container), getString(R.string.delete_item_done), Snackbar.LENGTH_LONG) .setAction(R.string.undo, new View.OnClickListener() { @Override public void onClick(View view) { } }).setCallback(new Snackbar.Callback() { @Override public void onDismissed(Snackbar snackbar, int event) { super.onDismissed(snackbar, event); if (event == DISMISS_EVENT_MANUAL) return; if (event != DISMISS_EVENT_ACTION) { mLayer.deleteAddChanges(mId); } } @Override public void onShown(Snackbar snackbar) { super.onShown(snackbar); } }); View view = snackbar.getView(); TextView textView = (TextView) view.findViewById(R.id.snackbar_text); textView.setTextColor( ContextCompat.getColor(view.getContext(), com.nextgis.maplibui.R.color.color_white)); snackbar.show(); mToolbar.setVisibility(View.GONE); return true; } else if (i == R.id.menu_edit) { ((IVectorLayerUI) mLayer).showEditForm(AttributesActivity.this, mId, null); return true; } return false; } }); mToolbar.setNavigationIcon(R.drawable.ic_action_cancel_dark); mToolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mToolbar.setVisibility(View.GONE); } }); mToolbar.setVisibility(View.GONE); mLayerId = Constants.NOT_FOUND; if (savedInstanceState != null) mLayerId = savedInstanceState.getInt(ConstantsUI.KEY_LAYER_ID); else mLayerId = getIntent().getIntExtra(ConstantsUI.KEY_LAYER_ID, mLayerId); mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { mTable.setAdapter(getAdapter()); } }; }
From source file:com.aurel.track.fieldType.runtime.matchers.run.AccountingTimeMatcherRT.java
/** * Whether the value matches or not//from ww w . j av a 2 s . co m * * @param attributeValue * @return */ @Override public boolean match(Object attributeValue) { Boolean nullMatch = nullMatcher(attributeValue); if (nullMatch != null) { return nullMatch.booleanValue(); } if (attributeValue == null || matchValue == null) { return false; } AccountingTimeTO attributeValueAccountingTime = null; AccountingTimeTO matcherValueAccountingTime = null; try { attributeValueAccountingTime = (AccountingTimeTO) attributeValue; } catch (Exception e) { LOGGER.error("Converting the attribute value " + attributeValue + " of type " + attributeValue.getClass().getName() + " to AccountingTimeTO failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); return false; } try { matcherValueAccountingTime = (AccountingTimeTO) matchValue; } catch (Exception e) { LOGGER.warn("Converting the matcher value " + matchValue + " of type " + matchValue.getClass().getName() + " to AccountingTimeTO failed with " + e.getMessage(), e); return false; } Double attributeValueDouble = attributeValueAccountingTime.getValue(); Double matcherValueDouble = matcherValueAccountingTime.getValue(); if (attributeValueDouble == null || matcherValueDouble == null) { return false; } Integer attributeValueUnit = attributeValueAccountingTime.getUnit(); Integer matcherValueUnit = matcherValueAccountingTime.getUnit(); if (attributeValueUnit == null) { attributeValueUnit = TIMEUNITS.HOURS; } if (matcherValueUnit == null) { matcherValueUnit = TIMEUNITS.HOURS; } if (!attributeValueUnit.equals(matcherValueUnit)) { if (attributeValueUnit.intValue() != TIME_UNIT.HOUR) { attributeValueDouble = AccountingBL.transformToTimeUnits(attributeValueDouble, this.getHourPerWorkday(), attributeValueUnit, TIME_UNIT.HOUR).doubleValue(); } if (matcherValueUnit.intValue() != TIME_UNIT.HOUR) { matcherValueDouble = AccountingBL.transformToTimeUnits(matcherValueDouble, this.getHourPerWorkday(), matcherValueUnit, TIME_UNIT.HOUR).doubleValue(); } } switch (relation) { case MatchRelations.EQUAL: return (Double.doubleToRawLongBits(attributeValueDouble.doubleValue()) - Double.doubleToRawLongBits(matcherValueDouble.doubleValue()) == 0); case MatchRelations.NOT_EQUAL: return (Double.doubleToRawLongBits(attributeValueDouble.doubleValue()) - Double.doubleToRawLongBits(matcherValueDouble.doubleValue()) != 0); case MatchRelations.GREATHER_THAN: return attributeValueDouble.doubleValue() > matcherValueDouble.doubleValue(); case MatchRelations.GREATHER_THAN_EQUAL: return attributeValueDouble.doubleValue() >= matcherValueDouble.doubleValue(); case MatchRelations.LESS_THAN: return attributeValueDouble.doubleValue() < matcherValueDouble.doubleValue(); case MatchRelations.LESS_THAN_EQUAL: return attributeValueDouble.doubleValue() <= matcherValueDouble.doubleValue(); default: return false; } }