FasterXML / jackson-dataformats-binary

Uber-project for standard Jackson binary format backends: avro, cbor, ion, protobuf, smile
Apache License 2.0
310 stars 133 forks source link

Add `CBORGenerat.Feature.WRITE_MINIMAL_DOUBLES` for writing `double`s as `float`s if safe to do so #356

Closed here-abarany closed 1 year ago

here-abarany commented 1 year ago

Enabling WRITE_MINIMAL_DOUBLES works similarly to WRITE_MINIMAL_INTS, choosing to use a smaller data representation (single-precision float) when the conversion will result in no loss of data. This can provide a substantial savings for data that contains many doubles that don't require full precision.

Cleaned up some of the writing code for floats and doubles to avoid code duplication, and reserve the proper amount of space for output for both types.

here-abarany commented 1 year ago

@cowtowncoder Just wanted to make sure you saw this PR. It's a relatively small addition, especially compared to my previous submission.

cowtowncoder commented 1 year ago

Excellent, @here-abarany -- sounds like useful feature, simple enough implementation. Could even consider possibility of porting to Smile format backend. But for now I'll merge it.

cowtowncoder commented 1 year ago

Ok, merged in 2.15 then to master.

here-abarany commented 1 year ago

Thanks!