Why 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)?

1 view (last 30 days)
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.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 21 Jan 2010
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.

More Answers (0)

Products


Release

R2008a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!