NI JSON number-of-digits bug

Issue #13 resolved
James Powell repo owner created an issue

The NI primitive has a big in the number of digits used in flattening floats: * EXT flattened to only 8 digits * SGL flattened to an excessive 18 digits

NI might not consider the SGL thing a bug, as the emphasise JSON as a machine-to-machine format of IEEE numbers, and are interested in being sure that they get bit-for-bit recovery. But 18 digits is excessive I think, and makes for very large files. DBLs are flattened by NI to 20 digits, higher than our preferred 15 digits, but this is a smaller difference.

Comments (5)

  1. James Powell reporter

    Speed experiments suggest the following for flattening an array of 10,000 SGLs:

    • NI-JSON --> 900 ns per SGL
    • Array-to-Spreadsheet:
      • %.7g --> 630 ns
      • %_7g --> 6000 ns
      • %.7e --> 430 ns
  2. James Powell reporter

    %.7g is problematic because it has fewer significant figures for some numbers.

    %_7g is what I would prefer for human readability, but %.7e (engineering notation always) is fine for long data files. So I am considering using %#_7g for short SGL arrays (which humans might want to read) and %.7e for long ones.

  3. James Powell reporter

    Problem with using Spreadsheet function is that it uses Inf and -Inf rather than the Infinity and -Infinity of the NI JSON function. But using "Format into String" in a loop allows us to swap these, while still having performance of 820 ns, slightly faster than NI JSON.

  4. Log in to comment