Precision-preserving number decode and conversion (#211)
This is part of dCBOR support. It decodes a number (int or float) into the best C representation. It's good for more than just dCBOR.
* Remove more stuff related to QCBOREncode_AddBytesLenOnly
* Commit beginnings so dev can be merged in
* Precision-preserving number decode
* Fix ifdefs for precise number decoding
* blank lines
* blank lines
* 65-bit negs without float HW
---------
Co-authored-by: Laurence Lundblade <lgl@securitytheory.com>
diff --git a/src/ieee754.h b/src/ieee754.h
index 53ab3eb..c893e6f 100644
--- a/src/ieee754.h
+++ b/src/ieee754.h
@@ -184,6 +184,25 @@
struct IEEE754_ToInt
IEEE754_SingleToInt(float f);
+
+/**
+ * @brief Convert an unsigned integer to a double with no precision loss.
+ *
+ * @param[in] uInt The value to convert.
+ * @param[in] uIsNegative 0 if postive, 1 if negative.
+ *
+ * @returns Either the converted number or 0.5 if no conversion.
+ *
+ * The conversion will fail if the input can not be represented in the
+ * 52 bits or precision that a double has. 0.5 is returned to indicate
+ * no conversion. It is out-of-band from non-error results, because
+ * all non-error results are whole integers.
+ */
+#define IEEE754_UINT_TO_DOUBLE_OOB 0.5
+double
+IEEE754_UintToDouble(uint64_t uInt, int uIsNegative);
+
+
#endif /* ! QCBOR_DISABLE_PREFERRED_FLOAT */