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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Nov 16 10:43:11 CET 2011


Author: romain
Date: 2011-11-16 10:43:11 +0100 (Wed, 16 Nov 2011)
New Revision: 3363

Modified:
   pkg/int64/inst/include/int64/LongVector.h
   pkg/int64/inst/include/int64/math.h
   pkg/int64/inst/include/int64/read_string.h
   pkg/int64/inst/include/int64/summary.h
Log:
more overflow handling

Modified: pkg/int64/inst/include/int64/LongVector.h
===================================================================
--- pkg/int64/inst/include/int64/LongVector.h	2011-11-16 09:33:05 UTC (rev 3362)
+++ pkg/int64/inst/include/int64/LongVector.h	2011-11-16 09:43:11 UTC (rev 3363)
@@ -121,6 +121,7 @@
                     case STRSXP:
                         {
                             int n = Rf_length(x) ;
+                            int64::internal::int64_naflag = false ;
                             SEXP y = PROTECT( Rf_allocVector( VECSXP, n ) ) ;
                             int hb, lb ;
                             LONG tmp ;
@@ -139,6 +140,9 @@
                             UNPROTECT(1) ; // y
                             data = y ;
                             R_PreserveObject(data) ;  
+                            if( int64::internal::int64_naflag ) {
+                                Rf_warning( "NA introduced by overflow" ) ;
+                            }
                             break ;        
                         }
                     default:

Modified: pkg/int64/inst/include/int64/math.h
===================================================================
--- pkg/int64/inst/include/int64/math.h	2011-11-16 09:33:05 UTC (rev 3362)
+++ pkg/int64/inst/include/int64/math.h	2011-11-16 09:43:11 UTC (rev 3363)
@@ -107,12 +107,15 @@
     int64::LongVector<LONG> res(n, na) ;
     LONG prod = data.get(0) ;
     res.set( 0, prod) ;
-    
+    int64_naflag = false ;
     for( int i=1; i<n; i++){
         prod = times<LONG>( prod, data.get(i) );
         if( prod == na ) break ;
         res.set( i, prod ) ;
     }
+    if( int64_naflag ) {
+        Rf_warning( "NA introduced by overflow" )   
+    }
     return res ;
 }
 
@@ -124,12 +127,16 @@
     int64::LongVector<LONG> res(x) ;
     LONG prod = data.get(0) ;
     res.set( 0, prod) ;
+    int64_naflag = false ;
     
     for( int i=1; i<n; i++){
         prod = plus<LONG>( prod, data.get(i) );
         if( prod == na ) break ;
         res.set( i, prod ) ;
     }
+    if( int64_naflag ) {
+        Rf_warning( "NA introduced by overflow" )   
+    }
     return res ;
 }
 

Modified: pkg/int64/inst/include/int64/read_string.h
===================================================================
--- pkg/int64/inst/include/int64/read_string.h	2011-11-16 09:33:05 UTC (rev 3362)
+++ pkg/int64/inst/include/int64/read_string.h	2011-11-16 09:43:11 UTC (rev 3363)
@@ -28,7 +28,10 @@
     inline int64_t read_string<int64_t>(const char* s ){
         errno = 0 ;
         int64_t res = strtoll( s, NULL, 0 ) ;
-        if( errno == ERANGE ) res = int64::LongVector<int64_t>::na ;
+        if( errno == ERANGE ) {
+            res = int64::LongVector<int64_t>::na ;
+            int64_naflag = true ;
+        }
         return res ;
     }
         
@@ -36,7 +39,10 @@
     inline uint64_t read_string<uint64_t>(const char* s){
         errno = 0 ;
         uint64_t res = strtoull( s, NULL, 0 ) ;
-        if( errno == ERANGE ) res = int64::LongVector<uint64_t>::na ;
+        if( errno == ERANGE ) {
+            res = int64::LongVector<uint64_t>::na ;
+            int64_naflag = true ;
+        }
         return res ;
     } 
         

Modified: pkg/int64/inst/include/int64/summary.h
===================================================================
--- pkg/int64/inst/include/int64/summary.h	2011-11-16 09:33:05 UTC (rev 3362)
+++ pkg/int64/inst/include/int64/summary.h	2011-11-16 09:43:11 UTC (rev 3363)
@@ -84,11 +84,12 @@
     LONG res = data.get(0) ;
     if( res == na ) return int64::internal::new_long<LONG>( na ) ;
     int n = data.size() ;
-    
+    int64_naflag = false ;
     for( int i=1; i<n; i++){
         res = times<LONG>( res, data.get(i) );
         if( res == na) break ;
     }
+    if( int64_naflag ) Rf_warning( "NAs introduced by overflow" ) ;
     return int64::internal::new_long<LONG>( res ) ;
 }
 
@@ -98,11 +99,14 @@
     LONG res = data.get(0) ;
     if( res == na ) return int64::internal::new_long<LONG>( na ) ;
     int n = data.size() ;
+    int64_naflag = false ;
     
     for( int i=1; i<n; i++){
         res = plus<LONG>( res, data.get(i) ) ;
         if( res == na ) break ;
     }
+    if( int64_naflag ) Rf_warning( "NAs introduced by overflow" ) ;
+    
     return int64::internal::new_long<LONG>( res ) ;
 }
 



More information about the Rcpp-commits mailing list