Skip to content

Commit 4ae2020

Browse files
committed
Adds Arg(X) sugar function (closes #625)
1 parent 8ac38d7 commit 4ae2020

File tree

5 files changed

+12
-0
lines changed

5 files changed

+12
-0
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2017-01-07 James J Balamuta <[email protected]>
2+
3+
* inst/include/Rcpp/sugar/functions/complex.h: Added Arg() function
4+
* inst/unitTests/runit.sugar.R: Added Arg() unit test to complex list
5+
* inst/unitTests/cpp/sugar.cpp: Idem
6+
17
2017-01-06 Dirk Eddelbuettel <[email protected]>
28

39
* DESCRIPTION (Version, Date): Mark new minor version

inst/NEWS.Rd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
\itemize{
1919
\item Added new Sugar function \code{sample()} (Nathan Russell in
2020
\ghpr{610}).
21+
\item Added new Sugar function \code{Arg()} (James Balamuta in
22+
\ghpr{626} addressing \ghit{625}).
2123
}
2224
\item Changes in Rcpp unit tests
2325
\itemize{

inst/include/Rcpp/sugar/functions/complex.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ inline double complex__Re( Rcomplex x){ return x.r ; }
6868
y.i = -x.i ;
6969
return y ;
7070
}
71+
inline double complex__Arg( Rcomplex x ){ return ::atan2(x.i, x.r); }
7172
// TODO: this does not use HAVE_C99_COMPLEX as in R, perhaps it should
7273
inline Rcomplex complex__exp( Rcomplex x){
7374
Rcomplex y ;
@@ -249,6 +250,7 @@ inline Rcomplex complex__tanh(Rcomplex z)
249250
RCPP_SUGAR_COMPLEX( Re, double )
250251
RCPP_SUGAR_COMPLEX( Im, double )
251252
RCPP_SUGAR_COMPLEX( Mod, double )
253+
RCPP_SUGAR_COMPLEX( Arg, double )
252254
RCPP_SUGAR_COMPLEX( Conj, Rcomplex )
253255
RCPP_SUGAR_COMPLEX( exp, Rcomplex )
254256
RCPP_SUGAR_COMPLEX( log, Rcomplex )

inst/unitTests/cpp/sugar.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ List runit_complex( ComplexVector cx ){
402402
_["Im"] = Im( cx ),
403403
_["Conj"] = Conj( cx ),
404404
_["Mod"] = Mod( cx ),
405+
_["Arg"] = Arg( cx ),
405406
_["exp"] = exp( cx ),
406407
_["log"] = log( cx ),
407408
_["sqrt"] = sqrt( cx ),

inst/unitTests/runit.sugar.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ if (.runThisTest) {
441441
Im = Im(x),
442442
Conj = Conj(x),
443443
Mod = Mod(x),
444+
Arg = Arg(x),
444445
exp = exp(x),
445446
log = log(x),
446447
sqrt = sqrt(x),

0 commit comments

Comments
 (0)