Skip to content

NaN values in Float64Array are incorrectly serialised as null #292

@triglav

Description

@triglav

Float64Array accepts only numbers, null is not a valid value for this type.
Unfortunatelly NaN values within the array are serialised as null, which then naturally comes back after deserialising as 0.
This essentially results in data loss/corruption.

Simple example to reproduce/observe the problem:

const a0 = new Float64Array([NaN, 0, NaN, 1]);
const a1 = stringify(a0);
console.log("a1", a1); // [null,0,null,1]
const a2 = parse<Float64Array>(a1);
console.log("a2", a2); // [0, 0, 0, 1]

const b0 = NaN;
const b1 = stringify(b0);
console.log("b1", b1); // "NaN"
const b2 = parse<number>(b1);
console.log("b2", b2); // NaN

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions