[Rcpp-commits] r1630 - pkg/Rcpp/inst/doc/Rcpp-sugar

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Jun 19 17:38:30 CEST 2010


Author: romain
Date: 2010-06-19 17:38:30 +0200 (Sat, 19 Jun 2010)
New Revision: 1630

Modified:
   pkg/Rcpp/inst/doc/Rcpp-sugar/Rcpp-sugar.Rnw
Log:
collapse operators

Modified: pkg/Rcpp/inst/doc/Rcpp-sugar/Rcpp-sugar.Rnw
===================================================================
--- pkg/Rcpp/inst/doc/Rcpp-sugar/Rcpp-sugar.Rnw	2010-06-19 14:17:30 UTC (rev 1629)
+++ pkg/Rcpp/inst/doc/Rcpp-sugar/Rcpp-sugar.Rnw	2010-06-19 15:38:30 UTC (rev 1630)
@@ -125,90 +125,40 @@
 
 \subsection{binary arithmetic operators}
 
-\subsubsection{operator+}
+\sugar~defines the usual binary arithmetic operators : \texttt{+}, \texttt{-},
+\texttt{*}, \texttt{/}. 
 
-The \texttt{operator+} is used to add two \sugar~expressions of the same
-size or one \sugar~expression with a single value of the appropriate type.
-
 <<lang=cpp>>=
 // two numeric vectors of the same size
 NumericVector x ;
 NumericVector y ;
 
-// two vectors
+// expressions involving two vectors
 NumericVector res = x + y ;
-
-// one vector, one single value
-NumericVector res = x + 2.0 ;
-NumericVector res = 2.0 + x;
-
-// two expressions
-NumericVector res = x * y + y / 2.0 ;
-@
-
-\subsubsection{operator-}
-
-The \texttt{operator-} is used to substract two \sugar~expressions of the same
-size or one \sugar~expression with a single value of the appropriate type.
-
-<<lang=cpp>>=
-// two numeric vectors of the same size
-NumericVector x ;
-NumericVector y ;
-
-// two vectors
 NumericVector res = x - y ;
+NumericVector res = x * y ;
+NumericVector res = x / y ;
 
 // one vector, one single value
-NumericVector res = x - 2.0 ;
+NumericVector res = x + 2.0 ;
 NumericVector res = 2.0 - x;
+NumericVector res = y * 2.0 ;
+NumericVector res = 2.0 / y;
 
 // two expressions
-NumericVector res = x * y - y / 2.0 ;
-@
-
-\subsubsection{operator*}
-
-The \texttt{operator*} is used to multiply two \sugar~expressions of the same
-size or one \sugar~expression with a single value of the appropriate type.
-
-<<lang=cpp>>=
-// two numeric vectors of the same size
-NumericVector x ;
-NumericVector y ;
-
-// two vectors
-NumericVector res = x * y ;
-
-// one vector, one single value
-NumericVector res = x * 2.0 ;
-NumericVector res = 2.0 * x;
-
-// two expressions
+NumericVector res = x * y + y / 2.0 ;
 NumericVector res = x * ( y - 2.0 ) ;
+NumericVector res = x / ( y * y ) ;
 @
 
-\subsubsection{operator/}
+The left hand side (lhs) and the right hand side (rhs) of each binary 
+arithmetic expression must be of the same type (for example they should be both
+\texttt{numeric} expressions). 
 
-The \texttt{operator*} is used to divide two \sugar~expressions of the same
-size or one \sugar~expression with a single value of the appropriate type.
+The lhs and the rhs can either have the same size or one of them could 
+be a primitive value of the appropriate type, for example adding a 
+\texttt{NumericVector} and a \texttt{double}. 
 
-<<lang=cpp>>=
-// two numeric vectors of the same size
-NumericVector x ;
-NumericVector y ;
-
-// two vectors
-NumericVector res = x / y ;
-
-// one vector, one single value
-NumericVector res = x / 2.0 ;
-NumericVector res = 2.0 / x;
-
-// two expressions
-NumericVector res = x / ( y * y ) ;
-@
-
 \subsection{binary logical operators}
 
 \subsubsection{operator<}



More information about the Rcpp-commits mailing list