The R Project SVN R

Rev

Rev 42034 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 42034 Rev 49068
Line 1... Line 1...
1
### Tests of complex arithemetic.
1
### Tests of complex arithemetic.
2
 
2
 
-
 
3
Meps <- .Machine$double.eps
3
## complex
4
## complex
4
z <- 0i ^ (-3:3)
5
z <- 0i ^ (-3:3)
5
stopifnot(Re(z) == 0 ^ (-3:3))
6
stopifnot(Re(z) == 0 ^ (-3:3))
6
set.seed(123)
7
set.seed(123)
7
z <- complex(real = rnorm(100), imag = rnorm(100))
8
z <- complex(real = rnorm(100), imag = rnorm(100))
8
stopifnot(Mod ( 1 -  sin(z) / ( (exp(1i*z)-exp(-1i*z))/(2*1i) ))
9
stopifnot(Mod ( 1 -  sin(z) / ( (exp(1i*z)-exp(-1i*z))/(2*1i) )) < 20 * Meps)
9
	  < 20 * .Machine$double.eps)
-
 
10
## end of moved from complex.Rd
10
## end of moved from complex.Rd
11
 
11
 
12
 
12
 
13
## powers, including complex ones
13
## powers, including complex ones
14
a <- -4:12
14
a <- -4:12
15
m <- outer(a +0i, b <- seq(-.5,2, by=.5), "^")
15
m <- outer(a +0i, b <- seq(-.5,2, by=.5), "^")
16
dimnames(m) <- list(paste(a), "^" = sapply(b,format))
16
dimnames(m) <- list(paste(a), "^" = sapply(b,format))
17
round(m,3)
17
round(m,3)
18
 
-
 
-
 
18
stopifnot(m[,as.character(0:2)] == cbind(1,a,a*a),
-
 
19
                                        # latter were only approximate
-
 
20
          all.equal(unname(m[,"0.5"]),
-
 
21
                    sqrt(abs(a))*ifelse(a < 0, 1i, 1),
-
 
22
                    tol= 20*Meps))
19
## fft():
23
## fft():
20
for(n in 1:30) cat("\nn=",n,":", round(fft(1:n), 8),"\n")
24
for(n in 1:30) cat("\nn=",n,":", round(fft(1:n), 8),"\n")
21
 
25
 
22
 
26
 
23
## Complex Trig.:
27
## Complex Trig.:
24
Meps <- .Machine$double.eps
-
 
25
abs(Im(cos(acos(1i))) -	 1) < 2*Meps
28
abs(Im(cos(acos(1i))) -	 1) < 2*Meps
26
abs(Im(sin(asin(1i))) -	 1) < 2*Meps
29
abs(Im(sin(asin(1i))) -	 1) < 2*Meps
27
##P (1 - Im(sin(asin(Ii))))/Meps
30
##P (1 - Im(sin(asin(Ii))))/Meps
28
##P (1 - Im(cos(acos(Ii))))/Meps
31
##P (1 - Im(cos(acos(Ii))))/Meps
29
abs(Im(asin(sin(1i))) -	 1) < 2*Meps
32
abs(Im(asin(sin(1i))) -	 1) < 2*Meps
Line 42... Line 45...
42
all(abs(Isi-1) < 100* Meps)
45
all(abs(Isi-1) < 100* Meps)
43
##P table(2*abs(Isi-1)	/ Meps)
46
##P table(2*abs(Isi-1)	/ Meps)
44
 
47
 
45
 
48
 
46
## polyroot():
49
## polyroot():
47
all(abs(1 + polyroot(choose(8, 0:8))) < 1e-10)# maybe smaller..
50
stopifnot(abs(1 + polyroot(choose(8, 0:8))) < 1e-10)# maybe smaller..
48
 
51
 
49
 
52
 
50
## PR#7781
53
## PR#7781
51
## This is not as given by e.g. glibc on AMD64
54
## This is not as given by e.g. glibc on AMD64
52
(z <- tan(1+1000i)) # 0+1i from R's own code.
55
(z <- tan(1+1000i)) # 0+1i from R's own code.