MATLAB: Does an operation on a NaN of type double convert it to a different bit representation with the Softing CAN-AC2 in xPC Target 3.4 (R2008a)

can-ac2decodingnanSimulink Real-Timesofting

I am working with the Softing CAN-AC2 in xPC Target 3.4 (R2008a).
For the decoding I am using an embedded MATLAB function for the decoding. In this function I use a typecast to split the 64-bit double into two uint32s.
Most of the time the decoding runs without any issues. However, sometimes the CAN data is formatted such that it actually represents a NaN if interpreted as a double.
Specifically a sNaN (first 12-bits are 1’s, and a one of the remaining bits is also 1). When this sNaN double is typecast to two uint32s, the sNaN is silently converted to a qNaN, which changes 1 bit of the data, thus corrupting it.
And my decoding does not work anymore.

Best Answer

This enhancement has been incorporated in xPC Target 4.2 (R2009b). For previous product releases, read below for any possible workarounds:
Any sort of operation on a double that is a NaN (assignment, cast, arithmetic, etc.) can convert the NaN to a different bit representation that is also a NaN.
To work around this issue you would need to use the CAN bit-packing/unpacking blocks which use memcopy to avoid this issue.