[Rcpp-commits] r3399 - in pkg/int64: . inst inst/include/int64

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Nov 26 20:44:32 CET 2011


Author: romain
Date: 2011-11-26 20:44:31 +0100 (Sat, 26 Nov 2011)
New Revision: 3399

Modified:
   pkg/int64/ChangeLog
   pkg/int64/inst/NEWS
   pkg/int64/inst/include/int64/math.h
Log:
log10 method, as requested by @hadleywickham

Modified: pkg/int64/ChangeLog
===================================================================
--- pkg/int64/ChangeLog	2011-11-26 18:59:09 UTC (rev 3398)
+++ pkg/int64/ChangeLog	2011-11-26 19:44:31 UTC (rev 3399)
@@ -1,6 +1,6 @@
-2011-11-23  Romain Francois  <romain at r-enthusiasts.com>
+2011-11-26  Romain Francois  <romain at r-enthusiasts.com>
 
-    * R/int64.R: str.[u]int64 as requested by Hadley Wickham
+    * R/int64.R: str and log10 methods for [u]int64 as requested by Hadley Wickham
 
 2011-11-23  Romain Francois  <romain at r-enthusiasts.com>
 

Modified: pkg/int64/inst/NEWS
===================================================================
--- pkg/int64/inst/NEWS	2011-11-26 18:59:09 UTC (rev 3398)
+++ pkg/int64/inst/NEWS	2011-11-26 19:44:31 UTC (rev 3399)
@@ -1,5 +1,11 @@
-1.1.0   2011-yy-zz
+1.2.0   2011-yy-zz
 
+    o   str methods for [u]int64 classes. Requested by @hadleywickham
+    
+    o   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
 

Modified: pkg/int64/inst/include/int64/math.h
===================================================================
--- pkg/int64/inst/include/int64/math.h	2011-11-26 18:59:09 UTC (rev 3398)
+++ pkg/int64/inst/include/int64/math.h	2011-11-26 19:44:31 UTC (rev 3399)
@@ -140,6 +140,25 @@
     return res ;
 }
 
+template <typename LONG>
+SEXP int64_log10( SEXP x ){
+    Rint64::LongVector<LONG> data(x) ;
+    int n = data.size() ;
+    const LONG na = long_traits<LONG>::na() ;
+    SEXP res = PROTECT( Rf_allocVector( REALSXP, n ) ) ;
+    double* p_res = REAL(res) ;
+    LONG tmp; 
+    for(int i=0; i<n; i++){
+        tmp = data.get(i) ;
+        if( tmp == na ) {
+            p_res[i] = NA_REAL;
+        } else {
+            p_res[i] = (double) log10( (long double)data.get(i) ) ;   
+        }
+    }
+    UNPROTECT(1) ; // res
+    return res ;
+}
 
 template <typename LONG>
 SEXP math( const char* op, SEXP x ){
@@ -160,6 +179,8 @@
         return cumprod<LONG>( x ) ;
     } else if( !strncmp( op, "cumsum", 6 ) ){
         return cumsum<LONG>( x ) ;   
+    } else if( !strncmp( op, "log10", 5 ) ){
+        return int64_log10<LONG>( x ) ;   
     }
     
     Rf_error( "generic not implemented" );



More information about the Rcpp-commits mailing list