is.na(as.logical(0/0)) is.na(as.integer(0/0)) is.nan(max(c(0/0, -1, 1))) is.nan(max(c(-1, 1, 0/0))) is.nan(min(c(0/0, -1, 1))) is.nan(min(c(-1, 1, 0/0))) { # as.logical(1/0) used to produce Error # bug 216, sbug 8/7/91 david as.logical(1/0) } { # comparions with NaN's used to fall thru to the hardware; we want # to trap them and process according to S rules; # comparison operations with NaN's should produce NA's. # bug 130 (erroneously 125), sbug 7/19/91 david. T } is.na((0/0) == (0/0)) && ! is.nan((0/0) == (0/0)) is.na((0/0) != (0/0)) && ! is.nan((0/0) != (0/0)) is.na((0/0) > (0/0)) && ! is.nan((0/0) > (0/0)) is.na((0/0) < (0/0)) && ! is.nan((0/0) < (0/0)) { # as.logical and as.integer used to fail with 0/0 # sbug 7/16/90 david is.na(as.logical(0/0)) && is.na(as.integer(0/0)) } { # min, max, range used to be screwy with NaN's # sbug 7/13/90 pat, 7/16/90 david x <- c(0/0, -1, 0, 1) y <- c(-1, 0, 1, 0/0) T } is.nan(max(x)) is.nan(max(y)) is.nan(min(x)) is.nan(min(y)) all(is.nan(range(x))) all(is.nan(range(y))) all(is.nan(range(c(0, 1, -1, 0/0)))) { # check that several functions (contour, persp, pretty, image. # stem, boxplot) accept NaN's and Inf's, in the sense that they are # either removed in Q-code, or the underlying stuff does something # sensible with them. # # Q-code fixes: contour, 7/12/91 bill # persp, 7/12/91 bill # pretty, 7/12/91 bill # # $P/narang.r now chucks Inf's along with NA's and NaN's, also changes # to $I/u/mach.mpp, $P/inftst.C (new), $DEV/gr_extern/test_inf.c: # 7/12/91 bill, 9/5/91 peter (twice), 9/8/91 peter (twice). # # Patch to $QPE/interface.c to convert Inf's to NA's before old S code # is called (this is for single precision, ATT already did it for # double): 7/28/91 bill # # misc: 9/4/91 peter, 9/5/91 scott, bill, # # See also ~stest/graphics/tests/Sbug1 for related tests. #cat("\nSHOULD get warning 'NAs generated in: log(x)' vvv.\n") options(warn=-1) m.double <- matrix(log((-1):7), 3, 3) options(warn=1) #cat("SHOULD get warning 'NAs generated in: log(x)' ^^^.\n\n") m.single <- m.double storage.mode(m.single) <- "single" # The following statements used to produce Errors with lots of messages: # They should be completely silent now, not even warnings. dummy.device.on() contour(1:3, 1:3, m.double) contour(1:3, 1:3, m.single) persp(1:3, 1:3, m.double) persp(1:3, 1:3, m.single) dummy.device.off() # Expect no messages: pretty(c(Inf,1)) pretty(as.single(c(Inf, 1))) T } { # (a+bi)/0 used to have an incorrect real part. # sbug 9/15/91 david Re(1i/0) == 0 } { # all.equal used to fail with complexes # bug 386, sbug 9/16/91 david all.equal(c(1i,2,Inf), c(1i,2,Inf)) } { # all.equal again, same mail message all.equal(c(1i,2,NA), c(1i,2,3)) == "1 missing value mismatches" } { # test that the code in comp_util.c underlying Re, Im and Conj works # for NaN's. (C code: cx_re, cx_im, cx_conj). # sbug 9/12/91 david "is.na.pattern.na"<- function(x) is.na(x) & !is.nan(x) "f"<- function(z) c(Re(z), Im(z), Conj(z)) # Tests upcoming: T } all(is.na.pattern.na(f(complex(re=0, im=NA)))) all(is.na.pattern.na(f(complex(re=NA, im=0)))) all(is.nan(f(complex(re=0, im=0/0)))) all(is.nan(f(complex(re=0/0, im=0)))) all(is.na.pattern.na(f(complex(re=NA, im=NA)))) all(is.nan(f(complex(re=0/0, im=0/0)))) { "end cx_re, cx_im, cx_conj tests" ; T } { # fixes to comp_util:Cmult by david # sbug 9/11/91 (twice, but ignore patch), 9/12/91 for patch - david if (platform() == "SUNOS5_SPARC") TRUE else {1i*Inf == Inf*1i && is.infinite(Inf*1i)} } { # various tests associated with complex math in comp_util. # Written on hardcopy of sbug 9/3/91, checked with david. # here come the tests T } { A <- (1+1i)*Inf ; Re(A) == Inf && Im(A) == Inf } if (platform() == "SUNOS5_SPARC") TRUE else { B <- (1+0i)*Inf ; Re(B) == Inf && Im(B) == 0 } { C <- complex(mod=Inf, arg=0) ; Re(C) == Inf && Im(C) == 0 } if (platform() == "SUNOS5_SPARC") TRUE else { D <- complex(mod=Inf, arg=pi/2) ; Re(D) == 0 && Im(D) == Inf } { # Infi didn't used to data.dump/data.restore properly. On # restoration, it was just Inf, not Infi. # bug 387, sbug 9/16/91 david cmpx.infi <<- Infi temp <- tempfile() data.dump("cmpx.infi", temp) rm(cmpx.infi) data.restore(temp) unlink(temp) cmpx.infi == Infi } { # Make sure we ran $C/fix.fpcr on Sqpe for HP300. This ensures that # the floating point control register will get run-time initialized # in such a way that the machine will follow IEEE rules, not generate # FPE's for exceptional math. if (platform() != "HP300") TRUE else { cat("Should NOT get any warnings with this exceptional math. vvv\n") ans <- is.infinite(1/0) && is.nan(0/0) cat("Should NOT get any warnings with this exceptional math. ^^^\n") ans } } { # 1i/0 should be 0 + Infi; it was NaN + 0i [sic] on HP-300. # This was due to the floating point control register on betty being # initialized to send SIGFPE on divide-by-zeros, instead of behaving # in IEEE fashion. Fixed by David's $C/fix.fpcr. # bug 580, 11/7/91 peter a <- 1i/0 Re(a) == 0 && Im(a) == Inf } if (platform() == "SUNOS5_SPARC") TRUE else { # Inf * 1i should be complex Inf; it was NaN (NA?) on HP-300. Same # cause as that behind 1i/0 being NaN: floating point control # register initialized to undesirable value. # bug 579, sbug 11/6/91 (twice) peter a <- Inf * 1i Re(a) == 0 && Im(a) == Inf } if (platform() == "SUNOS5_SPARC") TRUE else { # manifestations of bug 579 (Inf * 1i being NaN): # bug 579, sbug 11/6/91 (twice) peter a <- complex(re=0, im=Inf) ans <- Re(a) == 0 && Im(a) == Inf a2 <- complex(mod=Inf, arg=pi/2) ans <- ans && (Re(a2) == 0 && Im(a2) == Inf) ans } { # special values with mean, median. Bug 206. # -peter T } is.na(mean(c(1,2,3,NA), na.rm=F)) is.na(median(c(1,2,3,NA), na.rm=F)) is.infinite(m <- mean(c(1, Inf))) && sign(m) == 1 is.infinite(m <- mean(c(1, -Inf))) && sign(m) == -1 is.na(mean(c(-Inf, 0, Inf))) is.infinite(m <- median(c(1,Inf))) && sign(m) == 1 is.infinite(m <- median(c(-Inf, 1))) && sign(m) == -1 median(c(-Inf, 1, 2)) == 1 median(c(1, 2, Inf)) == 2 median(c(-Inf, 0, Inf)) == 0