[Rcpp-commits] r3326 - pkg/int64/inst/include/int64

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Nov 12 11:20:52 CET 2011


Author: romain
Date: 2011-11-12 11:20:52 +0100 (Sat, 12 Nov 2011)
New Revision: 3326

Modified:
   pkg/int64/inst/include/int64/compare.h
Log:
comparison operators with NA handling

Modified: pkg/int64/inst/include/int64/compare.h
===================================================================
--- pkg/int64/inst/include/int64/compare.h	2011-11-12 10:18:40 UTC (rev 3325)
+++ pkg/int64/inst/include/int64/compare.h	2011-11-12 10:20:52 UTC (rev 3326)
@@ -33,6 +33,7 @@
         
 template <typename LONG, bool Fun(LONG x1, LONG x2)>
 SEXP compare_long_long(SEXP e1, SEXP e2){
+    const LONG na = int64::LongVector<LONG>::na ;
     int64::LongVector<LONG> x1( e1 ) ;
     int64::LongVector<LONG> x2( e2 ) ;
     
@@ -45,22 +46,22 @@
     
     if( n1 == n2 ){
         for( i=0; i<n1; i++){
-            p_res[i] = Fun(x1.get(i), x2.get(i)) ;
+            p_res[i] = ( x1 == na || x2 == na) ? na : Fun(x1.get(i), x2.get(i)) ;
         }
     } else if( n1 == 1 ){
         tmp = x1.get(i) ;
         for( i=0; i<n2; i++){
-            p_res[i] = Fun(tmp,x2.get(i)) ;
+            p_res[i] = ( x1 == na || x2 == na) ? na : Fun(tmp,x2.get(i)) ;
         }
     } else if( n2 == 1) {
         tmp = x2.get(i) ;
         for( i=0; i<n1; i++){
-            p_res[i] = Fun(x1.get(i),tmp) ;
+            p_res[i] = ( x1 == na || x2 == na) ? na : Fun(x1.get(i),tmp) ;
         }
     } else {
         // recycling
         for (i=i1=i2=0; i<n; i1 = (++i1 == n1) ? 0 : i1, i2 = (++i2 == n2) ? 0 : i2, ++i){
-           p_res[i] = Fun(x1.get(i1), x2.get(i2)) ;
+           p_res[i] = ( x1 == na || x2 == na) ? na : Fun(x1.get(i1), x2.get(i2)) ;
         }
     }
     UNPROTECT(1) ; // res



More information about the Rcpp-commits mailing list