Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
grumpy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
grumpy
Commits
68416710
Commit
68416710
authored
Apr 24, 2017
by
Dong-hee Na
Committed by
Dylan Trotter
Apr 23, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement complex hash. (#293)
parent
0def2c25
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
0 deletions
+25
-0
runtime/complex.go
runtime/complex.go
+10
-0
runtime/complex_test.go
runtime/complex_test.go
+15
-0
No files found.
runtime/complex.go
View file @
68416710
...
@@ -72,6 +72,7 @@ func initComplexType(dict map[string]*Object) {
...
@@ -72,6 +72,7 @@ func initComplexType(dict map[string]*Object) {
ComplexType
.
slots
.
Eq
=
&
binaryOpSlot
{
complexEq
}
ComplexType
.
slots
.
Eq
=
&
binaryOpSlot
{
complexEq
}
ComplexType
.
slots
.
GE
=
&
binaryOpSlot
{
complexCompareNotSupported
}
ComplexType
.
slots
.
GE
=
&
binaryOpSlot
{
complexCompareNotSupported
}
ComplexType
.
slots
.
GT
=
&
binaryOpSlot
{
complexCompareNotSupported
}
ComplexType
.
slots
.
GT
=
&
binaryOpSlot
{
complexCompareNotSupported
}
ComplexType
.
slots
.
Hash
=
&
unaryOpSlot
{
complexHash
}
ComplexType
.
slots
.
LE
=
&
binaryOpSlot
{
complexCompareNotSupported
}
ComplexType
.
slots
.
LE
=
&
binaryOpSlot
{
complexCompareNotSupported
}
ComplexType
.
slots
.
LT
=
&
binaryOpSlot
{
complexCompareNotSupported
}
ComplexType
.
slots
.
LT
=
&
binaryOpSlot
{
complexCompareNotSupported
}
ComplexType
.
slots
.
NE
=
&
binaryOpSlot
{
complexNE
}
ComplexType
.
slots
.
NE
=
&
binaryOpSlot
{
complexNE
}
...
@@ -130,3 +131,12 @@ func complexCoerce(o *Object) (complex128, bool) {
...
@@ -130,3 +131,12 @@ func complexCoerce(o *Object) (complex128, bool) {
}
}
return
complex
(
floatO
,
0.0
),
true
return
complex
(
floatO
,
0.0
),
true
}
}
func
complexHash
(
f
*
Frame
,
o
*
Object
)
(
*
Object
,
*
BaseException
)
{
v
:=
toComplexUnsafe
(
o
)
.
Value
()
hashCombined
:=
hashFloat
(
real
(
v
))
+
1000003
*
hashFloat
(
imag
(
v
))
if
hashCombined
==
-
1
{
hashCombined
=
-
2
}
return
NewInt
(
hashCombined
)
.
ToObject
(),
nil
}
runtime/complex_test.go
View file @
68416710
...
@@ -93,3 +93,18 @@ func TestComplexRepr(t *testing.T) {
...
@@ -93,3 +93,18 @@ func TestComplexRepr(t *testing.T) {
}
}
}
}
}
}
func
TestComplexHash
(
t
*
testing
.
T
)
{
cases
:=
[]
invokeTestCase
{
{
args
:
wrapArgs
(
complex
(
0.0
,
0.0
)),
want
:
NewInt
(
0
)
.
ToObject
()},
{
args
:
wrapArgs
(
complex
(
0.0
,
1.0
)),
want
:
NewInt
(
1000003
)
.
ToObject
()},
{
args
:
wrapArgs
(
complex
(
1.0
,
0.0
)),
want
:
NewInt
(
1
)
.
ToObject
()},
{
args
:
wrapArgs
(
complex
(
3.1
,
-
4.2
)),
want
:
NewInt
(
-
1556830019620134
)
.
ToObject
()},
{
args
:
wrapArgs
(
complex
(
3.1
,
4.2
)),
want
:
NewInt
(
1557030815934348
)
.
ToObject
()},
}
for
_
,
cas
:=
range
cases
{
if
err
:=
runInvokeTestCase
(
wrapFuncForTest
(
complexHash
),
&
cas
);
err
!=
""
{
t
.
Error
(
err
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment