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:org.asoem.greyfish.utils.math.ApproximationMath.java

/**
 * An exp approximation based on the article
 * "A Fast, Compact Approximation of the Exponential Function", Nicol N. Schraudolph, Neural Computation (1999)
 * It has a max relative error of about 3e-2 for |value| < 700.0 or so, and no accuracy at all outside this range.
 *
 * @param x the exponent//from   w  w w.  ja va2 s  . c  o  m
 * @return an approximated value for e^x
 */
public static double exp(final double x) {
    final long tmp = (long) (EXP_A * x + (EXP_B - EXP_C));
    return Double.longBitsToDouble(tmp << 32);
}

From source file:ByteConvert.java

public static final double[] byte2Double(byte[] inData, boolean byteSwap) {
    int j = 0, upper, lower;
    int length = inData.length / 8;
    double[] outData = new double[length];
    if (!byteSwap)
        for (int i = 0; i < length; i++) {
            j = i * 8;//from w ww .j a va  2 s  .  c  o  m
            upper = (((inData[j] & 0xff) << 24) + ((inData[j + 1] & 0xff) << 16) + ((inData[j + 2] & 0xff) << 8)
                    + ((inData[j + 3] & 0xff) << 0));
            lower = (((inData[j + 4] & 0xff) << 24) + ((inData[j + 5] & 0xff) << 16)
                    + ((inData[j + 6] & 0xff) << 8) + ((inData[j + 7] & 0xff) << 0));
            outData[i] = Double.longBitsToDouble((((long) upper) << 32) + (lower & 0xffffffffl));
        }
    else
        for (int i = 0; i < length; i++) {
            j = i * 8;
            upper = (((inData[j + 7] & 0xff) << 24) + ((inData[j + 6] & 0xff) << 16)
                    + ((inData[j + 5] & 0xff) << 8) + ((inData[j + 4] & 0xff) << 0));
            lower = (((inData[j + 3] & 0xff) << 24) + ((inData[j + 2] & 0xff) << 16)
                    + ((inData[j + 1] & 0xff) << 8) + ((inData[j] & 0xff) << 0));
            outData[i] = Double.longBitsToDouble((((long) upper) << 32) + (lower & 0xffffffffl));
        }

    return outData;
}

From source file:com.l2jfree.network.ReceivableBasePacket.java

protected final double readF() {
    long result = _data[_off++] & 0xff;
    result |= _data[_off++] << 8 & 0xff00;
    result |= _data[_off++] << 16 & 0xff0000;
    result |= _data[_off++] << 24 & 0xff000000;
    result |= _data[_off++] << 32 & 0xff00000000l;
    result |= _data[_off++] << 40 & 0xff0000000000l;
    result |= _data[_off++] << 48 & 0xff000000000000l;
    result |= _data[_off++] << 56 & 0xff00000000000000l;
    return Double.longBitsToDouble(result);
}

From source file:cross.io.misc.Base64Util.java

/**
 *
 * @param raw// w w w  .  j  a  v  a  2s . c  o  m
 * @param bigEndian
 * @param length
 * @return
 */
public static double[] byteArrayToDoubleArray(final byte[] raw, final boolean bigEndian, final int length) {
    final double[] d = new double[length];
    int i = 0;
    if (bigEndian) {
        for (int iii = 0; iii < raw.length; iii += 8) {
            long ieee754 = 0;
            ieee754 |= ((raw[iii]) & 0xff);
            ieee754 <<= 8;
            ieee754 |= ((raw[iii + 1]) & 0xff);
            ieee754 <<= 8;
            ieee754 |= ((raw[iii + 2]) & 0xff);
            ieee754 <<= 8;
            ieee754 |= ((raw[iii + 3]) & 0xff);
            ieee754 <<= 8;
            ieee754 |= ((raw[iii + 4]) & 0xff);
            ieee754 <<= 8;
            ieee754 |= ((raw[iii + 5]) & 0xff);
            ieee754 <<= 8;
            ieee754 |= ((raw[iii + 6]) & 0xff);
            ieee754 <<= 8;
            ieee754 |= ((raw[iii + 7]) & 0xff);
            final double aDouble = Double.longBitsToDouble(ieee754);
            d[i++] = aDouble;
        }
    } else {
        for (int iii = 0; iii < raw.length; iii += 8) {
            long ieee754 = 0;
            ieee754 |= ((raw[iii + 7]) & 0xff);
            ieee754 <<= 8;
            ieee754 |= ((raw[iii + 6]) & 0xff);
            ieee754 <<= 8;
            ieee754 |= ((raw[iii + 5]) & 0xff);
            ieee754 <<= 8;
            ieee754 |= ((raw[iii + 4]) & 0xff);
            ieee754 <<= 8;
            ieee754 |= ((raw[iii + 3]) & 0xff);
            ieee754 <<= 8;
            ieee754 |= ((raw[iii + 2]) & 0xff);
            ieee754 <<= 8;
            ieee754 |= ((raw[iii + 1]) & 0xff);
            ieee754 <<= 8;
            ieee754 |= ((raw[iii]) & 0xff);
            final double aDouble = Double.longBitsToDouble(ieee754);
            d[i++] = aDouble;
        }
    }
    return d;
}

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.//from  ww w. jav  a 2 s . c  om
 *
 * @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:com.antsdb.saltedfish.server.mysql.util.BufferUtils.java

public static double readDouble(ByteBuf in) {
    return Double.longBitsToDouble(readLongLong(in));
}

From source file:org.apache.cassandra.stress.generate.FasterRandom.java

public double nextDouble() {
    return Double.longBitsToDouble(nextLong());
}

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

public final static long round(final double d) {
    final long l = ONE_HALF | sign(d); // equivalent to d < 0 ? -0.5 : 0.5;
    return (long) (d + Double.longBitsToDouble(l));
}

From source file:com.marklogic.io.Decoder.java

public double decodeDouble() throws IOException {
    long lobits = decode32bits() & 0xffffffffL;
    long hibits = decode32bits() & 0xffffffffL;
    long bits = (hibits << 32) | lobits;
    return Double.longBitsToDouble(bits);
}

From source file:com.dal.vv.type.AbstractValue.java

@Override
public double asDouble() {
    return Double.longBitsToDouble(asLong());
}