[Rcpp-commits] r2017 - pkg/Rcpp/inst/include/Rcpp/stats/random

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Aug 15 14:01:29 CEST 2010


Author: romain
Date: 2010-08-15 14:01:29 +0200 (Sun, 15 Aug 2010)
New Revision: 2017

Modified:
   pkg/Rcpp/inst/include/Rcpp/stats/random/rnorm.h
Log:
compile time handling of default for rnorm

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rnorm.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rnorm.h	2010-08-15 11:59:09 UTC (rev 2016)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rnorm.h	2010-08-15 12:01:29 UTC (rev 2017)
@@ -72,7 +72,7 @@
 
 } // stats
 
-inline NumericVector rnorm( int n, double mean = 0.0, double sd = 1.0 ){
+inline NumericVector rnorm( int n, double mean, double sd){
 	if (ISNAN(mean) || !R_FINITE(sd) || sd < 0.){
 		// TODO: R also throws a warning in that case, should we ?
 		return NumericVector( n, R_NaN ) ;
@@ -94,6 +94,26 @@
 	}
 }
 
+inline NumericVector rnorm( int n, double mean /*, double sd [=1.0] */ ){
+	if (ISNAN(mean) ){
+		// TODO: R also throws a warning in that case, should we ?
+		return NumericVector( n, R_NaN ) ;
+	}  else if ( !R_FINITE(mean)){
+		return NumericVector( n, mean ) ;
+	} else {
+		bool mean0 = mean == 0.0 ;
+		if( mean0 ){
+			return NumericVector( n, norm_rand ) ;
+		} else {
+			return NumericVector( n, stats::NormGenerator__sd1( mean ) );
+		}
+	}
+}
+
+inline NumericVector rnorm( int n /*, double mean [=0.0], double sd [=1.0] */ ){
+	return NumericVector( n, norm_rand ) ;
+}
+
 } // Rcpp
 
 #endif



More information about the Rcpp-commits mailing list