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
7819995d
Commit
7819995d
authored
Apr 19, 2016
by
Boxiang Sun
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
let floatNew behavouir like CPython's
parent
2a3b70eb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
53 deletions
+9
-53
src/runtime/float.cpp
src/runtime/float.cpp
+9
-53
No files found.
src/runtime/float.cpp
View file @
7819995d
...
...
@@ -838,59 +838,15 @@ Box* floatNonzero(BoxedFloat* self) {
return
boxBool
(
floatNonzeroUnboxed
(
self
));
}
template
<
ExceptionStyle
S
>
static
BoxedFloat
*
_floatNew
(
Box
*
a
)
noexcept
(
S
==
CAPI
)
{
if
(
a
->
cls
==
float_cls
)
{
return
static_cast
<
BoxedFloat
*>
(
a
);
}
else
if
(
PyInt_Check
(
a
))
{
return
new
BoxedFloat
(
static_cast
<
BoxedInt
*>
(
a
)
->
n
);
}
else
if
(
PyLong_Check
(
a
))
{
double
a_f
=
PyLong_AsDouble
(
a
);
if
(
a_f
==
-
1.0
&&
PyErr_Occurred
())
{
if
(
S
==
CAPI
)
return
NULL
;
else
throwCAPIException
();
}
// Make sure that we're not in an error state when we return a non-NULL value.
assert
(
!
PyErr_Occurred
());
return
new
BoxedFloat
(
a_f
);
}
else
if
(
a
->
cls
==
str_cls
||
a
->
cls
==
unicode_cls
)
{
BoxedFloat
*
res
=
(
BoxedFloat
*
)
PyFloat_FromString
(
a
,
NULL
);
if
(
!
res
)
{
if
(
S
==
CAPI
)
return
NULL
;
template
<
ExceptionStyle
S
>
static
BoxedFloat
*
_floatNew
(
Box
*
x
)
noexcept
(
S
==
CAPI
)
{
Box
*
rtn
;
if
(
PyString_CheckExact
(
x
))
rtn
=
PyFloat_FromString
(
x
,
NULL
);
else
rtn
=
PyNumber_Float
(
x
);
if
(
!
rtn
&&
S
==
CXX
)
throwCAPIException
();
}
return
res
;
}
else
{
static
BoxedString
*
float_str
=
internStringImmortal
(
"__float__"
);
Box
*
r
=
callattrInternal
<
S
,
NOT_REWRITABLE
>
(
a
,
float_str
,
CLASS_ONLY
,
NULL
,
ArgPassSpec
(
0
),
NULL
,
NULL
,
NULL
,
NULL
,
NULL
);
if
(
!
r
)
{
if
(
S
==
CAPI
)
{
if
(
!
PyErr_Occurred
())
PyErr_SetString
(
PyExc_TypeError
,
"float() argument must be a string or a number"
);
return
NULL
;
}
else
{
raiseExcHelper
(
TypeError
,
"float() argument must be a string or a number"
);
}
}
if
(
!
PyFloat_Check
(
r
))
{
if
(
S
==
CAPI
)
{
PyErr_Format
(
TypeError
,
"__float__ returned non-float (type %s)"
,
r
->
cls
->
tp_name
);
return
NULL
;
}
else
raiseExcHelper
(
TypeError
,
"__float__ returned non-float (type %s)"
,
r
->
cls
->
tp_name
);
}
return
static_cast
<
BoxedFloat
*>
(
r
);
}
return
static_cast
<
BoxedFloat
*>
(
rtn
);
}
template
<
ExceptionStyle
S
>
Box
*
floatNew
(
BoxedClass
*
_cls
,
Box
*
a
)
noexcept
(
S
==
CAPI
)
{
...
...
Boxiang Sun
@Daetalus
mentioned in commit
81a372d9
·
Sep 08, 2016
mentioned in commit
81a372d9
mentioned in commit 81a372d968ef47b6b8f5965856a22b2395c175dc
Toggle commit list
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