### Basically a shortened version of  the PR#16885 -- complex part b)
### of  R/tests/reg-tests-1c.R

## b) complex 'x' with different kinds of NaN
x0 <- c(0,1, NA, NaN); z <- outer(x0,x0, complex, length.out=1); rm(x0)
##           --- = NA_real_  but that does not exist e.g., in R 2.3.1
##                   similarly,  '1L', '2L', .. do not exist e.g., in R 2.3.1
(z <- z[is.na(z)])
outerID <- function(x,y, ...) { ## ugly; can we get outer() to work ?
    r <- matrix( , length(x), length(y))
    for(i in seq(along=x))
        for(j in seq(along=y))
            r[i,j] <- identical(z[i], z[j], ...)
    r
}
## Very strictly - in the sense of identical() -- these 12 complex numbers all differ:
## a version that works in older versions of R, where identical() had fewer arguments!
outerID.picky <- function(x,y) {
    nF <- length(formals(identical)) - 2
    do.call("outerID", c(list(x, y), as.list(rep(FALSE, nF))))
}
oldR <- !exists("getRversion") || getRversion() < "3.0.0" ## << FIXME: 3.0.0 is  a wild guess
symnum(id.z <- outerID.picky(z,z)) ## == Diagonal matrix [newer versions of R]
try(# for older R versions
stopifnot(identical(id.z, outerID(z,z)), oldR || identical(id.z, diag(12) == 1))
)
(mz <- match(z, z)) # currently different {NA,NaN} patterns differ - not in print()/format() _FIXME_
zRI <- rbind(Re=Re(z), Im=Im(z)) # and see the pattern :
print(cbind(format = format(z), t(zRI), mz), quote=FALSE)

## compute  match(z[i], z) , for  i = 1,2,..,12  :
(m1z <- sapply(z, match, table = z))
## 1 2 1 2 2 2 1 2 2 2 1 2   # R 1.2.3  (2001-04-26)
## 1 2 3 4 1 3 7 8 2 4 8 7   # R 1.4.1  (2002-01-30)
## 1 2 3 4 1 3 7 8 2 4 8 12  # R 1.5.1  (2002-06-17)
## 1 2 3 4 1 3 7 8 2 4 8 12  # R 1.8.1  (2003-11-21)
## 1 2 3 4 1 3 7 8 2 4 8 12  # R 2.0.1  (2004-11-15)
## 1 2 3 4 1 3 7 4 2 4 4 12  # R 2.1.1  (2005-06-20)
## 1 2 3 4 1 3 7 4 2 4 4 12  # R 2.3.1  (2006-06-01)
## 1 2 3 4 1 3 7 8 2 4 8 12  # R 2.5.1  (2007-06-27)
## 1 2 3 4 1 3 7 4 2 4 4 12  # R 2.10.1 (2009-12-14)
## 1 2 3 4 1 3 7 4 2 4 4 12  # R 3.1.1  (2014-07-10)
## 1 2 3 4 1 3 7 4 2 4 4 12  # R 3.2.5 -- and 3.3.0 patched
## 1 2 1 2 1 1 1 1 2 2 1 2   # <<-- Martin's R-devel and proposed future R

if(!exists("anyNA", mode="function")) anyNA <- function(x) any(is.na(x))
stopifnot(apply(zRI, 2, anyNA)) # *all* are  NA *or* NaN (or both)
is.NA <- function(.) is.na(.) & !is.nan(.)
(iNaN <- apply(zRI, 2, function(.) any(is.nan(.))))
(iNA <-  apply(zRI, 2, function(.) any(is.NA (.)))) # has non-NaN NA's
## In Martin's version of R-devel :
stopifnot(identical(m1z == 1, iNA),
          identical(m1z == 2, !iNA))
## m1z uses match(x, *) with length(x) == 1 and failed in R 3.3.0
stopifnot(identical(m1z, mz))
