File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change 4
4
5
5
package slices
6
6
7
- import "fmt"
7
+ import (
8
+ "fmt"
9
+ "math/cmplx"
10
+ )
8
11
9
12
func IntSum (s []int ) int {
10
13
sum := 0
@@ -28,6 +31,8 @@ type SliceInt16 []int16
28
31
type SliceInt32 []int32
29
32
type SliceInt64 []int64
30
33
34
+ type SliceComplex []complex128
35
+
31
36
type SliceIface []interface {}
32
37
33
38
type S struct {
@@ -47,3 +52,11 @@ func PrintSSlice(ss []*S) {
47
52
func PrintS (s * S ) {
48
53
fmt .Printf ("%v\n " , s .Name )
49
54
}
55
+
56
+ func CmplxSqrt (arr SliceComplex ) SliceComplex {
57
+ res := make ([]complex128 , len (arr ))
58
+ for i , el := range arr {
59
+ res [i ] = cmplx .Sqrt (el )
60
+ }
61
+ return res
62
+ }
Original file line number Diff line number Diff line change 3
3
# license that can be found in the LICENSE file.
4
4
5
5
from __future__ import print_function
6
+ import math
7
+ import random
6
8
import slices , go
7
9
8
10
a = [1 ,2 ,3 ,4 ]
35
37
slices .PrintS (ss [0 ])
36
38
slices .PrintS (ss [1 ])
37
39
40
+ cmplx = slices .SliceComplex ([(random .random () + random .random () * 1j ) for _ in range (16 )])
41
+ sqrts = slices .CmplxSqrt (cmplx )
42
+ for root , orig in zip (sqrts , cmplx ):
43
+ root_squared = root * root
44
+ assert math .isclose (root_squared .real , orig .real )
45
+ assert math .isclose (root_squared .imag , orig .imag )
46
+
38
47
print ("OK" )
You can’t perform that action at this time.
0 commit comments