more thorough removal of float
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index 1b6ff3e..532da1e 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -608,12 +608,24 @@
// caught before this is called.
case HALF_PREC_FLOAT:
+#ifndef QCBOR_CONFIG_DISABLE_ENCODE_IEEE754
+ // 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);
pDecodedItem->uDataType = QCBOR_TYPE_DOUBLE;
+#else
+ nReturn = QCBOR_ERR_UNSUPPORTED;
+#endif
break;
case SINGLE_PREC_FLOAT:
- pDecodedItem->val.dfnum = (double)UsefulBufUtil_CopyUint32ToFloat((uint32_t)uNumber);
- pDecodedItem->uDataType = QCBOR_TYPE_DOUBLE;
+#ifndef QCBOR_CONFIG_DISABLE_ENCODE_IEEE754
+ // The caast to uint32_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_FloatToDouble((uint32_t)uNumber);
+#else
+ pDecodedItem->val.fnum = UsefulBufUtil_CopyUint32ToFloat((uint32_t)uNumber);
+ pDecodedItem->uDataType = QCBOR_TYPE_FLOAT;
+#endif
break;
case DOUBLE_PREC_FLOAT:
pDecodedItem->val.dfnum = UsefulBufUtil_CopyUint64ToDouble(uNumber);
@@ -1221,7 +1233,10 @@
pDecodedItem->val.epochDate.nSeconds = (int64_t)pDecodedItem->val.uint64;
break;
+ // TODO: test this with float and half input
case QCBOR_TYPE_DOUBLE:
+ case QCBOR_TYPE_FLOAT:
+#ifndef QCBOR_DISABLE_FLOAT_HW_USE
{
// This comparison needs to be done as a float before
// conversion to an int64_t to be able to detect doubles
@@ -1231,7 +1246,7 @@
// is bad and wrong for the comparison because it will
// allow conversion of doubles that can't fit into a
// uint64_t. To remedy this INT64_MAX - 0x7ff is used as
- // the cutoff point as if that rounds up in conversion to
+ // the cutoff point because if that value rounds up in conversion to
// double it will still be less than INT64_MAX. 0x7ff is
// picked because it has 11 bits set.
//
@@ -1242,7 +1257,8 @@
//
// Without the 0x7ff there is a ~30 minute range of time
// values 10 billion years in the past and in the future
- // where this this code would go wrong.
+ // where this this code would go wrong and some compilers
+ // will generate warnings or errors.
const double d = pDecodedItem->val.dfnum;
if(d > (double)(INT64_MAX - 0x7ff)) {
nReturn = QCBOR_ERR_DATE_OVERFLOW;
@@ -1251,8 +1267,18 @@
pDecodedItem->val.epochDate.nSeconds = (int64_t)d;
pDecodedItem->val.epochDate.fSecondsFraction = d - (double)pDecodedItem->val.epochDate.nSeconds;
}
+#else
+ /* Disabling float support causes a floating point
+ data to error in the default below. The above code
+ requires floating point conversion to integers and
+ comparison which requires either floating point HW
+ or a SW library. */
+
+ nReturn = QCBOR_ERR_FLOAT_DATE_UNSUPPORTED;
+#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
break;
+
default:
nReturn = QCBOR_ERR_BAD_OPT_TAG;
goto Done;