[Rcpp-commits] r1099 - pkg/Rcpp/src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Apr 21 23:10:49 CEST 2010
Author: edd
Date: 2010-04-21 23:10:49 +0200 (Wed, 21 Apr 2010)
New Revision: 1099
Modified:
pkg/Rcpp/src/RcppDatetime.cpp
Log:
added some comment around round()
Modified: pkg/Rcpp/src/RcppDatetime.cpp
===================================================================
--- pkg/Rcpp/src/RcppDatetime.cpp 2010-04-21 20:39:11 UTC (rev 1098)
+++ pkg/Rcpp/src/RcppDatetime.cpp 2010-04-21 21:10:49 UTC (rev 1099)
@@ -3,6 +3,7 @@
// RcppDatetime.h: Rcpp R/C++ interface class library -- Datetime type support
//
// Copyright (C) 2008 - 2009 Dirk Eddelbuettel
+// Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois
//
// This file is part of Rcpp.
//
@@ -22,13 +23,20 @@
#include <RcppDatetime.h>
#include <time.h> // for strftime
-static int rcpp_round( double x ){
- int y = static_cast<int>(x);
- double diff = x - y ;
- if( diff >= 0.5 ) y++ ;
- return y ;
+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) {
More information about the Rcpp-commits
mailing list