Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Kirill Smelkov
cpython
Commits
21378934
Commit
21378934
authored
Dec 04, 2007
by
Facundo Batista
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fma speedup by avoiding to create a Context. Thanks Mark Dickinson.
parent
f714a810
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
16 deletions
+31
-16
Lib/decimal.py
Lib/decimal.py
+31
-16
No files found.
Lib/decimal.py
View file @
21378934
...
...
@@ -1636,24 +1636,39 @@ class Decimal(object):
"""
other
=
_convert_other
(
other
,
raiseit
=
True
)
third
=
_convert_other
(
third
,
raiseit
=
True
)
if
context
is
None
:
context
=
getcontext
()
# do self*other in fresh context with no traps and no rounding
mul_context
=
Context
(
traps
=
[],
flags
=
[],
_rounding_decision
=
NEVER_ROUND
)
product
=
self
.
__mul__
(
other
,
mul_context
)
if
mul_context
.
flags
[
InvalidOperation
]:
# reraise in current context
return
context
.
_raise_error
(
InvalidOperation
,
'invalid multiplication in fma'
,
1
,
product
)
# compute product; raise InvalidOperation if either operand is
# a signaling NaN or if the product is zero times infinity.
if
self
.
_is_special
or
other
.
_is_special
:
if
context
is
None
:
context
=
getcontext
()
if
self
.
_exp
==
'N'
:
return
context
.
_raise_error
(
InvalidOperation
,
'sNaN'
,
1
,
self
)
if
other
.
_exp
==
'N'
:
return
context
.
_raise_error
(
InvalidOperation
,
'sNaN'
,
1
,
other
)
if
self
.
_exp
==
'n'
:
product
=
self
elif
other
.
_exp
==
'n'
:
product
=
other
elif
self
.
_exp
==
'F'
:
if
not
other
:
return
context
.
_raise_error
(
InvalidOperation
,
'INF * 0 in fma'
)
product
=
Infsign
[
self
.
_sign
^
other
.
_sign
]
elif
other
.
_exp
==
'F'
:
if
not
self
:
return
context
.
_raise_error
(
InvalidOperation
,
'0 * INF in fma'
)
product
=
Infsign
[
self
.
_sign
^
other
.
_sign
]
else
:
product
=
_dec_from_triple
(
self
.
_sign
^
other
.
_sign
,
str
(
int
(
self
.
_int
)
*
int
(
other
.
_int
)),
self
.
_exp
+
other
.
_exp
)
ans
=
product
.
__add__
(
third
,
context
)
return
ans
third
=
_convert_other
(
third
,
raiseit
=
True
)
return
product
.
__add__
(
third
,
context
)
def
_power_modulo
(
self
,
other
,
modulo
,
context
=
None
):
"""Three argument version of __pow__"""
...
...
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