Big simplification of floating point API. Now does preferred encoding of floats like preferred encoding of ints per upcoming update to CBOR RFC
diff --git a/test/float_tests.c b/test/float_tests.c
index 37e7691..a1c8c8d 100644
--- a/test/float_tests.c
+++ b/test/float_tests.c
@@ -38,135 +38,6 @@
 #include <math.h> // For INFINITY and NAN and isnan()
 
 
-/*
- Output from http://cbor.me
- [0.0,
- 1.0,
- 1.100000023841858,
- 1.5,
- 65504.0,
- 100000.0,
- 3.4028234663852886e+38,
- Infinity,
- 5.960464477539063e-8,
- 0.00006103515625,
- -4.0,
- -4.099999904632568,
- NaN,
- Infinity,
- -Infinity,
- 0.0,
- 1.0,
- 1.1,
- 1.5,
- 65504.0,
- 100000.0,
- 3.4028234663852886e+38,
- 1.0e+300,
- 5.960464477539063e-8,
- 0.00006103515625,
- -4.0,
- -4.1,
- NaN,
- Infinity,
- -Infinity]
- */
-
-static uint8_t spExpectedEncodedFloat[] = {
-    0x98, 0x1e, 0xfa, 0x00, 0x00, 0x00, 0x00, 0xfa,
-    0x3f, 0x80, 0x00, 0x00, 0xfa, 0x3f, 0x8c, 0xcc,
-    0xcd, 0xfa, 0x3f, 0xc0, 0x00, 0x00, 0xfa, 0x47,
-    0x7f, 0xe0, 0x00, 0xfa, 0x47, 0xc3, 0x50, 0x00,
-    0xfa, 0x7f, 0x7f, 0xff, 0xff, 0xfa, 0x7f, 0x80,
-    0x00, 0x00, 0xfa, 0x33, 0x80, 0x00, 0x00, 0xfa,
-    0x38, 0x80, 0x00, 0x00, 0xfa, 0xc0, 0x80, 0x00,
-    0x00, 0xfa, 0xc0, 0x83, 0x33, 0x33, 0xfa, 0x7f,
-    0xc0, 0x00, 0x00, 0xfa, 0x7f, 0x80, 0x00, 0x00,
-    0xfa, 0xff, 0x80, 0x00, 0x00, 0xfb, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb, 0x3f,
-    0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb,
-    0x3f, 0xf1, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a,
-    0xfb, 0x3f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0xfb, 0x40, 0xef, 0xfc, 0x00, 0x00, 0x00,
-    0x00, 0x00, 0xfb, 0x40, 0xf8, 0x6a, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0xfb, 0x47, 0xef, 0xff, 0xff,
-    0xe0, 0x00, 0x00, 0x00, 0xfb, 0x7e, 0x37, 0xe4,
-    0x3c, 0x88, 0x00, 0x75, 0x9c, 0xfb, 0x3e, 0x70,
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb, 0x3f,
-    0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb,
-    0xc0, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0xfb, 0xc0, 0x10, 0x66, 0x66, 0x66, 0x66, 0x66,
-    0x66, 0xfb, 0x7f, 0xf8, 0x00, 0x00, 0x00, 0x00,
-    0x00, 0x00, 0xfb, 0x7f, 0xf0, 0x00, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0xfb, 0xff, 0xf0, 0x00, 0x00,
-    0x00, 0x00, 0x00, 0x00};
-
-
-int FloatValuesTest1()
-{
-    QCBOREncodeContext ECtx;
-    int nReturn = 0;
-    
-    UsefulBuf_MAKE_STACK_UB(EncodedStorage, 220);
-    
-    QCBOREncode_Init(&ECtx, EncodedStorage);
-    QCBOREncode_OpenArray(&ECtx);
-    
-    // These are all samples published
-    // in RFC 7049.
-    QCBOREncode_AddFloat(&ECtx, 0.0);
-    QCBOREncode_AddFloat(&ECtx, 1.0);
-    QCBOREncode_AddFloat(&ECtx, 1.1); // appx
-    QCBOREncode_AddFloat(&ECtx, 1.5);
-    QCBOREncode_AddFloat(&ECtx, 65504.0);
-    QCBOREncode_AddFloat(&ECtx, 100000.0);
-    QCBOREncode_AddFloat(&ECtx, 3.4028234663852886e+38);
-    QCBOREncode_AddFloat(&ECtx, 1.0e+300); // Infinity?
-    QCBOREncode_AddFloat(&ECtx, 5.960464477539063e-8);
-    QCBOREncode_AddFloat(&ECtx, 0.00006103515625);
-    QCBOREncode_AddFloat(&ECtx, -4.0);
-    QCBOREncode_AddFloat(&ECtx, -4.1); // appx
-    
-    QCBOREncode_AddFloat(&ECtx, NAN);
-    QCBOREncode_AddFloat(&ECtx, INFINITY);
-    QCBOREncode_AddFloat(&ECtx, -INFINITY);
-    
-    
-    QCBOREncode_AddDouble(&ECtx, 0.0);
-    QCBOREncode_AddDouble(&ECtx, 1.0);
-    QCBOREncode_AddDouble(&ECtx, 1.1); // appx
-    QCBOREncode_AddDouble(&ECtx, 1.5);
-    QCBOREncode_AddDouble(&ECtx, 65504.0);
-    QCBOREncode_AddDouble(&ECtx, 100000.0);
-    QCBOREncode_AddDouble(&ECtx, 3.4028234663852886e+38);
-    QCBOREncode_AddDouble(&ECtx, 1.0e+300); // Infinity?
-    QCBOREncode_AddDouble(&ECtx, 5.960464477539063e-8);
-    QCBOREncode_AddDouble(&ECtx, 0.00006103515625);
-    QCBOREncode_AddDouble(&ECtx, -4.0);
-    QCBOREncode_AddDouble(&ECtx, -4.1); // appx
-    
-    QCBOREncode_AddDouble(&ECtx, NAN);
-    QCBOREncode_AddDouble(&ECtx, INFINITY);
-    QCBOREncode_AddDouble(&ECtx, -INFINITY);
-    
-    QCBOREncode_CloseArray(&ECtx);
-    
-    UsefulBufC Encoded;
-    if(QCBOREncode_Finish2(&ECtx, &Encoded)) {
-        nReturn = -1;
-    }
-    
-    if(UsefulBuf_Compare(Encoded, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spExpectedEncodedFloat))) {
-        nReturn = -2;
-    }
-    
-    //printencoded(pEncoded, nEncodedLen);
-    
-    return(nReturn);
-}
-
-
-
 
 static const uint8_t spExpectedHalf[] = {
     0xB1,
@@ -219,50 +90,6 @@
 };
 
 
