int64/ 0000755 0001751 0000144 00000000000 11666175544 011253 5 ustar hornik users int64/MD5 0000644 0001751 0000144 00000004667 11666175544 011600 0 ustar hornik users 202f81114893214fe076a3dc7f2936d9 *ChangeLog
ad8039cfff19dd6a5b3d80e956dd7d1f *DESCRIPTION
ec0dab9f4dbc31f23248e064de4b4750 *NAMESPACE
e2b20ee2374adef9b8d2e35b21088ec8 *R/int64.R
bfaea06c518cea5a14b494255d1f4c12 *inst/NEWS
a5ef93bd26d2947da854a7d685eea6d4 *inst/doc/int64.Rnw
39ff51af8d440147bc862eaf522b2a0b *inst/doc/int64.pdf
329359223514fcae4f78306c8410fccb *inst/include/int64.h
1e6c68713a8915b4eaef8eff5f2981fe *inst/include/int64/LongVector.h
179205e75eb83a1c92e05673990ff35f *inst/include/int64/arith.h
2b38d34e10b215a0dc6f8236a0767286 *inst/include/int64/as_character.h
a296c9b8e57d75da41da1e88acacd849 *inst/include/int64/as_long.h
69a530398ec783efc30555b1451c7315 *inst/include/int64/compare.h
65225bac04d189edeb06064afa77bc5d *inst/include/int64/format_binary.h
ba7328bdd3f75c73d2a2c9fbf2cdfc76 *inst/include/int64/get_bits.h
d14b131f7d16cbe80d87756004756902 *inst/include/int64/get_class.h
096a0377b98cda9c78dc13ac6718d8b3 *inst/include/int64/get_long.h
4f0a3fb16cf49da953b92c433fa16e51 *inst/include/int64/int2.h
6e38efe0fb656615f1f4b86f99bace11 *inst/include/int64/int64.h
0a9536ae7b5237fa2c34c3c8d83fb42d *inst/include/int64/long_traits.h
f5285db4b84d95689c39e9990f4177d4 *inst/include/int64/math.h
66b06e0ae7c6bd3b5a6136ea65a78b32 *inst/include/int64/read_string.h
02d718588767dec109548677beb847f8 *inst/include/int64/read_string_forward.h
c012b69d9547ae54fd1d558cc44df0e3 *inst/include/int64/routines.h
64261b31645e581cb2302e631007928d *inst/include/int64/summary.h
71ba895b59243c94781bd832adffd007 *inst/unitTests/runTests.R
3f0d4d612d365d94246c3bb02e169f32 *inst/unitTests/runit.int64.R
7cf7d760f404594e04026b04550f9279 *man/as.int64.Rd
f28492e65e51d865497034a22a077ea7 *man/as.uint64.Rd
87e8e12369cda981ffcbff1944a18c14 *man/binary-class.Rd
a3c2dbd9fa9db038a6108fc8e443f8d3 *man/binary-methods.Rd
47d9b1e33644a68a821cd4656e122d99 *man/int64-class.Rd
848f1273eda3466d00faf831c06dcd60 *man/int64-package.Rd
83d1a8d85d3d7ba995e1f1fa62d72c8c *man/int64.Rd
13945b4cac0dcec9412935bee3b62c3f *man/numeric_limits.Rd
7a998dfe4fe6abf54bbe63a6e883b029 *man/sort-methods.Rd
14957d1c5b9d047beddde3cc88b9749d *man/uint64-class.Rd
0830f711d93f0651c0ed417c5deabd0d *man/uint64.Rd
bbe2cc89e11938a692bd3110e4324449 *man/unique-methods.Rd
e87abaa47a2160ce692e7d5306dd2aa7 *src/Makevars
e87abaa47a2160ce692e7d5306dd2aa7 *src/Makevars.win
911fb44ffecb91fe582101dcc35b2d00 *src/int64.cpp
2a6617e4ef79ab3a96bd9d53ec077a69 *src/int64_init.c
4fd5a0fe161fa48793eeb0cc58d19cab *tests/doRUnit.R
int64/tests/ 0000755 0001751 0000144 00000000000 11665656774 012425 5 ustar hornik users int64/tests/doRUnit.R 0000644 0001751 0000144 00000001004 11660746102 014103 0 ustar hornik users if(require("RUnit", quietly = TRUE)) {
pkg <- "int64"
require( pkg, character.only=TRUE)
path <- system.file("unitTests", package = pkg)
stopifnot(file.exists(path), file.info(path.expand(path))$isdir)
# without this, we get unit test failures
Sys.setenv( R_TESTS = "" )
int64.unit.test.output.dir <- getwd()
source(file.path(path, "runTests.R"), echo = TRUE)
} else {
print( "package RUnit not available, cannot run unit tests" )
}
int64/src/ 0000755 0001751 0000144 00000000000 11665656774 012052 5 ustar hornik users int64/src/Makevars.win 0000644 0001751 0000144 00000000044 11665656774 014340 0 ustar hornik users PKG_CPPFLAGS += -I../inst/include/
int64/src/Makevars 0000644 0001751 0000144 00000000044 11665656774 013544 0 ustar hornik users PKG_CPPFLAGS += -I../inst/include/
int64/src/int64_init.c 0000644 0001751 0000144 00000003421 11665656774 014205 0 ustar hornik users // int64_init.c : 64 bit integers
//
// Copyright (C) 2011 Romain Francois
// Copyright (C) 2011 Google Inc. All rights reserved.
//
// This file is part of int64.
//
// int64 is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// int64 is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with int64. If not, see .
#include
#include
#include
#include
// borrowed from Matrix
#define CALLDEF(name, n) {#name, (DL_FUNC) &name, n}
#define EXTDEF(name) {#name, (DL_FUNC) &name, -1}
static R_CallMethodDef callEntries[] = {
CALLDEF(int64_as_int64,1),
CALLDEF(int64_format_binary,1),
CALLDEF(int64_as_character_int64,2),
CALLDEF(int64_arith_int64_int64,4),
CALLDEF(int64_compare_int64_int64,4),
CALLDEF(int64_summary_int64,3),
CALLDEF(int64_as_uint64,1),
CALLDEF(int64_limits,1),
CALLDEF(int64_sort,3),
CALLDEF(int64_math,3),
CALLDEF(int64_signif,3),
CALLDEF(int64_isna,2),
{NULL, NULL, 0}
};
void R_init_int64( DllInfo* info){
/* Register routines, allocate resources. */
R_registerRoutines(info,
NULL /* .C*/,
callEntries /*.Call*/,
NULL /* .Fortran */,
NULL /*.External*/
);
}
void R_unload_int64(DllInfo *info) {
/* Release resources. */
}
int64/src/int64.cpp 0000644 0001751 0000144 00000014700 11665656774 013524 0 ustar hornik users // int64.cpp: int64 64 bit integers
//
// Copyright (C) 2011 Romain Francois
// Copyright (C) 2011 Google Inc. All rights reserved.
//
// This file is part of int64.
//
// int64 is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// int64 is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with int64. If not, see .
#define BUILDING_INT64
#include
#include
namespace Rint64{
namespace internal{
bool int64_naflag = false ;
SEXP int64_format_binary__standard(SEXP x){
int n = Rf_length(x) ;
SEXP res = PROTECT( Rf_allocVector( STRSXP, n ) ) ;
switch( TYPEOF(x) ){
case INTSXP:
{
int* data = INTEGER(x) ;
for( int i=0; i( data[i] ) ) ) ;
}
break ;
}
case REALSXP:
{
double* p_x = REAL(x) ;
for( int i=0; i( p_x[i] ) ) );
}
break ;
}
default:
Rf_error( "incompatible type" ) ;
}
UNPROTECT(1) ; // res ;
return res ;
}
}
}
extern "C" SEXP int64_format_binary(SEXP x){
if( Rf_inherits( x, "int64" ) ){
return Rint64::internal::int64_format_binary_long(x) ;
} else if( Rf_inherits( x, "uint64" ) ){
return Rint64::internal::int64_format_binary_long(x) ;
} else {
return Rint64::internal::int64_format_binary__standard(x);
}
return R_NilValue ;
}
extern "C" SEXP int64_as_character_int64(SEXP x, SEXP unsign){
bool is_unsigned = INTEGER(unsign)[0] ;
if( is_unsigned ){
return Rint64::internal::int64_as_character( x ) ;
} else {
return Rint64::internal::int64_as_character( x ) ;
}
}
extern "C" SEXP int64_as_int64(SEXP x){
return Rint64::internal::as_long(x) ;
}
extern "C" SEXP int64_as_uint64(SEXP x){
return Rint64::internal::as_long(x) ;
}
extern "C" SEXP int64_arith_int64_int64(SEXP generic, SEXP e1, SEXP e2, SEXP unsign ) {
const char* op = CHAR(STRING_ELT(generic, 0)) ;
bool is_unsigned = INTEGER(unsign)[0] ;
if( is_unsigned ){
return Rint64::internal::int64_arith__impl(op, e1, e2 ) ;
} else {
return Rint64::internal::int64_arith__impl(op, e1, e2 ) ;
}
}
extern "C" SEXP int64_compare_int64_int64(SEXP generic, SEXP e1, SEXP e2, SEXP unsign) {
const char* op = CHAR(STRING_ELT(generic, 0)) ;
bool is_unsigned = INTEGER(unsign)[0];
if( is_unsigned ){
return Rint64::internal::int64_compare(op,e1,e2) ;
} else {
return Rint64::internal::int64_compare(op,e1,e2) ;
}
}
extern "C" SEXP int64_summary_int64(SEXP generic, SEXP x, SEXP unsign){
const char* op = CHAR(STRING_ELT(generic, 0)) ;
bool is_unsigned = INTEGER(unsign)[0] ;
if( is_unsigned ){
return Rint64::internal::int64_summary(op, x ) ;
} else {
return Rint64::internal::int64_summary(op, x ) ;
}
}
extern "C" SEXP int64_limits( SEXP type_ ){
const char* type = CHAR(STRING_ELT(type_, 0) ) ;
if( !strncmp( type, "integer", 7 ) ){
SEXP res = PROTECT( Rf_allocVector(INTSXP, 2 ) ) ;
INTEGER(res)[0] = std::numeric_limits::min() + 1 ;
INTEGER(res)[1] = std::numeric_limits::max() ;
UNPROTECT(1) ;
return res ;
} else if( ! strncmp( type, "int64", 5 ) ){
return Rint64::internal::new_long_2(
Rint64::internal::long_traits::min() ,
Rint64::internal::long_traits::max()
) ;
} else if( !strncmp( type, "uint64", 6 ) ){
return Rint64::internal::new_long_2(
Rint64::internal::long_traits::min(),
Rint64::internal::long_traits::max()
) ;
}
Rf_error( "unsupported type" ) ;
return R_NilValue ;
}
extern "C" SEXP int64_sort( SEXP x, SEXP unsign, SEXP decr ){
bool is_unsigned = INTEGER(unsign)[0] ;
bool decreasing = INTEGER(decr)[0] ;
if( is_unsigned ){
return Rint64::LongVector(x).sort(decreasing ) ;
} else {
return Rint64::LongVector(x).sort(decreasing ) ;
}
}
extern "C" SEXP int64_math( SEXP generic, SEXP x, SEXP unsign){
bool is_unsigned = INTEGER(unsign)[0];
const char* op = CHAR(STRING_ELT(generic, 0 ) );
if( is_unsigned ){
return Rint64::internal::math( op, x ) ;
} else {
return Rint64::internal::math( op, x ) ;
}
}
extern "C" SEXP int64_signif( SEXP s_, SEXP digits_, SEXP len_){
std::string s ;
int n = Rf_length(s_) ;
int* digits = INTEGER(digits_) ;
int* len = INTEGER(len_) ;
SEXP res = PROTECT( Rf_allocVector( STRSXP, n ) ) ;
for( int i=0; i len[i] ){
SET_STRING_ELT( res, i, STRING_ELT( s_, i ) ) ;
} else {
s = CHAR(STRING_ELT(s_, i ));
for( int j=digits[i]; j( x_ ).is_na() ;
} else {
return Rint64::LongVector( x_ ).is_na() ;
}
}
int64/R/ 0000755 0001751 0000144 00000000000 11665656774 011464 5 ustar hornik users int64/R/int64.R 0000644 0001751 0000144 00000023615 11664531377 012550 0 ustar hornik users # Copyright (C) 2011 Romain Francois
# Copyright (C) 2011 Google Inc. All rights reserved.
#
# This file is part of int64.
#
# int64 is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# int64 is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with int64. If not, see .
setClassUnion( "maybeNames", c("character", "NULL" ) )
names_int64 <- function(x){
x@NAMES
}
namesgets_int64 <- function( x, value){
if( missing(value) || is.null(value) ){
x@NAMES <- NULL
} else if( is.character( value )){
if( length( value ) == length( x@.Data ) ){
x@NAMES <- value
} else if(length(value) < length(x@.Data) ) {
x@NAMES <- c( value, rep( NA, length(x@.Data) - length(value) ) )
} else {
stop( "error assigning names" )
}
} else {
stop( "must be character vector or NULL" )
}
x
}
setClass( "int64", contains = "list",
representation( NAMES = "maybeNames")
)
setClass( "uint64", contains = "list" ,
representation( NAMES = "maybeNames")
)
setMethod( "names", "int64", names_int64 )
setMethod( "names<-", "int64", namesgets_int64 )
setMethod( "names", "uint64", names_int64 )
setMethod( "names<-", "uint64", namesgets_int64 )
setClass( "binary",
representation( data = "character", bits = "integer" )
)
setGeneric( "binary", function(object) standardGeneric("binary") )
setMethod( "binary", "integer", function(object){
new( "binary", data = .Call( int64_format_binary, object ), bits = 32L )
} )
setMethod( "binary", "numeric", function(object){
new( "binary", data = .Call( int64_format_binary, object ), bits = 64L )
} )
setMethod( "binary", "int64", function(object){
new( "binary", data = .Call( int64_format_binary, object ), bits = 64L )
} )
setMethod( "binary", "uint64", function(object){
new( "binary", data = .Call( int64_format_binary, object ), bits = 64L )
} )
setMethod( "show", "binary", function(object){
print( noquote( object@data ) )
invisible(object)
})
int64 <- function(length=0L){
x <- new("int64", rep( list(integer(2L)), length ) )
x
}
uint64 <- function(length=0L){
x <- new("uint64", rep( list(integer(2L)), length ) )
x
}
setMethod( "length", "int64", function(x){
length(x@.Data)
} )
setMethod( "length", "uint64", function(x){
length(x@.Data)
} )
show_int64 <- function(object){
if( !length(object)) {
writeLines( sprintf( "%s(0)", class(object) ) )
} else {
if( is.null( object@NAMES ) ){
print( noquote( as.character( object ) ) )
} else {
x <- as.character( object )
names(x) <- object@NAMES
print(noquote(x))
}
}
invisible(object)
}
setMethod( "show", "int64", show_int64)
setMethod( "show", "uint64", show_int64)
as.int64 <- function(x){
if( is.character(x) ){
wrong <- ! grepl("^[-]?[0-9]+$", x)
if( any(wrong) ){
x[wrong] <- "NA"
warning( "NAs introduced" )
}
}
new( "int64", .Call(int64_as_int64, x) )
}
as.uint64 <- function(x){
if( is.character(x) ){
wrong <- ! grepl("^[0-9]+$", x)
if( any(wrong) ){
x[wrong] <- "NA"
warning( "NAs introduced" )
}
}
new( "uint64", .Call(int64_as_uint64, x) )
}
setMethod( "[", "int64", function(x, i, j, ...){
new( "int64", x@.Data[ i ] )
} )
setMethod( "[", "uint64", function(x, i, j, ...){
new( "uint64", x@.Data[ i ] )
} )
setMethod( "[<-", "int64", function(x, i, j, ..., value ){
data <- x@.Data
data[i] <- as.int64( value )@.Data
new( "int64", data )
} )
setMethod( "[<-", "uint64", function(x, i, j, ..., value ){
data <- x@.Data
data[i] <- as.uint64( value )@.Data
new( "uint64", data )
} )
setMethod( "Arith", signature(e1 = "int64", e2 = "int64" ),
function(e1,e2){
numbers <- .Call( int64_arith_int64_int64, .Generic, e1, e2, FALSE )
new( "int64", numbers )
} )
setMethod( "Arith", signature(e1 = "int64", e2 = "ANY" ),
function(e1,e2){
numbers <- .Call( int64_arith_int64_int64, .Generic, e1, as.int64(e2), FALSE )
new( "int64", numbers )
} )
setMethod( "Arith", signature(e1 = "ANY", e2 = "int64" ),
function(e1,e2){
numbers <- .Call( int64_arith_int64_int64, .Generic, as.int64(e1), e2, FALSE )
new( "int64", numbers )
} )
setMethod( "Arith", signature(e1 = "uint64", e2 = "uint64" ),
function(e1,e2){
numbers <- .Call( int64_arith_int64_int64, .Generic, e1, e2, TRUE )
new( "uint64", numbers )
} )
setMethod( "Arith", signature(e1 = "uint64", e2 = "ANY" ),
function(e1,e2){
numbers <- .Call( int64_arith_int64_int64, .Generic, e1, as.uint64(e2), TRUE )
new( "uint64", numbers )
} )
setMethod( "Arith", signature(e1 = "ANY", e2 = "uint64" ),
function(e1,e2){
numbers <- .Call( int64_arith_int64_int64, .Generic, as.uint64(e1), e2, TRUE )
new( "uint64", numbers )
} )
setMethod( "Compare", signature(e1 = "int64", e2 = "int64" ),
function(e1,e2){
.Call( int64_compare_int64_int64, .Generic, e1, e2, FALSE )
} )
setMethod( "Compare", signature(e1 = "ANY", e2 = "int64" ),
function(e1,e2){
.Call( int64_compare_int64_int64, .Generic, as.int64(e1), e2, FALSE )
} )
setMethod( "Compare", signature(e1 = "int64", e2 = "ANY" ),
function(e1,e2){
.Call( int64_compare_int64_int64, .Generic, e1, as.int64(e2), FALSE )
} )
setMethod( "Compare", signature(e1 = "uint64", e2 = "uint64" ),
function(e1,e2){
.Call( int64_compare_int64_int64, .Generic, e1, e2, TRUE )
} )
setMethod( "Compare", signature(e1 = "ANY", e2 = "uint64" ),
function(e1,e2){
.Call( int64_compare_int64_int64, .Generic, as.uint64(e1), e2, TRUE )
} )
setMethod( "Compare", signature(e1 = "uint64", e2 = "ANY" ),
function(e1,e2){
.Call( int64_compare_int64_int64, .Generic, e1, as.uint64(e2), TRUE)
} )
setMethod( "Summary", "int64", function(x,..., na.rm = FALSE){
.Call( int64_summary_int64, .Generic, x, FALSE)
} )
setMethod( "Summary", "uint64", function(x,..., na.rm = FALSE){
.Call( int64_summary_int64, .Generic, x, TRUE)
} )
setMethod( "as.character", "int64", function(x,...){
.Call( int64_as_character_int64, x, FALSE)
})
setMethod( "as.character", "uint64", function(x,...){
.Call( int64_as_character_int64, x, TRUE)
})
as.data.frame.int64 <- as.data.frame.uint64 <- as.data.frame.vector
format.int64 <- format.uint64 <- function(x, ...){
as.character(x)
}
numeric_limits <- function( type ){
.Call( int64_limits, type )
}
setGeneric( "unique" )
setMethod( "unique", "int64", function(x, incomparables = FALSE, ...){
new( "int64", .Data = unique( x@.Data, incomparables, ... ) )
} )
setMethod( "unique", "uint64", function(x, incomparables = FALSE, ...){
new( "uint64", .Data = unique( x@.Data, incomparables, ... ) )
} )
setGeneric( "sort" )
setMethod( "sort", "int64", function(x, decreasing = FALSE, ...){
.Call( int64_sort, x, FALSE, decreasing )
} )
setMethod( "sort", "uint64", function(x, decreasing = FALSE, ...){
.Call( int64_sort, x, TRUE, decreasing )
} )
setMethod( "Math", "int64", function(x){
.Call( int64_math, .Generic, x, FALSE)
} )
setMethod( "Math", "uint64", function(x){
.Call( int64_math, .Generic, x, TRUE )
} )
# implementation of signif using string maniplation
int64_Math2 <- function( type = "int64", .Generic, x, digits ){
if( .Generic == "round" ) x else{
if( any(digits<0 ) ) stop("digits must be positive")
# signif
s <- as.character( x )
len <- nchar( s )
signs <- ! grepl( "^-", s )
s <- sub( "^-", "", s )
# recycling
digits <- as.integer( rep( digits, length = length( s ) ) )
digits[ digits == 0L ] <- 1L
res <- .Call( int64_signif, s, digits, len )
res <- sprintf( "%s%s", ifelse(signs, "", "-"), res )
if( type == "int64" ) as.int64(res) else as.uint64(res)
}
}
setMethod( "Math2", "int64", function(x, digits = 6L){
int64_Math2( "int64", .Generic, x, digits )
} )
setMethod( "Math2", "uint64", function(x, digits = 6L){
int64_Math2( "uint64", .Generic, x, digits )
} )
setMethod( "is.na", "int64", function(x){
.Call( int64_isna, x, FALSE )
})
setMethod( "is.na", "uint64", function(x){
.Call( int64_isna, x, TRUE )
})
c_int64 <- function(as, ctor){
function(x, ..., recursive = FALSE ){
dots <- list(...)
if( !length(dots) ) return(x)
dots <- lapply( dots, function(x) as(x)@.Data )
n <- length(x) + sum( sapply( dots, length ) )
res <- ctor(n)
res@.Data[ 1:length(x) ] <- x@.Data
start <- length(x)+1L
for( i in 1:length(dots)){
data <- dots[[i]]
res@.Data[ start:(start+length(data)-1L) ] <- data
start <- start + length(data)
}
res
}
}
setMethod( "c", "int64", c_int64( as.int64, int64 ) )
setMethod( "c", "uint64", c_int64( as.uint64, uint64 ) )
setAs("character", "int64", function(from) as.int64(from))
setAs("character", "uint64", function(from) as.uint64(from))
setAs("integer", "int64", function(from) as.int64(from))
setAs("integer", "uint64", function(from) as.uint64(from))
setAs("logical", "int64", function(from) as.int64(from))
setAs("logical", "uint64", function(from) as.uint64(from))
setAs("numeric", "int64", function(from) as.int64(from))
setAs("numeric", "uint64", function(from) as.uint64(from))
str.int64 <- str.uint64 <- function(object, ...){
writeLines( sprintf( " %s [1:%d] %s ...", class(object), length(object),
paste( as.character( head( object, 3 ) ), collapse = " " )
) )
}
int64/NAMESPACE 0000644 0001751 0000144 00000000767 11664531377 012502 0 ustar hornik users useDynLib( int64, .registration = TRUE )
import( methods )
exportClasses( "int64", "uint64", "binary" )
exportMethods(
show, length, "[", Arith, Compare, Summary, Math, Math2,
as.character, names, "names<-",
binary, unique, sort, is.na, c
)
export(
int64, uint64, as.int64, as.uint64, numeric_limits
)
S3method( format, int64 )
S3method( format, uint64 )
S3method( as.data.frame , int64 )
S3method( as.data.frame , uint64 )
S3method( str, int64 )
S3method( str, uint64 )
int64/man/ 0000755 0001751 0000144 00000000000 11665656774 012036 5 ustar hornik users int64/man/unique-methods.Rd 0000644 0001751 0000144 00000001353 11660746102 015252 0 ustar hornik users \name{unique-methods}
\docType{methods}
\alias{unique-methods}
\alias{unique,ANY-method}
\alias{unique,int64-method}
\alias{unique,uint64-method}
\title{Unique implementation for 64 bit integer vectors}
\description{
Implementation of \code{\link{unique}} for 64 bit integer vectors
}
\section{Methods}{
\describe{
\item{\code{signature(x = "ANY")}}{default implementation (from base)}
\item{\code{signature(x = "int64")}}{
signed 64 bit integer vectors. \code{\linkS4class{int64}}
}
\item{\code{signature(x = "uint64")}}{
unsigned 64 bit integer vectors. \code{\linkS4class{uint64}}
}
}}
\keyword{methods}
\examples{
x <- as.int64( c(1:5, 1L, 5L) )
unique( x )
x <- as.uint64( c(1:5, 1L, 5L) )
unique( x )
}
int64/man/uint64.Rd 0000644 0001751 0000144 00000001311 11663177026 013434 0 ustar hornik users \name{uint64}
\alias{uint64}
\title{
Creates new uint64 vectors of a given length
}
\description{
Creates new \code{\linkS4class{uint64}} vectors of a given length
}
\usage{
uint64(length = 0L)
}
\arguments{
\item{length}{
Length of the resulting vector
}
}
\value{
A new \code{\linkS4class{uint64}} vector of the given length
}
\author{
Romain Francois, Sponsored by the Google Open Source Programs Office
}
\seealso{
\code{\link{as.uint64}} for converting integer or character vectors
into \code{\linkS4class{uint64}} vectors.
\code{\link{int64}} for signed 64 bit integer vectors, i.e. of class
\code{\linkS4class{int64}}.
}
\examples{
x <- uint64(10L)
}
\keyword{manip}
int64/man/uint64-class.Rd 0000644 0001751 0000144 00000006037 11662667471 014560 0 ustar hornik users \name{uint64-class}
\Rdversion{1.1}
\docType{class}
\alias{uint64-class}
\alias{Math,uint64-method}
\alias{Math2,uint64-method}
\alias{[,uint64-method}
\alias{[<-,uint64-method}
\alias{Arith,ANY,uint64-method}
\alias{Arith,uint64,ANY-method}
\alias{Arith,uint64,uint64-method}
\alias{as.character,uint64-method}
\alias{names,uint64-method}
\alias{names<-,uint64-method}
\alias{Compare,ANY,uint64-method}
\alias{Compare,uint64,ANY-method}
\alias{Compare,uint64,uint64-method}
\alias{length,uint64-method}
\alias{show,uint64-method}
\alias{Summary,uint64-method}
\alias{c,uint64-method}
\alias{is.na,uint64-method}
\title{Class \code{"uint64"}}
\description{
Vector of signed 64 bit integers
}
\section{Objects from the Class}{
Objects can be created by using the \code{\link{uint64}} function,
by converting character vectors or integer vectors using the
\code{\link{as.uint64}} function.
}
\section{Slots}{
\describe{
\item{\code{.Data}:}{list of integer vectors of length 2. Each
uint64 number is coded as two integers. }
\item{\code{NAMES}:}{Used for names of vectors. This is only being
used through the \code{names} and \code{names<-} functions. }
}
}
\section{Extends}{
Class \code{"\linkS4class{list}"}, from data part.
Class \code{"\linkS4class{vector}"}, by class "list", distance 2.
}
\section{Methods}{
\describe{
\item{[}{\code{signature(x = "uint64")}: ... }
\item{[<-}{\code{signature(x = "uint64")}: ... }
\item{Arith}{\code{signature(e1 = "ANY", e2 = "uint64")}: ... }
\item{Arith}{\code{signature(e1 = "uint64", e2 = "ANY")}: ... }
\item{Arith}{\code{signature(e1 = "uint64", e2 = "uint64")}: ... }
\item{as.character}{\code{signature(x = "uint64")}: ... }
\item{Compare}{\code{signature(e1 = "ANY", e2 = "uint64")}: ... }
\item{Compare}{\code{signature(e1 = "uint64", e2 = "ANY")}: ... }
\item{Compare}{\code{signature(e1 = "uint64", e2 = "uint64")}: ... }
\item{length}{\code{signature(x = "uint64")}: ... }
\item{Summary}{\code{signature(x = "uint64")}: ... }
\item{Math}{\code{signature(x = "uint64")}: ... }
\item{Math2}{\code{signature(x = "uint64")}: ... }
\item{c}{\code{signature(x = "uint64")}: ... }
\item{is.na}{\code{signature(x = "uint64")}: ... }
}
}
\author{
Romain Francois. Sponsored the Google Open Source Programs Office.
}
\seealso{
\code{\link{as.uint64}} to convert character or integer vectors.
\code{\link{uint64}} to create new \code{\linkS4class{uint64}} vectors of a given size.
The \code{\linkS4class{int64}} class to represent signed 64 bit
integer vectors.
}
\examples{
x <- uint64( 4 )
# setting subsets
x[1:2] <- 1:2
x[3:4] <- c("123456789012345", "9876543219876")
x
# arithmetic operations
x * 2L
x + x
x - 3L
# logical operations
x < 3L
x != c( 1L, 2L )
# Summary operations
range( x )
min( x )
max( x )
length(x)
df <- data.frame( a = 1:4 )
df$b <- x
df
as.character( x )
}
\keyword{classes}
int64/man/sort-methods.Rd 0000644 0001751 0000144 00000001073 11660746102 014732 0 ustar hornik users \name{sort-methods}
\docType{methods}
\alias{sort-methods}
\alias{sort,ANY-method}
\alias{sort,int64-method}
\alias{sort,uint64-method}
\title{Sorting 64 bits integer vector}
\description{
Sorting 64 bits integer vector
}
\section{Methods}{
\describe{
\item{\code{signature(x = "ANY")}}{
Standard method (from base)
}
\item{\code{signature(x = "int64")}}{
Sorting signed 64 bit integer vectors (\code{\linkS4class{int64}}
}
\item{\code{signature(x = "uint64")}}{
Sorting unsigned 64 bit integer vectors (\code{\linkS4class{uint64}}
}
}}
\keyword{methods}
int64/man/numeric_limits.Rd 0000644 0001751 0000144 00000000760 11660746102 015327 0 ustar hornik users \name{numeric_limits}
\alias{numeric_limits}
\title{
Give numeric limits of integer types
}
\description{
Give numeric limits of integer types
}
\usage{
numeric_limits(type)
}
\arguments{
\item{type}{type. must be integer, int64 or uint64. }
}
\value{
A vector of two values of the appropriate type.
}
\author{
Romain Francois, sponsored by the Google Open Source Programs Office
}
\examples{
numeric_limits( "integer" )
numeric_limits( "int64" )
numeric_limits( "uint64" )
}
\keyword{manip}
int64/man/int64.Rd 0000644 0001751 0000144 00000001303 11662667262 013255 0 ustar hornik users \name{int64}
\alias{int64}
\title{
Creates new int64 vectors of a given length
}
\description{
Creates new \code{\linkS4class{int64}} vectors of a given length
}
\usage{
int64(length = 0L)
}
\arguments{
\item{length}{
Length of the resulting vector
}
}
\value{
A new \code{\linkS4class{int64}} vector of the given length
}
\author{
Romain Francois, Sponsored by the Google Open Source Programs Office
}
\seealso{
\code{\link{as.int64}} for converting integer or character vectors
into \code{\linkS4class{int64}} vectors.
\code{\link{uint64}} for unsigned 64 bit integer vectors, i.e. of
class \code{\linkS4class{uint64}}
}
\examples{
x <- int64(10L)
}
\keyword{manip}
int64/man/int64-package.Rd 0000644 0001751 0000144 00000001032 11665622021 014630 0 ustar hornik users \name{int64-package}
\alias{int64-package}
\docType{package}
\title{
64 bit integer types
}
\description{
64 bit integer types
}
\details{
\tabular{ll}{
Package: \tab int64\cr
Type: \tab Package\cr
Version: \tab 1.1.2\cr
Date: \tab 2011-12-01\cr
License: \tab GPL (>= 2)\cr
LazyLoad: \tab yes\cr
}
}
\author{
Romain Francois, Sponsored by Google Open Source Programs Office
Maintainer: Romain Francois
}
\examples{
as.int64( 1:4 )
as.int64( c("123456789", "9876543219876543" ) )
}
\keyword{ package }
int64/man/int64-class.Rd 0000644 0001751 0000144 00000006343 11662667417 014373 0 ustar hornik users \name{int64-class}
\Rdversion{1.1}
\docType{class}
\alias{int64-class}
\alias{[,int64-method}
\alias{Math,int64-method}
\alias{Math2,int64-method}
\alias{[<-,int64-method}
\alias{Arith,ANY,int64-method}
\alias{Arith,int64,ANY-method}
\alias{Arith,int64,int64-method}
\alias{as.character,int64-method}
\alias{names,int64-method}
\alias{names<-,int64-method}
\alias{Compare,ANY,int64-method}
\alias{Compare,int64,ANY-method}
\alias{Compare,int64,int64-method}
\alias{length,int64-method}
\alias{show,int64-method}
\alias{Summary,int64-method}
\alias{c,int64-method}
\alias{is.na,int64-method}
\title{Class \code{"int64"}}
\description{
Vector of signed 64 bit integers
}
\section{Objects from the Class}{
Objects can be created by using the \code{\link{int64}} function,
by converting character vectors or integer vectors using the
\code{\link{as.int64}} function.
}
\section{Slots}{
\describe{
\item{\code{.Data}:}{list of integer vectors of length 2. Each
int64 number is coded as two integers. }
\item{\code{NAMES}:}{Used for names of vectors. This is only being
used through the \code{names} and \code{names<-} functions. }
}
}
\section{Extends}{
Class \code{"\linkS4class{list}"}, from data part.
Class \code{"\linkS4class{vector}"}, by class "list", distance 2.
}
\section{Methods}{
\describe{
\item{[}{\code{signature(x = "int64")}: ... }
\item{[<-}{\code{signature(x = "int64")}: ... }
\item{Arith}{\code{signature(e1 = "ANY", e2 = "int64")}: ... }
\item{Arith}{\code{signature(e1 = "int64", e2 = "ANY")}: ... }
\item{Arith}{\code{signature(e1 = "int64", e2 = "int64")}: ... }
\item{as.character}{\code{signature(x = "int64")}: ... }
\item{Compare}{\code{signature(e1 = "ANY", e2 = "int64")}: ... }
\item{Compare}{\code{signature(e1 = "int64", e2 = "ANY")}: ... }
\item{Compare}{\code{signature(e1 = "int64", e2 = "int64")}: ... }
\item{length}{\code{signature(x = "int64")}: ... }
\item{Summary}{\code{signature(x = "int64")}: ... }
\item{Math}{\code{signature(x = "int64")}: ... }
\item{Math2}{\code{signature(x = "int64")}: ... }
\item{c}{\code{signature(x = "int64")}: ... }
\item{is.na}{\code{signature(x = "int64")}: ... }
}
}
\author{
Romain Francois. Sponsored the Google Open Source Programs Office.
}
\seealso{
\code{\link{as.int64}} to convert character or integer vectors.
\code{\link{int64}} to create new \code{\linkS4class{int64}} vectors of a given size.
The \code{\linkS4class{uint64}} class to represent unsigned 64 bit
integer vectors.
}
\examples{
x <- int64( 4 )
# setting subsets
x[1:2] <- 1:2
x[3:4] <- c("123456789012345", "9876543219876")
x
# arithmetic operations
x * 2L
x + x
x - 3L
# arithmetic operations first convert both operands to 64 bit integer type
# so some precision will be lost
as.int64(1) + 1.5
# but it feels appropriate for dealing with large values
as.int64(43124567245667) + 1.5
# logical operations
x < 3L
x != c( 1L, 2L )
# Summary operations
range( x )
min( x )
max( x )
length(x)
df <- data.frame( a = 1:4 )
df$b <- x
df
as.character( x )
}
\keyword{classes}
int64/man/binary-methods.Rd 0000644 0001751 0000144 00000001432 11660746102 015226 0 ustar hornik users \name{binary-methods}
\docType{methods}
\alias{binary}
\alias{binary-methods}
\alias{binary,integer-method}
\alias{binary,int64-method}
\alias{binary,uint64-method}
\alias{binary,numeric-method}
\title{Get binary representation}
\description{
Get binary representation
}
\section{Methods}{
\describe{
\item{\code{signature(object = "integer")}}{
Method for integer Vectors
}
\item{\code{signature(object = "int64")}}{
Method for \code{\linkS4class{int64}} vectors
}
\item{\code{signature(object = "uint64")}}{
Method for \code{\linkS4class{uint64}} vectors
}
\item{\code{signature(object = "numeric")}}{
Method for numeric vectors
}
}}
\examples{
binary( 1:4 )
binary( c( 1.0, 2.0 ) )
binary( as.int64( 1:4 ) )
binary( as.uint64( 1:4 ) )
}
\keyword{methods}
int64/man/binary-class.Rd 0000644 0001751 0000144 00000001220 11660746102 014663 0 ustar hornik users \name{binary-class}
\Rdversion{1.1}
\docType{class}
\alias{binary-class}
\alias{show,binary-method}
\title{Class \code{"binary"}}
\description{
Binary representation
}
\section{Objects from the Class}{
Objects can be created by one of the forms of the \code{\link{binary}} methods.
}
\section{Slots}{
\describe{
\item{\code{data}:}{Character vectors, with 0 and 1}
\item{\code{bits}:}{Number of bits}
}
}
\section{Methods}{
\describe{
\item{show}{\code{signature(object = "binary")}: display method }
}
}
\author{
Romain Francois, sponsored by the Google Open Source Programs Office
}
\examples{
binary( 1:4 )
}
\keyword{classes}
int64/man/as.uint64.Rd 0000644 0001751 0000144 00000001455 11660746102 014041 0 ustar hornik users \name{as.uint64}
\alias{as.uint64}
\title{
Convert character or integer vectors into uint64 vectors.
}
\description{
Convert character or integer vectors into \code{\linkS4class{uint64}} vectors.
}
\usage{
as.uint64(x)
}
\arguments{
\item{x}{
A character or integer vector
}
}
\details{
For conversion of character vectors, the C function \code{atol} is used.
}
\value{
A new \code{\linkS4class{int64}} vector.
}
\references{
C++ \code{atol} function: \url{http://www.cplusplus.com/reference/clibrary/cstdlib/atol/}
}
\seealso{
\code{\link{as.int64}} for conversion to signed long vectors.
}
\author{
Romain Francois, sponsored by the Google Open Source Programs Office
}
\examples{
as.uint64( c(1L, 2L ) )
as.uint64( c("123456789123456", "987654321987654" ) )
}
\keyword{manip}
int64/man/as.int64.Rd 0000644 0001751 0000144 00000001451 11660746102 013650 0 ustar hornik users \name{as.int64}
\alias{as.int64}
\title{
Convert character or integer vectors into int64 vectors.
}
\description{
Convert character or integer vectors into \code{\linkS4class{int64}} vectors.
}
\usage{
as.int64(x)
}
\arguments{
\item{x}{
A character or integer vector
}
}
\details{
For conversion of character vectors, the C function \code{atol} is used.
}
\value{
A new \code{\linkS4class{int64}} vector.
}
\references{
C++ \code{atol} function: \url{http://www.cplusplus.com/reference/clibrary/cstdlib/atol/}
}
\seealso{
\code{\link{as.uint64}} for conversion to unsigned long vectors.
}
\author{
Romain Francois, sponsored by the Google Open Source Programs Office
}
\examples{
as.int64( c(1L, 2L ) )
as.int64( c("123456789123456", "987654321987654" ) )
}
\keyword{manip}
int64/inst/ 0000755 0001751 0000144 00000000000 11665656774 012240 5 ustar hornik users int64/inst/unitTests/ 0000755 0001751 0000144 00000000000 11665656774 014242 5 ustar hornik users int64/inst/unitTests/runTests.R 0000644 0001751 0000144 00000013051 11660746102 016170 0 ustar hornik users ## Copyright (C) 2011 Romain Francois
## Copyright (C) 2011 Google Inc. All rights reserved.
##
## This file is part of int64.
##
## int64 is free software: you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 2 of the License, or
## (at your option) any later version.
##
## int64 is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with int64. If not, see .
pkg <- "int64"
if(require("RUnit", quietly = TRUE)) {
is_local <- function(){
if( exists( "argv", globalenv() ) && "--local" %in% argv ) return(TRUE)
if( "--local" %in% commandArgs(TRUE) ) return(TRUE)
FALSE
}
if (is_local() ) path <- getwd()
library(package=pkg, character.only = TRUE)
if(!(exists("path") && file.exists(path)))
path <- system.file("unitTests", package = pkg)
## --- Testing ---
## Define tests
testSuite <- defineTestSuite(name=paste(pkg, "unit testing"), dirs = path
# , testFileRegexp = "Vector"
)
## this is crass but as we time out on Windows we have no choice
## but to disable a number of tests
## TODO: actually prioritize which ones we want
allTests <- function() {
if (.Platform$OS.type != "windows") return(TRUE)
if (exists( "argv", globalenv() ) && "--allTests" %in% argv) return(TRUE)
if ("--allTests" %in% commandArgs(TRUE)) return(TRUE)
return(FALSE)
}
## if (.Platform$OS.type == "windows" && allTests() == FALSE) {
## ## by imposing [D-Z] (instead of an implicit A-Z) we are going from
## ## 45 tests to run down to 38 (numbers as of release 0.8.3)
## testSuite$testFileRegexp <- "^runit.[D-Z]+\\.[rR]$"
## }
if (interactive()) {
cat("Now have RUnit Test Suite 'testSuite' for package '", pkg,
"' :\n", sep='')
str(testSuite)
cat('', "Consider doing",
"\t tests <- runTestSuite(testSuite)", "\nand later",
"\t printTextProtocol(tests)", '', sep="\n")
} else { ## run from shell / Rscript / R CMD Batch / ...
## Run
tests <- runTestSuite(testSuite)
output <- NULL
process_args <- function(argv){
if( !is.null(argv) && length(argv) > 0 ){
rx <- "^--output=(.*)$"
g <- grep( rx, argv, value = TRUE )
if( length(g) ){
sub( rx, "\\1", g[1L] )
}
}
}
# R CMD check uses this
if( exists( "int64.unit.test.output.dir", globalenv() ) ){
output <- int64.unit.test.output.dir
} else {
## give a chance to the user to customize where he/she wants
## the unit tests results to be stored with the --output= command
## line argument
if( exists( "argv", globalenv() ) ){
## littler
output <- process_args(argv)
} else {
## Rscript
output <- process_args(commandArgs(TRUE))
}
}
# if it did not work, try to use /tmp
if( is.null(output) ){
if( file.exists( "/tmp" ) ){
output <- "/tmp"
} else{
output <- getwd()
}
}
## Print results
output.txt <- file.path( output, sprintf("%s-unitTests.txt", pkg))
output.html <- file.path( output, sprintf("%s-unitTests.html", pkg))
printTextProtocol(tests, fileName=output.txt)
message( sprintf( "saving txt unit test report to '%s'", output.txt ) )
## Print HTML version to a file
## printHTMLProtocol has problems on Mac OS X
if (Sys.info()["sysname"] != "Darwin"){
message( sprintf( "saving html unit test report to '%s'", output.html ) )
printHTMLProtocol(tests, fileName=output.html)
}
## stop() if there are any failures i.e. FALSE to unit test.
## This will cause R CMD check to return error and stop
err <- getErrors(tests)
if( (err$nFail + err$nErr) > 0) {
data <- Filter(
function(x) any( sapply(x, function(.) .[["kind"]] ) %in% c("error","failure") ) ,
tests[[1]]$sourceFileResults )
err_msg <- sapply( data,
function(x) {
raw.msg <- paste(
sapply( Filter( function(.) .[["kind"]] %in% c("error","failure"), x ), "[[", "msg" ),
collapse = " // "
)
raw.msg <- gsub( "Error in compileCode(f, code, language = language, verbose = verbose) : \n", "", raw.msg, fixed = TRUE )
raw.msg <- gsub( "\n", "", raw.msg, fixed = TRUE )
raw.msg
}
)
msg <- sprintf( "unit test problems: %d failures, %d errors\n%s",
err$nFail, err$nErr,
paste( err_msg, collapse = "\n" )
)
stop( msg )
} else{
success <- err$nTestFunc - err$nFail - err$nErr - err$nDeactivated
cat( sprintf( "%d / %d\n", success, err$nTestFunc ) )
}
}
} else {
cat("R package 'RUnit' cannot be loaded -- no unit tests run\n",
"for package", pkg,"\n")
}
int64/inst/unitTests/runit.int64.R 0000644 0001751 0000144 00000010505 11663402306 016444 0 ustar hornik users # Copyright (C) 2011 Romain Francois
# Copyright (C) 2011 Google Inc. All rights reserved.
#
# This file is part of int64.
#
# int64 is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# int64 is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with int64. If not, see .
test.int64 <- function(){
ints <- c(-122L, 0L, 1L, 122L)
x <- as.int64(ints)
checkEquals(
as.integer(as.character(x)),
ints
)
checkEquals( as.character(x+1L), as.character(ints+1L) )
checkEquals( as.character(x-1L), as.character(ints-1L) )
checkEquals( as.character(x*x), as.character(ints*ints) )
checkEquals( as.character(x/2L), as.character(as.integer(ints/2L)) )
checkEquals( x > 0L, ints > 0L )
checkEquals( x < 0L, ints < 0L )
checkEquals( x == 0L, ints == 0L )
checkEquals( x != 0L, ints != 0L )
checkEquals( x <= 0L, ints <= 0L )
checkEquals( x >= 0L, ints >= 0L )
checkEquals( range(x), as.int64(c(-122L, 122L)) )
checkEquals( min(x), as.int64(-122L) )
checkEquals( max(x), as.int64(122L) )
checkEquals( prod(x), as.int64(as.integer(prod(ints))) )
checkEquals( sum(x), as.int64(as.integer(sum(ints))) )
checkEquals( any(x), any(ints) )
checkEquals( all(x), all(ints) )
chars <- c( "-9223372036854775807", "9223372036854775807" )
x <- as.int64( chars )
checkEquals( as.character(x), chars )
}
test.uint64 <- function(){
ints <- c(0L, 1L, 123L)
x <- as.uint64(ints)
checkEquals(
as.integer(as.character(x)),
ints
)
chars <- c( "123456789123456789", "18446744073709551614" )
x <- as.uint64( chars )
checkEquals( as.character(x), chars )
}
test.unique.int64 <- function(){
x <- as.int64( c(1:5, 1L, 3L) )
checkEquals( unique(x), as.int64(1:5) )
x <- as.uint64( c(1:5, 1L, 3L) )
checkEquals( unique(x), as.uint64(1:5) )
}
test.sort <- function( ){
x <- as.int64( c(1:4, 3L ) )
checkEquals( sort( x ), as.int64( c(1:3,3L,4L) ) )
checkEquals( sort( x, decreasing = TRUE), as.int64( c(4L,3L,3:1) ) )
x <- as.uint64( c(1:4, 3L ) )
checkEquals( sort( x ), as.uint64( c(1:3,3L,4L) ) )
checkEquals( sort( x, decreasing = TRUE), as.uint64( c(4L,3L,3:1) ) )
}
test.signif <- function(){
x <- as.int64( c( "12345", "12345", "12345" ) )
checkEquals(
signif( x, c(2,3,7) ),
as.int64( c("12000", "12300", "12345") )
)
x <- as.uint64( c( "12345", "12345", "12345" ) )
checkEquals(
signif( x, c(2,3,7) ),
as.uint64( c("12000", "12300", "12345") )
)
}
test.names <- function(){
x <- as.int64( 1:5 )
checkTrue( is.null(names(x) ) )
names <- letters[1:5]
names(x) <- names
checkEquals( names(x), letters[1:5] )
names(x) <- NULL
checkTrue( is.null(names(x) ) )
x <- as.uint64( 1:5 )
checkTrue( is.null(names(x) ) )
names <- letters[1:5]
names(x) <- names
checkEquals( names(x), letters[1:5] )
names(x) <- NULL
checkTrue( is.null(names(x) ) )
}
test.na <- function(){
old.op <- options( warn = 2 )
checkException( as.int64( "abcd12434" ) )
checkException( as.uint64( "abcd12434" ) )
checkEquals( as.int64("1234"), as.int64(1234))
checkEquals( as.uint64("1234"), as.uint64(1234))
options( old.op )
}
test.dataframe <- function(){
df <- data.frame( a = 1:4 )
df$b <- as.int64( 1:4 )
df$c <- as.uint64( 1:4 )
checkEquals( df$b[3:4], df$b[1:2] + 2L )
checkEquals( df$c[3:4], df$c[1:2] + 2L )
}
test.read.csv <- function(){
df <- data.frame( x = 1:10, y = 1:10, z = 1:10 )
tf <- tempfile()
write.table( df, tf, row.names = FALSE, sep = "," )
df <- read.csv( tf, header = TRUE,
colClasses = c( "integer", "int64", "uint64" ) )
checkEquals( df$x, 1:10 )
checkEquals( df$y, as.int64(1:10) )
checkEquals( df$z, as.uint64(1:10) )
}
int64/inst/NEWS 0000644 0001751 0000144 00000000517 11664531377 012730 0 ustar hornik users 1.1.1 2011-11-27
o str methods for [u]int64 classes. Requested by @hadleywickham
o log and log10 method for [u]int64 classes. Requested by @hadleywickham
1.1.0 2011-11-24
o Implemented setAs so that read.csv can handle colClasses = "int64"
and "uint64" using Gabor Grothendieck suggestion on R-devel
int64/inst/include/ 0000755 0001751 0000144 00000000000 11665656774 013663 5 ustar hornik users int64/inst/include/int64.h 0000644 0001751 0000144 00000002062 11660746102 014754 0 ustar hornik users // int64.h : 64 bit integers
//
// Copyright (C) 2011 Romain Francois
// Copyright (C) 2011 Google Inc. All rights reserved.
//
// This file is part of int64.
//
// int64 is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// int64 is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with int64. If not, see .
#ifndef int64__h
#define int64__h
#define R_NO_REMAP
#include
#include
#include // replace with cstdint if newer C++ standard used
#include // for numeric_limits
#include
#include
#include
#endif
int64/inst/include/int64/ 0000755 0001751 0000144 00000000000 11665656774 014627 5 ustar hornik users int64/inst/include/int64/summary.h 0000644 0001751 0000144 00000013064 11661703756 016466 0 ustar hornik users // summary.h : 64 bit integers
//
// Copyright (C) 2011 Romain Francois
// Copyright (C) 2011 Google Inc. All rights reserved.
//
// This file is part of int64.
//
// int64 is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// int64 is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with int64. If not, see .
#ifndef int64__summary__h
#define int64__summary__h
namespace Rint64{
namespace internal{
template
SEXP summary__min( const Rint64::LongVector& data){
const LONG na = long_traits::na() ;
LONG x = data.get(0) ;
if( x == na ) return Rint64::internal::new_long( na ) ;
LONG tmp = x ;
int n = data.size() ;
for( int i=1; i( x ) ;
}
template
SEXP summary__max( const Rint64::LongVector& data){
const LONG na = long_traits::na() ;
LONG x = data.get(0) ;
LONG tmp = x ;
int n = data.size() ;
for( int i=1; i x ) x = tmp ;
}
return Rint64::internal::new_long( x ) ;
}
template
SEXP summary__range( const Rint64::LongVector& data){
const LONG na = long_traits::na() ;
LONG min = data.get(0) ;
LONG max = data.get(0) ;
if( min == na ) return Rint64::internal::new_long_2( na, na) ;
LONG tmp = min ;
int n = data.size() ;
for( int i=1; i max ) max = tmp ;
}
return Rint64::internal::new_long_2( min, max) ;
}
template
SEXP summary__prod( const Rint64::LongVector& data){
const LONG na = long_traits::na() ;
LONG res = data.get(0) ;
if( res == na ) return Rint64::internal::new_long( na ) ;
int n = data.size() ;
int64_naflag = false ;
for( int i=1; i( res, data.get(i) );
if( res == na) break ;
}
if( int64_naflag ) Rf_warning( "NAs introduced by overflow" ) ;
return Rint64::internal::new_long( res ) ;
}
template
SEXP summary__sum( const Rint64::LongVector& data){
const LONG na = long_traits::na() ;
LONG res = data.get(0) ;
if( res == na ) return Rint64::internal::new_long( na ) ;
int n = data.size() ;
int64_naflag = false ;
for( int i=1; i( res, data.get(i) ) ;
if( res == na ) break ;
}
if( int64_naflag ) Rf_warning( "NAs introduced by overflow" ) ;
return Rint64::internal::new_long( res ) ;
}
template
SEXP summary__any( const Rint64::LongVector& data){
const LONG na = long_traits::na() ;
int n = data.size() ;
int res = 0 ;
bool seen_na = false ;
LONG tmp ;
for( int i=0; i
SEXP summary__all( const Rint64::LongVector& data){
const LONG na = long_traits::na() ;
int n = data.size() ;
int res = 1 ;
LONG tmp ;
bool seen_na = false ;
for( int i=0; i
SEXP int64_summary(const char* op, SEXP x){
Rint64::LongVector data( x ) ;
if( ! strncmp(op, "min", 3) ){
return Rint64::internal::summary__min( data ) ;
} else if( !strncmp(op, "max", 3) ){
return Rint64::internal::summary__max( data ) ;
} else if( !strncmp(op, "range", 5 ) ){
return Rint64::internal::summary__range( data ) ;
} else if( !strncmp(op, "prod", 4) ){
return Rint64::internal::summary__prod( data ) ;
} else if( !strncmp(op, "sum", 3 ) ) {
return Rint64::internal::summary__sum( data ) ;
} else if( !strncmp(op, "any", 3 ) ){
return Rint64::internal::summary__any( data ) ;
} else if( !strncmp(op, "all", 3) ){
return Rint64::internal::summary__all( data ) ;
}
Rf_error( "unknown operator" ) ;
return R_NilValue ;
}
} // namespace internal
} // namespace Rint64
#endif
int64/inst/include/int64/routines.h 0000644 0001751 0000144 00000003303 11660746102 016623 0 ustar hornik users // routines.h: int64 64 bit integers - .Call exports
//
// Copyright (C) 2011 Romain Francois
// Copyright (C) 2011 Google Inc. All rights reserved.
//
// This file is part of int64.
//
// int64 is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// int64 is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with int64. If not, see .
#ifndef int64_routines_h
#define int64_routines_h
#define CALLFUN_0(name) SEXP name()
#define CALLFUN_1(name) SEXP name(SEXP)
#define CALLFUN_2(name) SEXP name(SEXP,SEXP)
#define CALLFUN_3(name) SEXP name(SEXP,SEXP,SEXP)
#define CALLFUN_4(name) SEXP name(SEXP,SEXP,SEXP,SEXP)
#define CALLFUN_5(name) SEXP name(SEXP,SEXP,SEXP,SEXP,SEXP)
#define EXTFUN(name) SEXP name(SEXP)
// we have to do the ifdef __cplusplus dance because this file
// is included both in C and C++ files
#ifdef __cplusplus
extern "C" {
#endif
CALLFUN_1(int64_as_int64) ;
CALLFUN_1(int64_format_binary) ;
CALLFUN_2(int64_as_character_int64) ;
CALLFUN_4(int64_arith_int64_int64) ;
CALLFUN_4(int64_compare_int64_int64) ;
CALLFUN_3(int64_summary_int64) ;
CALLFUN_1(int64_as_uint64) ;
CALLFUN_1(int64_limits) ;
CALLFUN_3(int64_sort) ;
CALLFUN_3(int64_math) ;
CALLFUN_3(int64_signif) ;
CALLFUN_2(int64_isna) ;
#ifdef __cplusplus
}
#endif
#endif
int64/inst/include/int64/read_string_forward.h 0000644 0001751 0000144 00000002076 11661703756 021017 0 ustar hornik users // read_string_forward.h : 64 bit integers
//
// Copyright (C) 2011 Romain Francois
// Copyright (C) 2011 Google Inc. All rights reserved.
//
// This file is part of int64.
//
// int64 is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// int64 is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with int64. If not, see .
#ifndef int64__read_string_forward_h
#define int64__read_string_forward_h
namespace Rint64{
namespace internal{
template
inline LONG read_string(const char* s) ;
} // namespace internal
} // namespace Rint64
#endif
int64/inst/include/int64/read_string.h 0000644 0001751 0000144 00000003102 11661703756 017262 0 ustar hornik users // read_string.h : 64 bit integers
//
// Copyright (C) 2011 Romain Francois
// Copyright (C) 2011 Google Inc. All rights reserved.
//
// This file is part of int64.
//
// int64 is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// int64 is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with int64. If not, see .
#ifndef int64__read_string__h
#define int64__read_string__h
namespace Rint64{
namespace internal{
template <>
inline int64_t read_string(const char* s ){
errno = 0 ;
int64_t res = strtoll( s, NULL, 0 ) ;
if( errno == ERANGE ) {
res = Rint64::LongVector::na() ;
int64_naflag = true ;
}
return res ;
}
template <>
inline uint64_t read_string(const char* s){
errno = 0 ;
uint64_t res = strtoull( s, NULL, 0 ) ;
if( errno == ERANGE ) {
res = Rint64::LongVector::na() ;
int64_naflag = true ;
}
return res ;
}
} // namespace internal
} // namespace Rint64
#endif
int64/inst/include/int64/math.h 0000644 0001751 0000144 00000013554 11665622053 015720 0 ustar hornik users // math.h : 64 bit integers
//
// Copyright (C) 2011 Romain Francois
// Copyright (C) 2011 Google Inc. All rights reserved.
//
// This file is part of int64.
//
// int64 is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// int64 is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with int64. If not, see .
#ifndef int64__math__h
#define int64__math__h
namespace Rint64{
namespace internal{
template
SEXP abs( SEXP x ){
const LONG na = long_traits::na() ;
Rint64::LongVector data(x) ;
int n = data.size() ;
LONG tmp ;
Rint64::LongVector res(n) ;
for( int i=0; i 0 ? tmp : -tmp ) ;
}
return res ;
}
template <>
inline SEXP abs( SEXP x ){ return x ; }
template
SEXP sign( SEXP x){
const LONG na = long_traits::na() ;
Rint64::LongVector data(x) ;
int n = data.size() ;
LONG tmp ;
SEXP res = PROTECT(Rf_allocVector(REALSXP,n)) ;
double* p_res = REAL(res) ;
for( int i=0; i 0 ) ? 0.0 : 1.0 ;
}
}
UNPROTECT(1) ;
return res ;
}
template
SEXP cummax( SEXP x){
const LONG na = long_traits::na() ;
Rint64::LongVector data(x) ;
int n = data.size() ;
Rint64::LongVector res(n, na) ;
LONG max = data.get(0) ;
res.set( 0, max) ;
LONG tmp = 0 ;
for( int i=1; i max ) max=tmp ;
res.set( i, max ) ;
}
return res ;
}
template
SEXP cummin( SEXP x){
const LONG na = long_traits::na() ;
Rint64::LongVector data(x) ;
int n = data.size() ;
Rint64::LongVector res(n, na) ;
LONG max = data.get(0) ;
res.set( 0, max) ;
LONG tmp = 0 ;
for( int i=1; i
SEXP cumprod( SEXP x){
const LONG na = long_traits::na() ;
Rint64::LongVector data(x) ;
int n = data.size() ;
Rint64::LongVector res(n, na) ;
LONG prod = data.get(0) ;
res.set( 0, prod) ;
int64_naflag = false ;
for( int i=1; i( prod, data.get(i) );
if( prod == na ) break ;
res.set( i, prod ) ;
}
if( int64_naflag ) {
Rf_warning( "NA introduced by overflow" ) ;
}
return res ;
}
template
SEXP cumsum( SEXP x){
const LONG na = long_traits::na() ;
Rint64::LongVector data(x) ;
int n = data.size() ;
Rint64::LongVector res(x) ;
LONG prod = data.get(0) ;
res.set( 0, prod) ;
int64_naflag = false ;
for( int i=1; i( prod, data.get(i) );
if( prod == na ) break ;
res.set( i, prod ) ;
}
if( int64_naflag ) {
Rf_warning( "NA introduced by overflow" ) ;
}
return res ;
}
template
SEXP int64_log10( SEXP x ){
Rint64::LongVector data(x) ;
int n = data.size() ;
const LONG na = long_traits::na() ;
SEXP res = PROTECT( Rf_allocVector( REALSXP, n ) ) ;
double* p_res = REAL(res) ;
LONG tmp;
for(int i=0; i
SEXP int64_log( SEXP x ){
Rint64::LongVector data(x) ;
int n = data.size() ;
const LONG na = long_traits::na() ;
SEXP res = PROTECT( Rf_allocVector( REALSXP, n ) ) ;
double* p_res = REAL(res) ;
LONG tmp;
for(int i=0; i
SEXP math( const char* op, SEXP x ){
if( !strncmp( op, "abs", 3 ) ){
return abs(x) ;
} else if( !strncmp(op, "sign", 4) ) {
return sign(x) ;
} else if( !strncmp( op, "trunc", 5 ) ){
return x ;
} else if( !strncmp( op, "floor", 5) ){
return x ;
} else if( !strncmp( op, "cummax", 6 ) ){
return cummax( x ) ;
} else if( !strncmp( op, "cummin", 6 ) ){
return cummin( x ) ;
} else if( !strncmp( op, "cumprod", 7 ) ){
return cumprod( x ) ;
} else if( !strncmp( op, "cumsum", 6 ) ){
return cumsum( x ) ;
} else if( !strncmp( op, "log10", 5 ) ){
return int64_log10( x ) ;
} else if( !strncmp( op, "log", 3 ) ){
return int64_log( x) ;
}
Rf_error( "generic not implemented" );
return R_NilValue ;
}
} // namespace internal
} // namespace Rint64
#endif
int64/inst/include/int64/LongVector.h 0000644 0001751 0000144 00000023770 11661703756 017060 0 ustar hornik users // routines.h: int64 64 bit integers
//
// Copyright (C) 2011 Romain Francois
// Copyright (C) 2011 Google Inc. All rights reserved.
//
// This file is part of int64.
//
// int64 is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// int64 is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with int64. If not, see .
#ifndef int64_LongVector_h
#define int64_LongVector_h
#include
#include
#include
#include
namespace Rint64{
template
class LongVector : public internal::long_traits {
private :
SEXP data ;
public:
LongVector(SEXP x) : data(x) {
if( Rf_inherits( x, internal::get_class().c_str() ) ){
data = x ;
R_PreserveObject(data) ;
} else {
switch( TYPEOF(x) ){
case INTSXP:
{
int n = Rf_length(x) ;
SEXP y = PROTECT( Rf_allocVector( VECSXP, n ) ) ;
int hb, lb ;
LONG tmp ;
int* p_i_x = INTEGER(x) ;
for( int i=0; i(tmp) ;
lb = internal::get_low_bits(tmp) ;
SET_VECTOR_ELT( y, i, Rint64::internal::int2(hb,lb) ) ;
}
}
UNPROTECT(1) ; // y
data = y ;
R_PreserveObject(data) ;
break ;
}
case LGLSXP:
{
int n = Rf_length(x) ;
SEXP y = PROTECT( Rf_allocVector( VECSXP, n ) ) ;
int hb, lb ;
LONG tmp ;
int* p_i_x = INTEGER(x) ;
for( int i=0; i(tmp) ;
lb = internal::get_low_bits(tmp) ;
SET_VECTOR_ELT( y, i, Rint64::internal::int2(hb,lb) ) ;
}
}
UNPROTECT(1) ; // y
data = y ;
R_PreserveObject(data) ;
break ;
}
case REALSXP:
{
int n = Rf_length(x) ;
SEXP y = PROTECT( Rf_allocVector( VECSXP, n ) ) ;
int hb, lb ;
LONG tmp ;
double* p_d_x = REAL(x) ;
for( int i=0; i(tmp) ;
lb = internal::get_low_bits(tmp) ;
SET_VECTOR_ELT( y, i, Rint64::internal::int2(hb,lb) ) ;
}
}
UNPROTECT(1) ; // y
data = y ;
R_PreserveObject(data) ;
break ;
}
case STRSXP:
{
int n = Rf_length(x) ;
Rint64::internal::int64_naflag = false ;
SEXP y = PROTECT( Rf_allocVector( VECSXP, n ) ) ;
int hb, lb ;
LONG tmp ;
for( int i=0; i( CHAR(STRING_ELT(x,i)) ) ;
hb = internal::get_high_bits(tmp) ;
lb = internal::get_low_bits(tmp) ;
SET_VECTOR_ELT( y, i, Rint64::internal::int2(hb,lb) ) ;
}
}
UNPROTECT(1) ; // y
data = y ;
R_PreserveObject(data) ;
if( Rint64::internal::int64_naflag ) {
Rf_warning( "NA introduced by overflow" ) ;
}
break ;
}
default:
{
Rf_error( "unimplemented conversion" ) ;
}
}
}
}
operator SEXP(){
std::string klass = Rint64::internal::get_class() ;
SEXP res = PROTECT(
R_do_slot_assign(
R_do_new_object( R_do_MAKE_CLASS( klass.c_str() ) ),
Rf_install(".Data"),
data ) ) ;
UNPROTECT(1) ;
return res ;
}
LongVector(int n) : data(R_NilValue) {
SEXP x = PROTECT( Rf_allocVector( VECSXP, n ) ) ;
for( int i=0; i( value ) ;
int lb = internal::get_low_bits( value ) ;
for( int i=0; i
LongVector(int n, ITERATOR start, ITERATOR end) : data(R_NilValue) {
SEXP x = PROTECT( Rf_allocVector( VECSXP, n ) ) ;
int hb, lb ;
for( int i=0; i(*start) ;
lb = Rint64::internal::get_low_bits(*start) ;
SET_VECTOR_ELT( x, i, Rint64::internal::int2(hb,lb) ) ;
}
UNPROTECT(1) ; // x
data = x ;
R_PreserveObject(data) ;
}
~LongVector(){
R_ReleaseObject(data) ;
}
inline LONG get(int i) const {
int* p = INTEGER(VECTOR_ELT(data,i)) ;
return Rint64::internal::get_long( p[0], p[1] ) ;
}
inline void set(int i, LONG x){
int* p = INTEGER(VECTOR_ELT(data,i)) ;
p[0] = Rint64::internal::get_high_bits(x) ;
p[1] = Rint64::internal::get_low_bits(x) ;
}
inline int size() const { return Rf_length(data); }
LongVector sort(bool decreasing) const {
int n = size() ;
std::vector x( n ) ;
for( int i=0; i() ) ;
} else {
std::sort( x.begin(), x.end() ) ;
}
return LongVector( n, x.begin(), x.end() ) ;
}
SEXP is_na(){
int n = size() ;
SEXP res = PROTECT( Rf_allocVector(LGLSXP,n)) ;
int* p ;
int* p_res = INTEGER(res) ;
for( int i=0; i::na_lb(); }
inline int na_hb(){ return internal::long_traits::na_hb(); }
} ;
}
#endif
int64/inst/include/int64/long_traits.h 0000644 0001751 0000144 00000004413 11661703756 017314 0 ustar hornik users // long_traits.h: int64 64 bit integers
//
// Copyright (C) 2011 Romain Francois
// Copyright (C) 2011 Google Inc. All rights reserved.
//
// This file is part of int64.
//
// int64 is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// int64 is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with int64. If not, see .
#ifndef int64_long_traits_h
#define int64_long_traits_h
namespace Rint64{
namespace internal{
template
struct long_traits ;
template<>
struct long_traits{
static inline int64_t min () { return std::numeric_limits::min() + 1 ; }
static inline int64_t max () { return std::numeric_limits::max() ; }
static inline int64_t na () { return std::numeric_limits::min() ; }
static inline int na_hb () { return get_high_bits( std::numeric_limits::min() ); }
static inline int na_lb () { return get_low_bits( std::numeric_limits::min() ); }
} ;
template<>
struct long_traits{
static inline uint64_t min () { return 0 ; }
static inline uint64_t max () { return std::numeric_limits::max() - 1; }
static inline uint64_t na () { return std::numeric_limits::max() ; }
static inline int na_hb () { return get_high_bits( std::numeric_limits::max() ); }
static inline int na_lb () { return get_low_bits( std::numeric_limits::max() ); }
} ;
}
}
#endif
int64/inst/include/int64/int64.h 0000644 0001751 0000144 00000003717 11665656352 015744 0 ustar hornik users // int64.h : 64 bit integers
//
// Copyright (C) 2011 Romain Francois
// Copyright (C) 2011 Google Inc. All rights reserved.
//
// This file is part of int64.
//
// int64 is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// int64 is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with int64. If not, see .
#ifndef int64__int64__h
#define int64__int64__h
namespace Rint64{
namespace internal {
extern bool int64_naflag ;
}
}
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
namespace Rint64{
namespace internal {
template
SEXP new_long(LONG x){
std::string klass = get_class() ;
Rint64::LongVector y(1) ;
y.set(0, x) ;
return y ;
}
template
SEXP new_long_2(LONG x, LONG y){
std::string klass = get_class() ;
Rint64::LongVector z(2) ;
z.set(0, x ) ;
z.set(1, y ) ;
return z ;
}
}
}
#if defined(BUILDING_INT64)
#include
#endif
#include
#include
#include
#include
#endif
int64/inst/include/int64/int2.h 0000644 0001751 0000144 00000002305 11661703756 015641 0 ustar hornik users // routines.h: int64 64 bit integers
//
// Copyright (C) 2011 Romain Francois
// Copyright (C) 2011 Google Inc. All rights reserved.
//
// This file is part of int64.
//
// int64 is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// int64 is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with int64. If not, see .
#ifndef int64_int2_h
#define int64_int2_h
namespace Rint64{
namespace internal{
// we only use this for T=int
template
SEXP int2( T x, T y){
SEXP res = PROTECT( Rf_allocVector(INTSXP, 2) ) ;
int* p = INTEGER(res) ;
p[0] = x;
p[1] = y ;
UNPROTECT(1) ;
return res ;
}
}
}
#endif
int64/inst/include/int64/get_long.h 0000644 0001751 0000144 00000002156 11661703756 016567 0 ustar hornik users // get_long.h : 64 bit integers
//
// Copyright (C) 2011 Romain Francois
// Copyright (C) 2011 Google Inc. All rights reserved.
//
// This file is part of int64.
//
// int64 is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// int64 is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with int64. If not, see .
#ifndef int64__get_long__h
#define int64__get_long__h
namespace Rint64{
namespace internal{
template
inline T get_long( int highbits, int lowbits ){
return ( ( (T) (unsigned int)highbits ) << 32 ) | ( (T) (unsigned int)lowbits ) ;
}
} // namespace internal
} // namespace Rint64
#endif
int64/inst/include/int64/get_class.h 0000644 0001751 0000144 00000002345 11661703756 016735 0 ustar hornik users // get_class.h : 64 bit integers
//
// Copyright (C) 2011 Romain Francois
// Copyright (C) 2011 Google Inc. All rights reserved.
//
// This file is part of int64.
//
// int64 is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// int64 is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with int64. If not, see .
#ifndef int64__get_class__h
#define int64__get_class__h
namespace Rint64{
namespace internal {
template
inline std::string get_class(){ return "" ; }
template <>
inline std::string get_class(){
return "int64" ;
}
template <>
inline std::string get_class(){
return "uint64" ;
}
}
}
#endif
int64/inst/include/int64/get_bits.h 0000644 0001751 0000144 00000002206 11661703756 016565 0 ustar hornik users // get_bits.h : 64 bit integers
//
// Copyright (C) 2011 Romain Francois
// Copyright (C) 2011 Google Inc. All rights reserved.
//
// This file is part of int64.
//
// int64 is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// int64 is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with int64. If not, see .
#ifndef int64__get_bits__h
#define int64__get_bits__h
namespace Rint64{
namespace internal{
template
inline int get_low_bits( T64 x){
return (int)( x & 0x00000000FFFFFFFF ) ;
}
template
inline int get_high_bits( T64 x){
return (int)( x >> 32 ) ;
}
} // namespace internal
} // namespace Rint64
#endif
int64/inst/include/int64/format_binary.h 0000644 0001751 0000144 00000003677 11661703756 017636 0 ustar hornik users // format_binary.h : 64 bit integers
//
// Copyright (C) 2011 Romain Francois
// Copyright (C) 2011 Google Inc. All rights reserved.
//
// This file is part of int64.
//
// int64 is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// int64 is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with int64. If not, see .
#ifndef int64__binary__h
#define int64__binary__h
namespace Rint64{
namespace internal{
template
inline const char* format_binary__impl(T x) {
const int SIZE = sizeof(T)*8 ;
static std::string b( SIZE, '0' ) ;
for (int z = 0; z < SIZE; z++) {
b[SIZE-1-z] = ((x>>z) & 0x1) ? '1' : '0';
}
return b.c_str() ;
}
template <>
inline const char* format_binary__impl(double x){
int64_t* y = (int64_t*)&x ;
return format_binary__impl(*y) ;
}
template
SEXP int64_format_binary_long(SEXP x){
Rint64::LongVector data(x) ;
int n = data.size() ;
SEXP res = PROTECT( Rf_allocVector( STRSXP, n ) ) ;
for( int i=0; i