List of usage examples for java.lang Double doubleToRawLongBits
@HotSpotIntrinsicCandidate public static native long doubleToRawLongBits(double value);
From source file:Main.java
/** * Returns unbiased exponent of a <code>double</code>. *//* w w w . ja v a2 s.c o m*/ public static int getExponent(double d) { /* * Bitwise convert d to long, mask out exponent bits, shift * to the right and then subtract out double's bias adjust to * get true exponent value. */ return (int) (((Double.doubleToRawLongBits(d) & DoubleConsts.EXP_BIT_MASK) >> (DoubleConsts.SIGNIFICAND_WIDTH - 1)) - DoubleConsts.EXP_BIAS); }
From source file:Main.java
/** * Returns the floating-point value adjacent to <code>d</code> in * the direction of positive infinity. This method is * semantically equivalent to <code>nextAfter(d, * Double.POSITIVE_INFINITY)</code>; however, a <code>nextUp</code> * implementation may run faster than its equivalent * <code>nextAfter</code> call. * * <p>Special Cases:// w w w . j a va 2 s.co m * <ul> * <li> If the argument is NaN, the result is NaN. * * <li> If the argument is positive infinity, the result is * positive infinity. * * <li> If the argument is zero, the result is * <code>Double.MIN_VALUE</code> * * </ul> * * @param d starting floating-point value * @return The adjacent floating-point value closer to positive * infinity. * @author Joseph D. Darcy */ public static double nextUp(double d) { if (isNaN(d) || d == Double.POSITIVE_INFINITY) return d; else { d += 0.0d; return Double.longBitsToDouble(Double.doubleToRawLongBits(d) + ((d >= 0.0d) ? +1L : -1L)); } }
From source file:Main.java
/** * Returns the floating-point value adjacent to <code>d</code> in * the direction of negative infinity. This method is * semantically equivalent to <code>nextAfter(d, * Double.NEGATIVE_INFINITY)</code>; however, a * <code>nextDown</code> implementation may run faster than its * equivalent <code>nextAfter</code> call. * * <p>Special Cases://from w ww. j a v a 2 s . c om * <ul> * <li> If the argument is NaN, the result is NaN. * * <li> If the argument is negative infinity, the result is * negative infinity. * * <li> If the argument is zero, the result is * <code>-Double.MIN_VALUE</code> * * </ul> * * @param d starting floating-point value * @return The adjacent floating-point value closer to negative * infinity. * @author Joseph D. Darcy */ public static double nextDown(double d) { if (isNaN(d) || d == Double.NEGATIVE_INFINITY) return d; else { if (d == 0.0) return -Double.MIN_VALUE; else return Double.longBitsToDouble(Double.doubleToRawLongBits(d) + ((d > 0.0d) ? -1L : +1L)); } }
From source file:com.l2jfree.network.SendableBasePacket.java
protected final void writeF(double org) { long value = Double.doubleToRawLongBits(org); _bao.write((int) (value & 0xff)); _bao.write((int) (value >> 8 & 0xff)); _bao.write((int) (value >> 16 & 0xff)); _bao.write((int) (value >> 24 & 0xff)); _bao.write((int) (value >> 32 & 0xff)); _bao.write((int) (value >> 40 & 0xff)); _bao.write((int) (value >> 48 & 0xff)); _bao.write((int) (value >> 56 & 0xff)); }
From source file:Main.java
/** * Returns unbiased exponent of a <code>double</code>; for * subnormal values, the number is treated as if it were * normalized. That is for all finite, non-zero, positive numbers * <i>x</i>, <code>scalb(<i>x</i>, -ilogb(<i>x</i>))</code> is * always in the range [1, 2).//from www .ja v a 2s . c o m * <p> * Special cases: * <ul> * <li> If the argument is NaN, then the result is 2<sup>30</sup>. * <li> If the argument is infinite, then the result is 2<sup>28</sup>. * <li> If the argument is zero, then the result is -(2<sup>28</sup>). * </ul> * * @param d floating-point number whose exponent is to be extracted * @return unbiased exponent of the argument. * @author Joseph D. Darcy */ public static int ilogb(double d) { int exponent = getExponent(d); switch (exponent) { case DoubleConsts.MAX_EXPONENT + 1: // NaN or infinity if (isNaN(d)) return (1 << 30); // 2^30 else // infinite value return (1 << 28); // 2^28 // break; case DoubleConsts.MIN_EXPONENT - 1: // zero or subnormal if (d == 0.0) { return -(1 << 28); // -(2^28) } else { long transducer = Double.doubleToRawLongBits(d); /* * To avoid causing slow arithmetic on subnormals, * the scaling to determine when d's significand * is normalized is done in integer arithmetic. * (there must be at least one "1" bit in the * significand since zero has been screened out. */ // isolate significand bits transducer &= DoubleConsts.SIGNIF_BIT_MASK; assert (transducer != 0L); // This loop is simple and functional. We might be // able to do something more clever that was faster; // e.g. number of leading zero detection on // (transducer << (# exponent and sign bits). while (transducer < (1L << (DoubleConsts.SIGNIFICAND_WIDTH - 1))) { transducer *= 2; exponent--; } exponent++; assert (exponent >= DoubleConsts.MIN_EXPONENT - (DoubleConsts.SIGNIFICAND_WIDTH - 1) && exponent < DoubleConsts.MIN_EXPONENT); return exponent; } // break; default: assert (exponent >= DoubleConsts.MIN_EXPONENT && exponent <= DoubleConsts.MAX_EXPONENT); return exponent; // break; } }
From source file:Main.java
public static byte[] toByta(double data) { return toByta(Double.doubleToRawLongBits(data)); }
From source file:frk.gpssimulator.support.NavUtils.java
/** * Returns coordinates of position which is given distance and bearing from given point. * @param pt1//w w w. j a v a 2s.co m * @param dist * @param brg * @return */ public static Point getPosition(Point pt1, double d, double brg) { if (Double.doubleToRawLongBits(d) == 0) { return pt1; } double lat1 = Math.toRadians(pt1.getLatitude()); double lon1 = Math.toRadians(pt1.getLongitude()); double brgAsRadians = Math.toRadians(brg); double lat2 = Math.asin(Math.sin(lat1) * Math.cos(d / EARTH_RADIUS_IN_METERS) + Math.cos(lat1) * Math.sin(d / EARTH_RADIUS_IN_METERS) * Math.cos(brgAsRadians)); double x = Math.sin(brgAsRadians) * Math.sin(d / EARTH_RADIUS_IN_METERS) * Math.cos(lat1); double y = Math.cos(d / EARTH_RADIUS_IN_METERS) - Math.sin(lat1) * Math.sin(lat2); double lon2 = lon1 + Math.atan2(x, y); return new Point(Math.toDegrees(lat2), Math.toDegrees(lon2), null); }
From source file:Main.java
/** * Returns the first floating-point argument with the sign of the * second floating-point argument. Note that unlike the {@link * FpUtils#copySign(double, double) copySign} method, this method * does not require NaN <code>sign</code> arguments to be treated * as positive values; implementations are permitted to treat some * NaN arguments as positive and other NaN arguments as negative * to allow greater performance./*w w w.j av a2 s . co m*/ * * @param magnitude the parameter providing the magnitude of the result * @param sign the parameter providing the sign of the result * @return a value with the magnitude of <code>magnitude</code> * and the sign of <code>sign</code>. * @author Joseph D. Darcy */ public static double rawCopySign(double magnitude, double sign) { return Double.longBitsToDouble((Double.doubleToRawLongBits(sign) & (DoubleConsts.SIGN_BIT_MASK)) | (Double.doubleToRawLongBits(magnitude) & (DoubleConsts.EXP_BIT_MASK | DoubleConsts.SIGNIF_BIT_MASK))); }
From source file:demo.support.NavUtils.java
/** * Returns coordinates of position which is given distance and bearing from given point. * @param pt1/*ww w .j av a 2 s. co m*/ * @param dist * @param brg * @return */ public static Point getPosition(Point pt1, double d, double brg) { if (Double.doubleToRawLongBits(d) == 0) { return pt1; } double lat1 = Math.toRadians(pt1.getLatitude()); double lon1 = Math.toRadians(pt1.getLongitude()); double brgAsRadians = Math.toRadians(brg); double lat2 = Math.asin(Math.sin(lat1) * Math.cos(d / EARTH_RADIUS_IN_METERS) + Math.cos(lat1) * Math.sin(d / EARTH_RADIUS_IN_METERS) * Math.cos(brgAsRadians)); double x = Math.sin(brgAsRadians) * Math.sin(d / EARTH_RADIUS_IN_METERS) * Math.cos(lat1); double y = Math.cos(d / EARTH_RADIUS_IN_METERS) - Math.sin(lat1) * Math.sin(lat2); double lon2 = lon1 + Math.atan2(x, y); return new Point(Math.toDegrees(lat2), Math.toDegrees(lon2)); }
From source file:it.unibo.alchemist.utils.MathUtils.java
/** * Compares two double values, taking care of computing a relative error * tolerance threshold./*from w ww . j a va 2 s. co m*/ * * @param a * first double * @param b * second double * @return true if the double are equals with a precision order of * DOUBLE_EQUALITY_EPSILON */ public static boolean exactEquals(final double a, final double b) { return Double.doubleToRawLongBits(a) == Double.doubleToRawLongBits(b); }