-
-int HalfPrecisionEncodeBasicTests()
-{
-    UsefulBuf_MAKE_STACK_UB(EncodedHalfsMem, 250);
-
-    QCBOREncodeContext EC;
-    QCBOREncode_Init(&EC, EncodedHalfsMem);
-    // These are mostly from https://en.wikipedia.org/wiki/Half-precision_floating-point_format
-    QCBOREncode_OpenMap(&EC);
-    QCBOREncode_AddFloatAsHalfToMap(&EC, "zero", 0.00F);
-    QCBOREncode_AddFloatAsHalfToMap(&EC, "infinitity", INFINITY);
-    QCBOREncode_AddFloatAsHalfToMap(&EC, "negative infinitity", -INFINITY);
-    QCBOREncode_AddFloatAsHalfToMap(&EC, "NaN", NAN);
-    QCBOREncode_AddFloatAsHalfToMap(&EC, "one", 1.0F);
-    QCBOREncode_AddFloatAsHalfToMap(&EC, "one third", 0.333251953125F);
-    QCBOREncode_AddFloatAsHalfToMap(&EC, "largest half-precision",65504.0F);
-    // Float 65536.0F is 0x47800000 in hex. It has an exponent of 16, which is larger than 15, the largest half-precision exponent
-    QCBOREncode_AddFloatAsHalfToMap(&EC, "too-large half-precision", 65536.0F);
-    // Should convert to smallest possible half precision which is encodded as 0x00 0x01 or 5.960464477539063e-8
-    QCBOREncode_AddFloatAsHalfToMap(&EC, "smallest subnormal", 0.0000000596046448F);
-    QCBOREncode_AddFloatAsHalfToMap(&EC, "smallest normal",    0.0000610351526F); // in hex single is 0x387fffff, exponent -15, significand 7fffff
-    QCBOREncode_AddFloatAsHalfToMap(&EC, "biggest subnormal",  0.0000610351563F); // in hex single is 0x38800000, exponent -14, significand 0
-    QCBOREncode_AddFloatAsHalfToMap(&EC, "subnormal single", 4e-40F); 
-    QCBOREncode_AddFloatAsHalfToMapN(&EC, 3, -2.0F);
-    QCBOREncode_AddFloatAsHalfToMapN(&EC, 4, UsefulBufUtil_CopyUint32ToFloat(0x7fc00000L)); // qNaN
-    QCBOREncode_AddFloatAsHalfToMapN(&EC, 5, UsefulBufUtil_CopyUint32ToFloat(0x7f800001L)); // sNaN
-    QCBOREncode_AddFloatAsHalfToMapN(&EC, 6, UsefulBufUtil_CopyUint32ToFloat(0x7fc0f00fL)); // qNaN with payload
-    QCBOREncode_AddFloatAsHalfToMapN(&EC, 7, UsefulBufUtil_CopyUint32ToFloat(0x7f80f00fL)); // sNaN with payload
-    QCBOREncode_CloseMap(&EC);
-    
-    UsefulBufC EncodedHalfs;
-    int nReturn = QCBOREncode_Finish2(&EC, &EncodedHalfs);
-    if(nReturn) {
-        return -1;
-    }
-    
-    if(UsefulBuf_Compare(EncodedHalfs, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spExpectedHalf))) {
-        return -3;
-    }
-    
-    return 0;
-}
-
-
 int HalfPrecisionDecodeBasicTests()
 {
     UsefulBufC HalfPrecision = UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spExpectedHalf);
