Floating point tests and fixes related to #ifdefs
diff --git a/inc/qcbor/qcbor_common.h b/inc/qcbor/qcbor_common.h
index fa927c7..137906a 100644
--- a/inc/qcbor/qcbor_common.h
+++ b/inc/qcbor/qcbor_common.h
@@ -372,10 +372,14 @@
/** Decoding of floating-point epoch dates is unsupported and a
floating-point date was encountered by the decoder. */
- QCBOR_ERR_FLOAT_DATE_UNSUPPORTED = 34,
+ QCBOR_ERR_FLOAT_DATE_DISABLED = 34,
/** Support for half-precision float decoding is disabled. */
- QCBOR_ERR_HALF_PRECISION_UNSUPPORTED = 35
+ QCBOR_ERR_HALF_PRECISION_DISABLED = 35,
+
+ /** Use of floating-point HW is disabled. This affects all type conversions
+ to and from double and float types. */
+ QCBOR_ERR_HW_FLOAT_DISABLED = 36,
/* This is stored in uint8_t; never add values > 255 */
} QCBORError;
diff --git a/inc/qcbor/qcbor_encode.h b/inc/qcbor/qcbor_encode.h
index c3cc53a..adda824 100644
--- a/inc/qcbor/qcbor_encode.h
+++ b/inc/qcbor/qcbor_encode.h
@@ -268,7 +268,7 @@
doubles and floats, especially if the zero, NaN and infinity are
frequently used.
- To avoid use of preferred serialization when encoding, use
+ To avoid use of preferred serialization in the standard configuration when encoding, use
QCBOREncode_AddDoubleNoPreferred() or
QCBOREncode_AddFloatNoPreferred().
@@ -298,14 +298,16 @@
QCBOR_DISABLE_FLOAT_HW_USE reduces object code size on CPUs with
floating-point hardware by a tiny amount.
- If QCBOR_DISABLE_FLOAT_HW_USE is defined and
- QCBOR_DISABLE_PREFERRED_FLOAT is not defined, then the only
- functionality lost is the decoding of floating-point dates. An error
- will be returned if they are encountered.
+ When QCBOR_DISABLE_FLOAT_HW_USE is defined, trying to
+ decoding floating point dates will give error @ref QCBOR_ERR_FLOAT_DATE_DISABLED and decoded
+ single-precision
+ numbers will be returned as @ref QCBOR_TYPE_FLOAT instead of converting them to
+ double as usual.
+
If both QCBOR_DISABLE_FLOAT_HW_USE and QCBOR_DISABLE_PREFERRED_FLOAT
are defined, then the only thing QCBOR can do is encode/decode a
- float as 32-bits and a double as 64-bits. Floating-point epoch dates
+ C float type as 32-bits and a C double type as 64-bits. Floating-point epoch dates
will be unsupported.
Summary Limits of this implementation:
diff --git a/inc/qcbor/qcbor_spiffy_decode.h b/inc/qcbor/qcbor_spiffy_decode.h
index a89cc81..9af3a59 100644
--- a/inc/qcbor/qcbor_spiffy_decode.h
+++ b/inc/qcbor/qcbor_spiffy_decode.h
@@ -254,8 +254,13 @@
When converting floating-point values, the integer is rounded to the
nearest integer using llround(). By default, floating-point suport is
- enabled for QCBOR. If it is turned off, then floating-point
- conversion is not available and TODO: error will be set.
+ enabled for QCBOR.
+
+ If floating-point HW use is disabled this will set
+ @ref QCBOR_ERR_HW_FLOAT_DISABLED if a single-precision
+ number is encountered. If half-precision support is disabled,
+ this will set QCBOR_ERR_HALF_PRECISION_DISABLED if
+ a half-precision number is encountered.
See also QCBORDecode_GetInt64ConvertAll() which will perform the same
conversions as this and a lot more at the cost of adding more object
@@ -359,6 +364,12 @@
unsigned integer and thus sets @ref QCBOR_ERR_NUMBER_SIGN_CONVERSION
is set if the value to be decoded is negatve.
+ If floating-point HW use is disabled this will set
+ @ref QCBOR_ERR_HW_FLOAT_DISABLED if a single-precision
+ number is encountered. If half-precision support is disabled,
+ this will set QCBOR_ERR_HALF_PRECISION_DISABLED if
+ a half-precision number is encountered.
+
See also QCBORDecode_GetUInt64Convert() and
QCBORDecode_GetUInt64ConvertAll().
*/
@@ -416,6 +427,12 @@
single-precision or double-precision floating-point value. If not
@ref QCBOR_ERR_UNEXPECTED_TYPE is set.
+ If floating-point HW use is disabled this will set
+ @ref QCBOR_ERR_HW_FLOAT_DISABLED if a single-precision
+ number is encountered. If half-precision support is disabled,
+ this will set QCBOR_ERR_HALF_PRECISION_DISABLED if
+ a half-precision number is encountered.
+
See @ref Decode-Errors for discussion on how error handling works.
See also QCBORDecode_GetDoubleConvert() and
@@ -441,7 +458,7 @@
@param[out] pdValue The returned floating-point value.
This will decode CBOR integer and floating-point numbers, returning
- them as a floating-point number. This function supports @ref
+ them as a double floating-point number. This function supports @ref
QCBOR_CONVERT_TYPE_XINT64 and @ref QCBOR_CONVERT_TYPE_FLOAT
conversions. If the CBOR is not one of the requested types or a type
not supported by this function, @ref QCBOR_ERR_UNEXPECTED_TYPE is
@@ -449,6 +466,12 @@
See @ref Decode-Errors for discussion on how error handling works.
+ If floating-point HW use is disabled this will set
+ @ref QCBOR_ERR_HW_FLOAT_DISABLED if a single-precision
+ number is encountered. If half-precision support is disabled,
+ this will set QCBOR_ERR_HALF_PRECISION_DISABLED if
+ a half-precision number is encountered.
+
Positive and negative integers can always be converted to
floating-point, so this will never error on type 0 or 1 CBOR.