[Rcpp-commits] r1103 - pkg/Rcpp/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Apr 22 00:37:54 CEST 2010


Author: romain
Date: 2010-04-22 00:37:54 +0200 (Thu, 22 Apr 2010)
New Revision: 1103

Modified:
   pkg/Rcpp/src/RcppDatetime.cpp
Log:
using Rf_fround

Modified: pkg/Rcpp/src/RcppDatetime.cpp
===================================================================
--- pkg/Rcpp/src/RcppDatetime.cpp	2010-04-21 22:34:49 UTC (rev 1102)
+++ pkg/Rcpp/src/RcppDatetime.cpp	2010-04-21 22:37:54 UTC (rev 1103)
@@ -22,21 +22,8 @@
 
 #include <RcppDatetime.h>
 #include <time.h> // for strftime
+#include <Rmath.h> // for Rf_fround
 
-static int rcpp_round( double x ) { // needed as C++ has no round which trips up Solaris
-    int y = static_cast<int>(x);
-    double diff = x - y ;
-    if (diff >= 0.5 ) y++ ; 
-    return y ;
-}
-
-// for what it is worth, a double round(double) can defined as
-//    double round(double r) {
-//      return (r > 0.0) ? floor(r + 0.5) : ceil(r - 0.5);
-//    }
-// see e.g. http://stackoverflow.com/questions/485525/round-for-float-in-c
-// and in particular the answer by Johannes Schaub
-
 RcppDatetime::RcppDatetime(void) : m_d(0), 
 				   m_parsed(false), 
 				   m_us(0) { 
@@ -59,7 +46,7 @@
     m_tm = *localtime(&tt);			// parse time type into time structure 
 
     // m_us is fractional (micro)secs is diff. between (fractional) m_d and m_tm
-    m_us = rcpp_round( (m_d - tt) * 1.0e6);	
+    m_us = static_cast<int>( ::Rf_fround( (m_d - tt) * 1.0e6), 0.0 );	
 
     m_parsed = true;				// and note that we parsed the time type
 }



More information about the Rcpp-commits mailing list