more progress on disabling float
diff --git a/src/ieee754.c b/src/ieee754.c
index 226282a..1538033 100644
--- a/src/ieee754.c
+++ b/src/ieee754.c
@@ -10,7 +10,7 @@
Created on 7/23/18
=============================================================================*/
-#ifndef QCBOR_CONFIG_DISABLE_ENCODE_IEEE754
+#ifndef QCBOR_DISABLE_PREFERRED_FLOAT
#include "ieee754.h"
#include <string.h> // For memcpy()
@@ -595,4 +595,4 @@
return result;
}
-#endif /* QCBOR_CONFIG_DISABLE_ENCODE_IEEE754 */
+#endif /* QCBOR_DISABLE_PREFERRED_FLOAT */
diff --git a/src/ieee754.h b/src/ieee754.h
index 72444f1..54d4e57 100644
--- a/src/ieee754.h
+++ b/src/ieee754.h
@@ -10,7 +10,7 @@
Created on 7/23/18
=============================================================================*/
-#ifndef QCBOR_CONFIG_DISABLE_ENCODE_IEEE754
+#ifndef QCBOR_DISABLE_PREFERRED_FLOAT
#ifndef ieee754_h
#define ieee754_h
@@ -155,7 +155,7 @@
#endif /* ieee754_h */
-#endif /* QCBOR_CONFIG_DISABLE_ENCODE_IEEE754 */
+#endif /* QCBOR_DISABLE_PREFERRED_FLOAT */
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index 99060f3..3c11a64 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -570,7 +570,7 @@
// caught before this is called.
case HALF_PREC_FLOAT:
-#ifndef QCBOR_CONFIG_DISABLE_ENCODE_IEEE754
+#ifndef QCBOR_DISABLE_PREFERRED_FLOAT
// The caast to uint16_t is safe because the encoded value
// was 16 bits. It was widened to 64 bits to be passed in here.
pDecodedItem->val.dfnum = IEEE754_HalfToDouble((uint16_t)uNumber);
@@ -580,7 +580,7 @@
#endif
break;
case SINGLE_PREC_FLOAT:
-#ifndef QCBOR_CONFIG_DISABLE_ENCODE_IEEE754
+#ifndef QCBOR_DISABLE_PREFERRED_FLOAT
// The caast to uint32_t is safe because the encoded value
// was 32 bits. It was widened to 64 bits to be passed in here.
pDecodedItem->val.dfnum = IEEE754_FloatToDouble((uint32_t)uNumber);
diff --git a/src/qcbor_encode.c b/src/qcbor_encode.c
index 95cb9fa..c3f2dca 100644
--- a/src/qcbor_encode.c
+++ b/src/qcbor_encode.c
@@ -575,19 +575,29 @@
}
+void QCBOREncode_AddDoubleNoPreferred(QCBOREncodeContext *me, double dNum)
+{
+ QCBOREncode_AddType7(me, sizeof(uint64_t), UsefulBufUtil_CopyDoubleToUint64(dNum));
+}
+
/*
Public functions for adding a double. See qcbor/qcbor_encode.h
*/
void QCBOREncode_AddDouble(QCBOREncodeContext *me, double dNum)
{
-#ifndef QCBOR_CONFIG_DISABLE_ENCODE_IEEE754
+#ifndef QCBOR_DISABLE_PREFERRED_FLOAT
const IEEE754_union uNum = IEEE754_DoubleToSmallest(dNum);
QCBOREncode_AddType7(me, uNum.uSize, uNum.uValue);
#else
- QCBOREncode_AddType7(me, sizeof(uint64_t), UsefulBufUtil_CopyDoubleToUint64(dNum));
+ QCBOREncode_AddDoubleNoPreferred(me, dNum);
#endif
+}
+
+void QCBOREncode_AddFloatNoPreferred(QCBOREncodeContext *me, float fNum)
+{
+ QCBOREncode_AddType7(me, sizeof(uint32_t), UsefulBufUtil_CopyFloatToUint32(fNum));
}
@@ -596,12 +606,12 @@
*/
void QCBOREncode_AddFloat(QCBOREncodeContext *me, float fNum)
{
-#ifndef QCBOR_CONFIG_DISABLE_ENCODE_IEEE754
+#ifndef QCBOR_DISABLE_PREFERRED_FLOAT
const IEEE754_union uNum = IEEE754_FloatToSmallest(fNum);
QCBOREncode_AddType7(me, uNum.uSize, uNum.uValue);
#else
- QCBOREncode_AddType7(me, sizeof(uint32_t), UsefulBufUtil_CopyFloatToUint32(fNum));
+ QCBOREncode_AddFloatNoPreferred(me, fNum);
#endif
}