@@ -367,54 +194,6 @@
 }
 
 
-int HalfPrecisionTransitiveTest()
-{
-    for(uint32_t uHalfP = 0; uHalfP < 0xffff; uHalfP += 1) {
-        // Contruct the CBOR for the half-precision float by hand
-        UsefulBuf_MAKE_STACK_UB(EncodedCBORMem, 3);
-        UsefulOutBuf UOB;
-        UsefulOutBuf_Init(&UOB, EncodedCBORMem);
-        
-        const uint8_t uHalfPrecInitialByte = HALF_PREC_FLOAT + (CBOR_MAJOR_TYPE_SIMPLE << 5); // 0xf9
-        UsefulOutBuf_AppendByte(&UOB, uHalfPrecInitialByte); // The initial byte for a half-precision float
-        UsefulOutBuf_AppendUint16(&UOB, (uint16_t)uHalfP);
-        
-        
-        // Now parse the hand-constructed CBOR. This will invoke the conversion to a float
-        QCBORDecodeContext DC;
-        QCBORDecode_Init(&DC, UsefulOutBuf_OutUBuf(&UOB), 0);
-        
-        QCBORItem Item;
-        QCBORDecode_GetNext(&DC, &Item);
-        if(Item.uDataType != QCBOR_TYPE_FLOAT) {
-            return -1;
-        }
-        
-        //printf("%04x  QCBOR:%15.15f  \n", uHalfP,Item.val.fnum);
-
-        
-        // Now generate CBOR with the half-precision value. This will invoke the conversion from float to half
-        UsefulBuf_MAKE_STACK_UB(OtherEncodedCBORMem, 5);
-        QCBOREncodeContext EC;
-        QCBOREncode_Init(&EC, OtherEncodedCBORMem);
-        QCBOREncode_AddFloatAsHalf(&EC, Item.val.fnum);
-        UsefulBufC EnCBOR;
-        QCBOREncode_Finish2(&EC, &EnCBOR); // todo check return code
-        
-        
-        // Finally parse the CBOR by hand to get at half-precision that was actually encoded.
-        UsefulInputBuf UIB;
-        UsefulInputBuf_Init(&UIB, EnCBOR);
-        if(UsefulInputBuf_GetByte(&UIB) != uHalfPrecInitialByte) {
-            return -2;
-        }
-        if(UsefulInputBuf_GetUint16(&UIB) != uHalfP) { // the moment of truth did we get back what we started with?
-            return -3;
-        }
-    }
-    
-    return 0;
-}
 
 
 int HalfPrecisionAgainstRFCCodeTest()
