Why does min(200, 300) returns 300 for integer64 class

I'm pretty sure that this is a bug. Please report it to the package maintainer.

If I slightly change the definition of min.integer64, it works correctly:

assignInNamespace("min.integer64",
function (..., na.rm = FALSE) 
{
  l <- list(...)
  ret <- double(1)
  noval <- TRUE
  if (length(l) == 1) {
    if (length(l[[1]])) 
      noval <- FALSE
    .Call(bit64:::C_min_integer64, l[[1]], na.rm, ret)
    oldClass(ret) <- "integer64"
  }
  else {
    ret <- sapply(l, function(e) {
      if (length(e)) 
        noval <<- FALSE
      if (is.integer64(e)) {
        ret <- double(1) #this was missing
        .Call(bit64:::C_min_integer64, e, na.rm, ret)
        ret
      }
      else {
        as.integer64(min(e, na.rm = na.rm))
      }
    })
    oldClass(ret) <- "integer64"
    ret <- min(ret, na.rm = na.rm)
  }
  if (noval) 
    warning("no non-NA value, returning +9223372036854775807")
  ret
}, pos = "package:bit64")

min(x, y)
#integer64
#[1] 200
min(y, x)
#integer64
#[1] 200

Tags:

R

Bit64