more tidy up of preferred serialization tests
diff --git a/test/float_tests.c b/test/float_tests.c
index a66ef04..c23a3b8 100644
--- a/test/float_tests.c
+++ b/test/float_tests.c
@@ -305,67 +305,125 @@
*/
// TODO: check these values in hex against expected encoded by hand
static const uint8_t spExpectedSmallest[] = {
- 0xB8, 0x1A, 0x64, 0x7A, 0x65, 0x72, 0x6F, 0xF9, 0x00, 0x00,
- 0x6D, 0x6E, 0x65, 0x67, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20,
- 0x7A, 0x65, 0x72, 0x6F, 0xF9, 0x80, 0x00, 0x6A, 0x69, 0x6E,
- 0x66, 0x69, 0x6E, 0x69, 0x74, 0x69, 0x74, 0x79, 0xF9, 0x7C,
- 0x00, 0x73, 0x6E, 0x65, 0x67, 0x61, 0x74, 0x69, 0x76, 0x65,
- 0x20, 0x69, 0x6E, 0x66, 0x69, 0x6E, 0x69, 0x74, 0x69, 0x74,
- 0x79, 0xF9, 0xFC, 0x00, 0x63, 0x4E, 0x61, 0x4E, 0xF9, 0x7E,
- 0x00, 0x63, 0x6F, 0x6E, 0x65, 0xF9, 0x3C, 0x00, 0x69, 0x6F,
- 0x6E, 0x65, 0x20, 0x74, 0x68, 0x69, 0x72, 0x64, 0xF9, 0x35,
- 0x55, 0x76, 0x6C, 0x61, 0x72, 0x67, 0x65, 0x73, 0x74, 0x20,
- 0x68, 0x61, 0x6C, 0x66, 0x2D, 0x70, 0x72, 0x65, 0x63, 0x69,
- 0x73, 0x69, 0x6F, 0x6E, 0xF9, 0x7B, 0xFF, 0x78, 0x20, 0x6C,
- 0x61, 0x72, 0x67, 0x65, 0x73, 0x74, 0x20, 0x68, 0x61, 0x6C,
- 0x66, 0x2D, 0x70, 0x72, 0x65, 0x63, 0x69, 0x73, 0x69, 0x6F,
- 0x6E, 0x20, 0x70, 0x6F, 0x69, 0x6E, 0x74, 0x20, 0x6F, 0x6E,
- 0x65, 0xFB, 0x40, 0xEF, 0xFC, 0x03, 0x33, 0x33, 0x33, 0x33,
- 0x78, 0x18, 0x74, 0x6F, 0x6F, 0x2D, 0x6C, 0x61, 0x72, 0x67,
- 0x65, 0x20, 0x68, 0x61, 0x6C, 0x66, 0x2D, 0x70, 0x72, 0x65,
- 0x63, 0x69, 0x73, 0x69, 0x6F, 0x6E, 0xFA, 0x47, 0x80, 0x00,
- 0x00, 0x77, 0x73, 0x6D, 0x61, 0x6C, 0x6C, 0x65, 0x73, 0x74,
- 0x20, 0x68, 0x61, 0x6C, 0x66, 0x20, 0x73, 0x75, 0x62, 0x6E,
- 0x6F, 0x72, 0x6D, 0x61, 0x6C, 0xFA, 0x33, 0x80, 0x00, 0x00,
- 0x74, 0x73, 0x6D, 0x61, 0x6C, 0x6C, 0x65, 0x73, 0x74, 0x20,
- 0x68, 0x61, 0x6C, 0x66, 0x20, 0x6E, 0x6F, 0x72, 0x6D, 0x61,
- 0x6C, 0xF9, 0x04, 0x00, 0x78, 0x19, 0x73, 0x6D, 0x61, 0x6C,
- 0x6C, 0x65, 0x73, 0x74, 0x20, 0x68, 0x61, 0x6C, 0x66, 0x20,
- 0x6E, 0x6F, 0x72, 0x6D, 0x61, 0x6C, 0x20, 0x70, 0x6C, 0x75,
- 0x73, 0xFB, 0x3F, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
- 0x75, 0x73, 0x6D, 0x61, 0x6C, 0x6C, 0x65, 0x73, 0x74, 0x20,
- 0x6E, 0x6F, 0x72, 0x6D, 0x61, 0x6C, 0x20, 0x6D, 0x69, 0x6E,
- 0x75, 0x73, 0xFB, 0x3F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0x75, 0x73, 0x6D, 0x61, 0x6C, 0x6C, 0x65, 0x73, 0x74,
- 0x20, 0x6E, 0x6F, 0x72, 0x6D, 0x61, 0x6C, 0x20, 0x6D, 0x69,
- 0x6E, 0x75, 0x73, 0xFA, 0x38, 0x00, 0x00, 0x00, 0x6E, 0x6C,
- 0x61, 0x72, 0x67, 0x65, 0x73, 0x74, 0x20, 0x73, 0x69, 0x6E,
- 0x67, 0x6C, 0x65, 0xFA, 0x7F, 0x7F, 0xFF, 0xFF, 0x73, 0x6C,
- 0x61, 0x72, 0x67, 0x65, 0x73, 0x74, 0x20, 0x73, 0x69, 0x6E,
- 0x67, 0x6C, 0x65, 0x20, 0x70, 0x6C, 0x75, 0x73, 0xFB, 0x47,
- 0xEF, 0xFF, 0xFF, 0xE0, 0x00, 0x00, 0x01, 0x73, 0x6C, 0x61,
- 0x72, 0x67, 0x65, 0x73, 0x74, 0x20, 0x73, 0x69, 0x6E, 0x67,
- 0x6C, 0x65, 0x20, 0x70, 0x6C, 0x75, 0x73, 0xFB, 0x47, 0xFF,
- 0xFF, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x6F, 0x73, 0x6D, 0x61,
- 0x6C, 0x6C, 0x65, 0x73, 0x74, 0x20, 0x73, 0x69, 0x6E, 0x67,
- 0x6C, 0x65, 0xFA, 0x00, 0x80, 0x00, 0x00, 0x74, 0x73, 0x6D,
- 0x61, 0x6C, 0x6C, 0x65, 0x73, 0x74, 0x20, 0x73, 0x69, 0x6E,
- 0x67, 0x6C, 0x65, 0x20, 0x70, 0x6C, 0x75, 0x73, 0xFB, 0x38,
- 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x75, 0x73, 0x6D,
- 0x61, 0x6C, 0x6C, 0x65, 0x73, 0x74, 0x20, 0x73, 0x69, 0x6E,
- 0x67, 0x6C, 0x65, 0x20, 0x6D, 0x69, 0x6E, 0x75, 0x73, 0xFB,
- 0x38, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x78, 0x1A,
- 0x73, 0x6D, 0x61, 0x6C, 0x6C, 0x65, 0x73, 0x74, 0x20, 0x73,
- 0x69, 0x6E, 0x67, 0x6C, 0x65, 0x20, 0x6D, 0x69, 0x6E, 0x75,
- 0x73, 0x20, 0x6D, 0x6F, 0x72, 0x65, 0xFB, 0x38, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xF9, 0xC0, 0x00, 0x70,
- 0x73, 0x69, 0x6E, 0x67, 0x6C, 0x65, 0x20, 0x70, 0x72, 0x65,
- 0x63, 0x69, 0x73, 0x69, 0x6F, 0x6E, 0xFA, 0x4B, 0x80, 0x00,
- 0x00, 0x78, 0x1A, 0x73, 0x69, 0x6E, 0x67, 0x6C, 0x65, 0x20,
- 0x77, 0x69, 0x74, 0x68, 0x20, 0x70, 0x72, 0x65, 0x63, 0x69,
- 0x73, 0x69, 0x6F, 0x6E, 0x20, 0x6C, 0x6F, 0x73, 0x73, 0xFB,
- 0x41, 0x70, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0x63,
- 0x66, 0x69, 0x6E
+ 0xB8, 0x1A,
+ 0x64, 0x7A, 0x65, 0x72, 0x6F,
+ 0xF9, 0x00, 0x00,
+
+ 0x6D, 0x6E, 0x65, 0x67, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20,
+ 0x7A, 0x65, 0x72, 0x6F,
+ 0xF9, 0x80, 0x00,
+
+ 0x6A, 0x69, 0x6E, 0x66, 0x69, 0x6E, 0x69, 0x74, 0x69, 0x74, 0x79,
+ 0xF9, 0x7C, 0x00,
+
+ 0x73, 0x6E, 0x65, 0x67, 0x61, 0x74, 0x69, 0x76, 0x65,
+ 0x20, 0x69, 0x6E, 0x66, 0x69, 0x6E, 0x69, 0x74, 0x69, 0x74,
+ 0x79,
+ 0xF9, 0xFC, 0x00,
+
+ 0x63, 0x4E, 0x61, 0x4E,
+ 0xF9, 0x7E, 0x00,
+
+ 0x63, 0x6F, 0x6E, 0x65,
+ 0xF9, 0x3C, 0x00,
+
+ 0x69, 0x6F,
+ 0x6E, 0x65, 0x20, 0x74, 0x68, 0x69, 0x72, 0x64,
+ 0xF9, 0x35, 0x55,
+
+ 0x76, 0x6C, 0x61, 0x72, 0x67, 0x65, 0x73, 0x74, 0x20,
+ 0x68, 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, 0x6C, 0x65, 0x20, 0x70, 0x6C, 0x75, 0x73,
+ 0xFB, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+
+ 0x75, 0x73, 0x6D,
+ 0x61, 0x6C, 0x6C, 0x65, 0x73, 0x74, 0x20, 0x73, 0x69, 0x6E,
+ 0x67, 0x6C, 0x65, 0x20, 0x6D, 0x69, 0x6E, 0x75, 0x73,
+ 0xFB, 0x38, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+
+ 0x78, 0x1A,
+ 0x73, 0x6D, 0x61, 0x6C, 0x6C, 0x65, 0x73, 0x74, 0x20, 0x73,
+ 0x69, 0x6E, 0x67, 0x6C, 0x65, 0x20, 0x6D, 0x69, 0x6E, 0x75,
+ 0x73, 0x20, 0x6D, 0x6F, 0x72, 0x65,
+ 0xFB, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
+ 0x03,
+ 0xF9, 0xC0, 0x00,
+
+ 0x70,
+ 0x73, 0x69, 0x6E, 0x67, 0x6C, 0x65, 0x20, 0x70, 0x72, 0x65,
+ 0x63, 0x69, 0x73, 0x69, 0x6F, 0x6E,
+ 0xFA, 0x4B, 0x80, 0x00, 0x00,
+
+ 0x78, 0x1A, 0x73, 0x69, 0x6E, 0x67, 0x6C, 0x65, 0x20,
+ 0x77, 0x69, 0x74, 0x68, 0x20, 0x70, 0x72, 0x65, 0x63, 0x69,
+ 0x73, 0x69, 0x6F, 0x6E, 0x20, 0x6C, 0x6F, 0x73, 0x73,
+ 0xFB, 0x41, 0x70, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
+
+ 0x01,
+ 0x63, 0x66, 0x69, 0x6E
};
@@ -427,21 +485,25 @@
QCBOREncode_AddDoubleToMap(&EC, "one third", 0.333251953125);
// 65504.0, converts to the large possible half-precision.
+ // 0xF9, 0x7B, 0xFF,
QCBOREncode_AddDoubleToMap(&EC, "largest half-precision", 65504.0);
// 65504.1, the double that has both to large an exponent and too
// much precision, so no conversion.
+ // 0xFB, 0x40, 0xEF, 0xFC, 0x03, 0x33, 0x33, 0x33, 0x33,
QCBOREncode_AddDoubleToMap(&EC, "largest half-precision point one", 65504.1);
// 65536.0 has an exponent of 16, which is larger than 15, the
// largest half-precision exponent. It is the exponent, not
// precision loss that prevents conversion to half. It does convert
// to single precision.
+ // 0xFA, 0x47, 0x80, 0x00, 0x00,
QCBOREncode_AddDoubleToMap(&EC, "too-large half-precision", 65536.0);
// 5.9604644775390625E-8, the smallest possible half-precision
// subnormal, but digitis are lost converting to half, so this is
// output as a double.
+ // 0xFA, 0x33, 0x80, 0x00, 0x00, TODO: is this right?
QCBOREncode_AddDoubleToMap(&EC,
"smallest half subnormal",
MAKE_DOUBLE(0x3e70000000000000));
@@ -449,6 +511,7 @@
// 0.00006103515625, the double value that converts to the smallest
// possible half-precision normal. which is what should appear in
// the output.
+ // 0xF9, 0x04, 0x00,
QCBOREncode_AddDoubleToMap(&EC,
"smallest half normal",
MAKE_DOUBLE(0x3f10000000000000));
@@ -456,6 +519,7 @@
// 0.000061035156250000014 ,the double value that is a tiny bit
// greater than smallest possible half-precision normal. It will be
// output as a double because converting it will reduce precision.
+ // 0xFB, 0x3F, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
QCBOREncode_AddDoubleToMap(&EC,
"smallest half normal plus",
MAKE_DOUBLE(0x3f10000000000001));
@@ -464,6 +528,7 @@
// smaller than the smallest half-precision normal. This will fail
// to convert to a half-precision because both the exponent is too
// small and the precision is too large for a half-precision.
+ // 0xFB, 0x3F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
QCBOREncode_AddDoubleToMap(&EC,
"smallest normal minus",
MAKE_DOUBLE(0x3f0fffffffffffff));
@@ -473,12 +538,14 @@
// because precision would be lost. (This would fit into a
// half-precision subnormal, but there is no converstion to
// that). This ends up encoded as a single-precision.
+ // 0xFA, 0x38, 0x00, 0x00, 0x00,
QCBOREncode_AddDoubleToMap(&EC,
"smallest normal minus",
MAKE_DOUBLE(0x3f00000000000000));
// 3.4028234664e38, the value that converts to the largest possible
// single-precision.
+ // 0xFA, 0x7F, 0x7F, 0xFF, 0xFF,
QCBOREncode_AddDoubleToMap(&EC,
"largest single",
MAKE_DOUBLE(0x47efffffe0000000));
@@ -486,6 +553,7 @@
// 3.402823466385289E38, sightly larger than the largest possible
// possible precision. Conversion fails because precision would be
// lost.
+ // 0xFB, 0x47, 0xEF, 0xFF, 0xFF, 0xE0, 0x00, 0x00, 0x01,
QCBOREncode_AddDoubleToMap(&EC,
"largest single plus",
MAKE_DOUBLE(0x47efffffe0000001));
@@ -493,12 +561,14 @@
// 6.8056469327705772E38, slightly more larger than the largers
// possible single precision. Conversion fails because exponent is
// too large.
+ // 0xFB, 0x47, 0xFF, 0xFF, 0xFF, 0xE0, 0x00, 0x00, 0x00,
QCBOREncode_AddDoubleToMap(&EC,
"largest single plus",
MAKE_DOUBLE(0x47ffffffe0000000));
// 1.1754943508222875E-38, The double value that converts to the
// smallest possible single-precision normal
+ // 0xFA, 0x00, 0x80, 0x00, 0x00,
QCBOREncode_AddDoubleToMap(&EC,
"smallest single",
MAKE_DOUBLE(0x3810000000000000));
@@ -506,12 +576,14 @@
// 1.1754943508222878E-38, double value that is slightly larger
// than the smallest single-precision normal. Conversion fails
// because of precision
+ // 0xFB, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
QCBOREncode_AddDoubleToMap(&EC,
"smallest single plus",
MAKE_DOUBLE(0x3810000000000001));
// 1.1754943508222874E-38, slightly smaller than the smallest
- // single-precision normal. Conversion fails because of precsiion
+ // single-precision normal. Conversion fails because of precision
+ // 0xFB, 0x38, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
QCBOREncode_AddDoubleToMap(&EC,
"smallest single minus",
MAKE_DOUBLE(0x380fffffffffffff));
@@ -519,6 +591,7 @@
// 5.8774717541114375E-39, slightly smaller than the smallest
// single-precision normal. Conversion fails because the exponent
// is too small.
+ // 0xFB, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
QCBOREncode_AddDoubleToMap(&EC,
"smallest single minus more",
MAKE_DOUBLE(0x3800000000000000));
@@ -533,6 +606,7 @@
// 16777217, One more than above. Too much precision for a single
// so no conversion.
+ // 0xFB, 0x41, 0x70, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
QCBOREncode_AddDoubleToMap(&EC, "single with precision loss", 16777217);
// Just a convenient marker when cutting and pasting encoded CBOR