Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions demo/node/rntuple_test32.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ import { readFileSync } from 'fs';


// convert float to hex representation based on IEEE-754 and C99 standard
function floatToHex(num)
function floatToHex(num, field)
{
if (num === 0)
return (Object.is(num, -0) ? '-' : '') + '0x0p+0';

// convert num to Float32 for correct precision
if (field.startsWith("Float")) {
const tmp = new DataView(new ArrayBuffer(4));
tmp.setFloat32(0, num, false);
num = tmp.getFloat32(0, false);
}

const buf = new ArrayBuffer(8), // 8 Byte == 64 Bit
view = new DataView(buf);
view.setFloat64(0, num, false);
Expand Down Expand Up @@ -59,7 +66,7 @@ async function read_file(input_root = 'rntuple_test32.root', input_ref = 'rntupl
selector.Process = function(entryIndex) {
for (const field of fields) {
try {
const value = floatToHex(this.tgtobj[field]), expected = original[entryIndex][field];
const value = floatToHex(this.tgtobj[field], field), expected = original[entryIndex][field];

if (value !== expected) {
console.error(`FAILURE: ${field} at entry ${entryIndex} expected ${expected},`+
Expand Down
8 changes: 4 additions & 4 deletions demo/node/rntuple_test32.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
[
{
"FloatReal32Quant1": "-0x1p+0",
"FloatReal32Quant8": "-0x1.fdfdfdfdfdfep-2",
"FloatReal32Quant32": "0x1.0000000a1516p-2",
"FloatReal32Quant8": "-0x1.fdfdfep-2",
"FloatReal32Quant32": "0x1p-2",
"DoubleReal32Quant1": "0x1p+0",
"DoubleReal32Quant20": "0x1p+0",
"DoubleReal32Quant32": "0x1.000000118p+1"
},
{
"FloatReal32Quant1": "0x1p+0",
"FloatReal32Quant8": "0x1.0101010101p-8",
"FloatReal32Quant8": "0x1.010102p-8",
"FloatReal32Quant32": "0x1.921fbp-31",
"DoubleReal32Quant1": "0x1p+0",
"DoubleReal32Quant20": "0x1.00001p-20",
"DoubleReal32Quant32": "0x0p+0"
},
{
"FloatReal32Quant1": "0x1p+0",
"FloatReal32Quant8": "0x1.0101010101p-8",
"FloatReal32Quant8": "0x1.010102p-8",
"FloatReal32Quant32": "0x1.921fbp-31",
"DoubleReal32Quant1": "0x1p+0",
"DoubleReal32Quant20": "0x1.00001p-20",
Expand Down