"For all binary operations in which one operand is an array of integer data type (except 64-bit integers) and the other is a scalar double, MATLAB computes the operation using elementwise double-precision arithmetic, and then converts the result back to the original integer data type."
Since that sentence talks about the arithmetic operations AND conversion into an integer data type, let's talk about conversion. When dealing with values that are too large or too small to fit in an int8, INT8 will saturate a value that's too large at intmax('int8') and one that's too small at intmin('int8'). But NaN is neither too large nor too small; instead, it's a square peg that can't fit in the round hole that is INT8. [All the possible bit patterns are used for numbers between intmin and intmax, none were reserved for integer NaN.]
So what is int8(NaN)? Unfortunately, it appears there's one conversion operation that's not defined on that documentation page, and that is int8(NaN). [I vaguely remember asking the documentation staff to add that; I'll have to check what happened to that request.] As you can check, int8(NaN) is int8(0).
int8(4) + NaN
= int8(4+NaN)
= int8(NaN)
= int8(0)
and
NaN + int8(4)
= int8(NaN+4)
= int8(NaN)
= int8(0)
Best Answer