Search in sources :

Example 1 with Int8Array

use of elemental2.core.Int8Array in project console by hal.

the class DataInput method readDouble.

double readDouble() {
    byte[] doubleBytes = new byte[8];
    readFully(doubleBytes);
    ArrayBuffer buffer = new ArrayBuffer(8);
    Int8Array array = new Int8Array(buffer);
    DataView view = new DataView(buffer);
    for (int i = 0; i < doubleBytes.length; i++) {
        array.setAt(i, (double) doubleBytes[i]);
    }
    return view.getFloat64(0);
}
Also used : Int8Array(elemental2.core.Int8Array) DataView(elemental2.core.DataView) ArrayBuffer(elemental2.core.ArrayBuffer)

Example 2 with Int8Array

use of elemental2.core.Int8Array in project console by hal.

the class DataOutput method writeDouble.

void writeDouble(double v) {
    ArrayBuffer buffer = new ArrayBuffer(8);
    Int8Array array = new Int8Array(buffer);
    DataView view = new DataView(buffer);
    view.setFloat64(0, v);
    for (int i = 0; i < array.getLength(); i++) {
        bytes.push(array.getAt(i).byteValue());
    }
}
Also used : Int8Array(elemental2.core.Int8Array) DataView(elemental2.core.DataView) ArrayBuffer(elemental2.core.ArrayBuffer)

Aggregations

ArrayBuffer (elemental2.core.ArrayBuffer)2 DataView (elemental2.core.DataView)2 Int8Array (elemental2.core.Int8Array)2