Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
4ba2dfed
Commit
4ba2dfed
authored
Jul 20, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #725 from kmod/neg_zero
Cache floats based on their bits, not their value
parents
1b7a412c
00852137
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
4 deletions
+18
-4
src/core/ast.cpp
src/core/ast.cpp
+2
-0
src/runtime/types.cpp
src/runtime/types.cpp
+9
-2
src/runtime/types.h
src/runtime/types.h
+2
-2
test/tests/float.py
test/tests/float.py
+5
-0
No files found.
src/core/ast.cpp
View file @
4ba2dfed
...
...
@@ -1860,7 +1860,9 @@ bool PrintVisitor::visit_unaryop(AST_UnaryOp* node) {
RELEASE_ASSERT
(
0
,
"%s"
,
getOpName
(
node
->
op_type
)
->
c_str
());
break
;
}
printf
(
"("
);
node
->
operand
->
accept
(
this
);
printf
(
")"
);
return
true
;
}
...
...
src/runtime/types.cpp
View file @
4ba2dfed
...
...
@@ -495,15 +495,22 @@ BoxedInt* BoxedModule::getIntConstant(int64_t n) {
return
r
;
}
static
int64_t
getDoubleBits
(
double
d
)
{
int64_t
rtn
;
static_assert
(
sizeof
(
rtn
)
==
sizeof
(
d
),
""
);
memcpy
(
&
rtn
,
&
d
,
sizeof
(
d
));
return
rtn
;
}
BoxedFloat
*
BoxedModule
::
getFloatConstant
(
double
d
)
{
BoxedFloat
*&
r
=
float_constants
[
d
];
BoxedFloat
*&
r
=
float_constants
[
getDoubleBits
(
d
)
];
if
(
!
r
)
r
=
static_cast
<
BoxedFloat
*>
(
boxFloat
(
d
));
return
r
;
}
Box
*
BoxedModule
::
getPureImaginaryConstant
(
double
d
)
{
Box
*&
r
=
imaginary_constants
[
d
];
Box
*&
r
=
imaginary_constants
[
getDoubleBits
(
d
)
];
if
(
!
r
)
r
=
createPureImaginary
(
d
);
return
r
;
...
...
src/runtime/types.h
View file @
4ba2dfed
...
...
@@ -856,8 +856,8 @@ private:
ContiguousMap
<
int64_t
,
BoxedInt
*
,
std
::
unordered_map
<
int64_t
,
int
>>
int_constants
;
// I'm not sure how well it works to use doubles as hashtable keys; thankfully
// it's not a big deal if we get misses.
ContiguousMap
<
double
,
BoxedFloat
*
,
std
::
unordered_map
<
double
,
int
>>
float_constants
;
ContiguousMap
<
double
,
Box
*
,
std
::
unordered_map
<
double
,
int
>>
imaginary_constants
;
ContiguousMap
<
int64_t
,
BoxedFloat
*
,
std
::
unordered_map
<
int64_t
,
int
>>
float_constants
;
ContiguousMap
<
int64_t
,
Box
*
,
std
::
unordered_map
<
int64_t
,
int
>>
imaginary_constants
;
ContiguousMap
<
llvm
::
StringRef
,
Box
*
,
llvm
::
StringMap
<
int
>>
long_constants
;
public:
...
...
test/tests/float.py
View file @
4ba2dfed
...
...
@@ -88,3 +88,8 @@ try:
float
(
-
l
)
except
OverflowError
as
e
:
print
e
.
message
print
0.0
print
-
0.0
print
-
(
0.0
)
print
-
(
-
0.0
)
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