diff --git a/test/float_tests.h b/test/float_tests.h
index 15a94b1..6bc0af1 100644
--- a/test/float_tests.h
+++ b/test/float_tests.h
@@ -35,14 +35,8 @@
 #ifndef float_tests_h
 #define float_tests_h
 
-int FloatValuesTest1(void);
-
-int HalfPrecisionEncodeBasicTests(void);
-
 int HalfPrecisionDecodeBasicTests(void);
 
-int HalfPrecisionTransitiveTest(void);
-
 int DoubleAsSmallestTest(void);
 
 int HalfPrecisionAgainstRFCCodeTest(void);
diff --git a/test/qcbor_encode_tests.c b/test/qcbor_encode_tests.c
index 485f47e..28bb817 100644
--- a/test/qcbor_encode_tests.c
+++ b/test/qcbor_encode_tests.c
@@ -49,7 +49,7 @@
 
 //#define PRINT_FUNCTIONS_FOR_DEBUGGINGXX
 
-#if PRINT_FUNCTIONS_FOR_DEBUGGINGXX
+#if  PRINT_FUNCTIONS_FOR_DEBUGGINGXX
 #include <stdio.h>
 
 // ifdef these out to not have compiler warnings
@@ -235,7 +235,7 @@
 
 
 static const uint8_t spExpectedEncodedAll[] = {
- 0x98, 0x29, 0x66, 0x55, 0x49, 0x4e, 0x54, 0x36, 0x32, 0xd8,
+ 0x98, 0x22, 0x66, 0x55, 0x49, 0x4e, 0x54, 0x36, 0x32, 0xd8,
  0x64, 0x1a, 0x05, 0x5d, 0x23, 0x15, 0x65, 0x49, 0x4e, 0x54,
  0x36, 0x34, 0xd8, 0x4c, 0x1b, 0x00, 0x00, 0x00, 0x12, 0x16,
  0xaf, 0x2b, 0x15, 0x00, 0x38, 0x2b, 0xa4, 0x63, 0x4c, 0x42,
@@ -244,16 +244,7 @@
  0x53, 0x20, 0x4b, 0x49, 0x4e, 0x44, 0x20, 0x4f, 0x46, 0x20,
  0x4c, 0x4f, 0x4e, 0x47, 0x3b, 0x00, 0x00, 0x02, 0x2d, 0x9a,
  0xc6, 0x94, 0x55, 0x3a, 0x05, 0xf5, 0xe0, 0xff, 0x3a, 0x2f,
- 0xaf, 0x07, 0xff, 0x65, 0x4a, 0x61, 0x69, 0x6d, 0x65, 0xd8,
- 0x58, 0xfa, 0x40, 0x49, 0x0f, 0xd0, 0x66, 0x53, 0x74, 0x72,
- 0x65, 0x65, 0x74, 0xd8, 0x63, 0xfb, 0x40, 0x21, 0x4f, 0x01,
- 0x96, 0xd8, 0xf4, 0xf9, 0xfa, 0x3f, 0x80, 0x00, 0x00, 0xfb,
- 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x63,
- 0x66, 0x6f, 0x6f, 0xfa, 0x45, 0x98, 0xb8, 0x00, 0x39, 0x03,
- 0xe6, 0xfa, 0x44, 0x79, 0xc0, 0x00, 0x66, 0x66, 0x6f, 0x6f,
- 0x66, 0x6f, 0x6f, 0xfb, 0x41, 0x58, 0xf7, 0x7d, 0xc0, 0x00,
- 0x00, 0x00, 0x39, 0xaf, 0xc6, 0xfb, 0x40, 0xf5, 0xba, 0x70,
- 0x00, 0x00, 0x00, 0x00, 0xc1, 0x1a, 0x8e, 0x15, 0x1c, 0x8a,
+ 0xaf, 0x07, 0xff, 0xc1, 0x1a, 0x8e, 0x15, 0x1c, 0x8a,
  0xa3, 0x74, 0x4c, 0x6f, 0x6e, 0x67, 0x4c, 0x69, 0x76, 0x65,
  0x44, 0x65, 0x6e, 0x69, 0x73, 0x52, 0x69, 0x74, 0x63, 0x68,
  0x69, 0x65, 0xc1, 0x1a, 0x53, 0x72, 0x4e, 0x00, 0x66, 0x74,
@@ -499,22 +490,6 @@
    QCBOREncode_AddInt64ToMap(&ECtx, "NEGLBLTHAT IS KIND OF LONG", -2394893489238);
    QCBOREncode_AddInt64ToMapN(&ECtx, -100000000, -800000000);
    QCBOREncode_CloseMap(&ECtx);
-
-   // floats and doubles
-   QCBOREncode_AddTag(&ECtx, 88);
-   QCBOREncode_AddFloat_2(&ECtx, "Jaime", QCBOR_NO_INT_LABEL, 3.14159);
-   QCBOREncode_AddTag(&ECtx, 99);
-   QCBOREncode_AddDouble_2(&ECtx, "Street", QCBOR_NO_INT_LABEL, 8.654309);
-   QCBOREncode_AddFloat(&ECtx, 1);
-   QCBOREncode_AddDouble(&ECtx, 1);
-
-   // floats and doubles that go in map
-   QCBOREncode_OpenMap(&ECtx);
-   QCBOREncode_AddFloatToMap(&ECtx, "foo", 4887);
-   QCBOREncode_AddFloatToMapN(&ECtx, -999, 999);
-   QCBOREncode_AddDoubleToMap(&ECtx, "foofoo", 6544887);
-   QCBOREncode_AddDoubleToMapN(&ECtx, -44999, 88999);
-   QCBOREncode_CloseMap(&ECtx);
    
    // Epoch Date
    QCBOREncode_AddDateEpoch(&ECtx, 2383748234);
diff --git a/test/run_tests.c b/test/run_tests.c
index 9c420d1..ec91dac 100644
--- a/test/run_tests.c
+++ b/test/run_tests.c
@@ -122,7 +122,6 @@
     TEST_ENTRY(NestedMapTestIndefLen),
     TEST_ENTRY(ParseSimpleTest),
     TEST_ENTRY(EncodeRawTest),
-    TEST_ENTRY(FloatValuesTest1),
     TEST_ENTRY(RTICResultsTest),
     TEST_ENTRY(MapEncodeTest),
     TEST_ENTRY(ArrayNestingTest1),
@@ -148,9 +147,7 @@
     TEST_ENTRY(IntegerValuesParseTest),
     TEST_ENTRY(MemPoolTest),
     TEST_ENTRY(IndefiniteLengthStringTest),
-    TEST_ENTRY(HalfPrecisionEncodeBasicTests),
     TEST_ENTRY(HalfPrecisionDecodeBasicTests),
-    TEST_ENTRY(HalfPrecisionTransitiveTest),
     TEST_ENTRY(DoubleAsSmallestTest),
     TEST_ENTRY(HalfPrecisionAgainstRFCCodeTest),
     TEST_ENTRY(BstrWrapTest),