Commutative property of arithmetic operations with NA and NaN

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Commutative property of arithmetic operations with NA and NaN

Erik Leunissen
Are the rules of commutativity for binary arithmetic operators also valid (or make sense) for the
exceptional values NaN and NA?

I'm observing the following results with multiplication, division, addition and subtraction (didn't
bother to try other operations):

octave:1> NaN*NA
ans = NA
octave:2> NA*NaN
ans = NaN

octave:3> NaN/NA
ans = NaN
octave:4> NA/NaN
ans = NA

octave:5> NaN + NA
ans = NA
octave:6> NA + NaN
ans = NaN

octave:7> NaN - NA
ans = NaN
octave:8> NA - NaN
ans = NA

Please note that the above results originate from "playing with exceptional values"; I have no
use-case. Moreover, I'm unfamiliar with theory regarding NaN and NA.

Nevertheless, I dare say that the different results for multiplication (octave commands 1 and 2
above) and the different results for addition (octave commands 5 and 6) don't make any sense to me.

As for the results for division and subtraction, my "judgement" about validity of these results is
less pronounced. But considering only that NaN and NA have a profoundly different meaning (to me
they seem to exist on entirely different dimensions/scales), I can imagine that swapping the
operands ought not make a difference for the result.

I'd be very interested in a more knowledgeable judgement.

TIA,
Erik Leunissen.
--


Reply | Threaded
Open this post in threaded view
|

Re: Commutative property of arithmetic operations with NA and NaN

nrjank
Administrator
Moreover, I'm unfamiliar with theory regarding NaN and NA.

I don't think there is really a theory with regards to NA.  NAN is part of the IEEE 754 floating point standard, and has set rules that Octave tries to follow (in addition. To trying to follow MATLAB compatibility).  NA on the other hand, is to my knowledge primarily used as a particular error value in MS Excel, and I don't believe it's defined in any numerical standard. I don't believe Matlab handles NA as a data type either.

So, unless it's been defined elsewhere, I think the properties you're examining may be unique to octave. Will probably need someone involved in early implementation to comment on the "why"


Reply | Threaded
Open this post in threaded view
|

Re: Commutative property of arithmetic operations with NA and NaN

Francesco Potortì
In reply to this post by Erik Leunissen
>octave:1> NaN*NA
>ans = NA
>octave:2> NA*NaN
>ans = NaN
...
>octave:5> NaN + NA
>ans = NA
>octave:6> NA + NaN
>ans = NaN

Waiting for more knowledgeable opinions, here is what I remember) caveat
emptor).

NaN is defined by IEEE standards.  It has not a single binary
representations, so two NaN values may legally have different underlying
binary representations.

NA is a particular NaN representation which is used in the R language,
from which Octave copies the semantic meaning.  It is commonly used in
data series to indicate a missing values (Not Available).

Examples of usage are the NaN and TSA packages, which however do not
require NA to be used, but are happy with NaN:
http://pub.ist.ac.at/~schloegl/matlab/NaN/

--
Francesco Potortì (ricercatore)        Voice:  +39.050.621.3058
ISTI - Area della ricerca CNR          Mobile: +39.348.8283.107
via G. Moruzzi 1, I-56124 Pisa         Skype:  wnlabisti
(gate 20, 1st floor, room C71)         Web:    http://fly.isti.cnr.it