Skip to content

Floating point precision and missing integer fields #90

Description

@marklombardi

Thank-you for creating a great library. I am seeing a performance improvement of approximately 10:1 over JsonCpp. File sizes tested up to 3 MB.

Q1:
I have noticed that tables with integer fields with 0 values are not printed. Is this a bug or have I missed something in the documentation?

Q2:
I would like to specify the floating point precision (significant figures) to use when writing floats or doubles? Ideally through a configuration option. In my application I'd like to reduce the number of significant figures to 5. This will reduce the size of my JSON files by a factor of 2.

This is the relevant piece of code. The precision is hard coded. However, it is easily parameterized for the standard library use case. For the grisu3 library function grisu3_print_double, its unclear as to how to modify the function to limit the precision. Could you perhaps provide a code snippet that includes the changes by adding a precision parameter to the grisu3_print_double call?

flatcc/include/flatcc/portable/pprintfp.h

#ifdef grisu3_print_double_is_defined
/* Currently there is not special support for floats. */
#define print_float(n, p) grisu3_print_double((float)(n), (p))
#define print_double(n, p) grisu3_print_double((double)(n), (p))
#else
#include <stdio.h>
#define print_float(n, p) sprintf(p, "%.9g", (float)(n))
#define print_double(n, p) sprintf(p, "%.17g", (double)(n))
#endif

Thank-you!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions