[C++ SDK] FieldBase::SetFLOAT64Value has unspecified behaviour

In fit_field_base.cppthe FieldBase::SetFLOAT64Value method uses C-style casts to convert a FIT_FLOAT64 (i.e. double) value to an unsigned integer. For fields with a signed type, the conversion is not standard, especially if the roundedValue is negative.

For instance, the type of the "grade" field is FIT_BASE_TYPE_SINT16. According to the following snippet, roundedValue (double) is being converted to a  FIT_UINT16 (i.e. uint16_t):

case FIT_BASE_TYPE_SINT16:
case FIT_BASE_TYPE_UINT16:
case FIT_BASE_TYPE_UINT16Z:
    SetUINT16Value((FIT_UINT16) roundedValue, fieldArrayIndex);
    break;

This works well when roundedValue is positive. However, the result of the conversion is implementation-dependent when roundedValue is negative. On some platforms, casting a negative double to an unsigned integer amounts to 0. A possible solution for this could be using the SetSINT16Value method for fields with a signed type:

case FIT_BASE_TYPE_SINT16:
    SetSINT16Value((FIT_SINT16) roundedValue, fieldArrayIndex);
    break;
case FIT_BASE_TYPE_UINT16:
case FIT_BASE_TYPE_UINT16Z:
    SetUINT16Value((FIT_UINT16) roundedValue, fieldArrayIndex);
    break;
 
(and similar modifications for the 8, 32 and 64 bit types as well).
With this modified approach, for signed fields, a negative double will be first cast to a signed integer (which would preserve its negative value), and then implicitly converted to an unsigned integer.