1Type 7 – Floats & control tokens 2================================= 3 4This type combines two completely unrelated types of items -- floating point numbers and special values such as true, false, null, etc. We refer to these special values as 'control values' or 'ctrls' for short throughout the code. 5 6Just like integers, they have different possible width (resulting in different value ranges and precisions). 7 8.. doxygenenum:: cbor_float_width 9 10================================== ========================================= 11Corresponding :type:`cbor_type` ``CBOR_TYPE_FLOAT_CTRL`` 12Number of allocations One per lifetime 13Storage requirements ``sizeof(cbor_item_t) + 1/4/8`` 14================================== ========================================= 15 16Getting metadata 17~~~~~~~~~~~~~~~~~ 18 19.. doxygenfunction:: cbor_float_ctrl_is_ctrl 20.. doxygenfunction:: cbor_float_get_width 21 22Reading data 23~~~~~~~~~~~~~ 24 25.. doxygenfunction:: cbor_float_get_float2 26.. doxygenfunction:: cbor_float_get_float4 27.. doxygenfunction:: cbor_float_get_float8 28.. doxygenfunction:: cbor_float_get_float 29.. doxygenfunction:: cbor_ctrl_value 30.. doxygenfunction:: cbor_get_bool 31 32Creating new items 33~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 34 35.. doxygenfunction:: cbor_new_ctrl 36.. doxygenfunction:: cbor_new_float2 37.. doxygenfunction:: cbor_new_float4 38.. doxygenfunction:: cbor_new_float8 39.. doxygenfunction:: cbor_new_null 40.. doxygenfunction:: cbor_new_undef 41 42 43Building items 44~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 45 46.. doxygenfunction:: cbor_build_bool 47.. doxygenfunction:: cbor_build_ctrl 48.. doxygenfunction:: cbor_build_float2 49.. doxygenfunction:: cbor_build_float4 50.. doxygenfunction:: cbor_build_float8 51 52 53Manipulating existing items 54~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 55 56.. doxygenfunction:: cbor_set_ctrl 57.. doxygenfunction:: cbor_set_bool 58.. doxygenfunction:: cbor_set_float2 59.. doxygenfunction:: cbor_set_float4 60.. doxygenfunction:: cbor_set_float8 61 62 63.. _api_type_7_hard_floats: 64 65Half floats 66~~~~~~~~~~~~ 67CBOR supports two `bytes wide ("half-precision") <https://en.wikipedia.org/wiki/Half-precision_floating-point_format>`_ 68floats which are not supported by the C language. *libcbor* represents them using `float <https://en.cppreference.com/w/c/language/type>` values throughout the API. Encoding will be performed by :func:`cbor_encode_half`, which will handle any values that cannot be represented as a half-float. 69