RyanSkraba commented on code in PR #2529:
URL: https://github.com/apache/avro/pull/2529#discussion_r2570817592
##########
lang/java/avro/src/test/java/org/apache/avro/io/TestJsonDecoder.java:
##########
@@ -66,6 +69,29 @@ private void checkNumeric(String type, Object value) throws
Exception {
}
}
+ @Test
+ void testFloatPrecision() throws Exception {
+ String def = "{\"type\":\"record\",\"name\":\"X\",\"fields\":" +
"[{\"type\":\"float\",\"name\":\"n\"}]}";
+ Schema schema = new Schema.Parser().parse(def);
+ DatumReader<GenericRecord> reader = new GenericDatumReader<>(schema);
+
+ float value = 33.33000183105469f;
+ GenericData.Record record = new GenericData.Record(schema);
+ record.put(0, value);
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ JsonEncoder encoder = EncoderFactory.get().jsonEncoder(schema, out);
+
+ DatumWriter<GenericRecord> writer = new GenericDatumWriter<>(schema);
+ writer.write(record, encoder);
+ encoder.flush();
+ // check the whole float precision is kept.
+ assertEquals("{\"n\":33.33000183105469}", out.toString());
Review Comment:
The correct decimal string representation of `33.33000183105469f` is
probably `"n": 33.33` though...
I think this test would fail if we put in `33000183105555f` and expected
_that_ precision out, for example.
Or if we put in `33.33f` and expected `"n": 33.33` out (which I would
definitely expect).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]