Make Decimal a subclass of Real and Inexact.

This commit is contained in:
Guido van Rossum 2007-12-10 20:04:04 +00:00
parent 968e68dc71
commit a13f4a1129
3 changed files with 30 additions and 29 deletions

View File

@ -134,6 +134,7 @@ __all__ = [
'setcontext', 'getcontext', 'localcontext' 'setcontext', 'getcontext', 'localcontext'
] ]
import numbers as _numbers
import copy as _copy import copy as _copy
# Rounding # Rounding
@ -509,7 +510,7 @@ def localcontext(ctx=None):
##### Decimal class ####################################################### ##### Decimal class #######################################################
class Decimal(object): class Decimal(_numbers.Real, _numbers.Inexact):
"""Floating point class for decimal arithmetic.""" """Floating point class for decimal arithmetic."""
__slots__ = ('_exp','_int','_sign', '_is_special') __slots__ = ('_exp','_int','_sign', '_is_special')

View File

@ -5,10 +5,10 @@ test_cProfile
ncalls tottime percall cumtime percall filename:lineno(function) ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 1.000 1.000 <string>:1(<module>) 1 0.000 0.000 1.000 1.000 <string>:1(<module>)
2 0.000 0.000 0.000 0.000 io.py:1201(flush) 2 0.000 0.000 0.000 0.000 io.py:1211(flush)
1 0.000 0.000 0.000 0.000 io.py:259(flush) 1 0.000 0.000 0.000 0.000 io.py:269(flush)
1 0.000 0.000 0.000 0.000 io.py:646(closed) 1 0.000 0.000 0.000 0.000 io.py:656(closed)
1 0.000 0.000 0.000 0.000 io.py:864(flush) 1 0.000 0.000 0.000 0.000 io.py:874(flush)
8 0.064 0.008 0.080 0.010 test_cProfile.py:103(subhelper) 8 0.064 0.008 0.080 0.010 test_cProfile.py:103(subhelper)
28 0.028 0.001 0.028 0.001 test_cProfile.py:115(__getattr__) 28 0.028 0.001 0.028 0.001 test_cProfile.py:115(__getattr__)
1 0.270 0.270 1.000 1.000 test_cProfile.py:30(testfunc) 1 0.270 0.270 1.000 1.000 test_cProfile.py:30(testfunc)
@ -30,11 +30,11 @@ test_cProfile
Function called... Function called...
ncalls tottime cumtime ncalls tottime cumtime
<string>:1(<module>) -> 1 0.270 1.000 test_cProfile.py:30(testfunc) <string>:1(<module>) -> 1 0.270 1.000 test_cProfile.py:30(testfunc)
io.py:1201(flush) -> 1 0.000 0.000 io.py:259(flush) io.py:1211(flush) -> 1 0.000 0.000 io.py:269(flush)
1 0.000 0.000 io.py:864(flush) 1 0.000 0.000 io.py:874(flush)
io.py:259(flush) -> io.py:269(flush) ->
io.py:646(closed) -> io.py:656(closed) ->
io.py:864(flush) -> 1 0.000 0.000 io.py:646(closed) io.py:874(flush) -> 1 0.000 0.000 io.py:656(closed)
test_cProfile.py:103(subhelper) -> 16 0.016 0.016 test_cProfile.py:115(__getattr__) test_cProfile.py:103(subhelper) -> 16 0.016 0.016 test_cProfile.py:115(__getattr__)
test_cProfile.py:115(__getattr__) -> test_cProfile.py:115(__getattr__) ->
test_cProfile.py:30(testfunc) -> 1 0.014 0.130 test_cProfile.py:40(factorial) test_cProfile.py:30(testfunc) -> 1 0.014 0.130 test_cProfile.py:40(factorial)
@ -53,7 +53,7 @@ test_cProfile.py:89(helper2_indirect) -> 2 0.006 0.040
test_cProfile.py:93(helper2) -> 8 0.064 0.080 test_cProfile.py:103(subhelper) test_cProfile.py:93(helper2) -> 8 0.064 0.080 test_cProfile.py:103(subhelper)
8 0.000 0.008 {hasattr} 8 0.000 0.008 {hasattr}
{exec} -> 1 0.000 1.000 <string>:1(<module>) {exec} -> 1 0.000 1.000 <string>:1(<module>)
2 0.000 0.000 io.py:1201(flush) 2 0.000 0.000 io.py:1211(flush)
{hasattr} -> 12 0.012 0.012 test_cProfile.py:115(__getattr__) {hasattr} -> 12 0.012 0.012 test_cProfile.py:115(__getattr__)
{method 'append' of 'list' objects} -> {method 'append' of 'list' objects} ->
{method 'disable' of '_lsprof.Profiler' objects} -> {method 'disable' of '_lsprof.Profiler' objects} ->
@ -65,10 +65,10 @@ test_cProfile.py:93(helper2) -> 8 0.064 0.080
Function was called by... Function was called by...
ncalls tottime cumtime ncalls tottime cumtime
<string>:1(<module>) <- 1 0.000 1.000 {exec} <string>:1(<module>) <- 1 0.000 1.000 {exec}
io.py:1201(flush) <- 2 0.000 0.000 {exec} io.py:1211(flush) <- 2 0.000 0.000 {exec}
io.py:259(flush) <- 1 0.000 0.000 io.py:1201(flush) io.py:269(flush) <- 1 0.000 0.000 io.py:1211(flush)
io.py:646(closed) <- 1 0.000 0.000 io.py:864(flush) io.py:656(closed) <- 1 0.000 0.000 io.py:874(flush)
io.py:864(flush) <- 1 0.000 0.000 io.py:1201(flush) io.py:874(flush) <- 1 0.000 0.000 io.py:1211(flush)
test_cProfile.py:103(subhelper) <- 8 0.064 0.080 test_cProfile.py:93(helper2) test_cProfile.py:103(subhelper) <- 8 0.064 0.080 test_cProfile.py:93(helper2)
test_cProfile.py:115(__getattr__) <- 16 0.016 0.016 test_cProfile.py:103(subhelper) test_cProfile.py:115(__getattr__) <- 16 0.016 0.016 test_cProfile.py:103(subhelper)
12 0.012 0.012 {hasattr} 12 0.012 0.012 {hasattr}

View File

@ -10,10 +10,10 @@ test_profile
12 0.000 0.000 0.012 0.001 :0(hasattr) 12 0.000 0.000 0.012 0.001 :0(hasattr)
1 0.000 0.000 0.000 0.000 :0(setprofile) 1 0.000 0.000 0.000 0.000 :0(setprofile)
1 0.000 0.000 1.000 1.000 <string>:1(<module>) 1 0.000 0.000 1.000 1.000 <string>:1(<module>)
2 0.000 0.000 0.000 0.000 io.py:1201(flush) 2 0.000 0.000 0.000 0.000 io.py:1211(flush)
1 0.000 0.000 0.000 0.000 io.py:259(flush) 1 0.000 0.000 0.000 0.000 io.py:269(flush)
1 0.000 0.000 0.000 0.000 io.py:646(closed) 1 0.000 0.000 0.000 0.000 io.py:656(closed)
1 0.000 0.000 0.000 0.000 io.py:864(flush) 1 0.000 0.000 0.000 0.000 io.py:874(flush)
0 0.000 0.000 profile:0(profiler) 0 0.000 0.000 profile:0(profiler)
1 0.000 0.000 1.000 1.000 profile:0(testfunc()) 1 0.000 0.000 1.000 1.000 profile:0(testfunc())
8 0.064 0.008 0.080 0.010 test_profile.py:103(subhelper) 8 0.064 0.008 0.080 0.010 test_profile.py:103(subhelper)
@ -33,15 +33,15 @@ Function called...
:0(append) -> :0(append) ->
:0(exc_info) -> :0(exc_info) ->
:0(exec) -> <string>:1(<module>)(1) 1.000 :0(exec) -> <string>:1(<module>)(1) 1.000
io.py:1201(flush)(2) 0.000 io.py:1211(flush)(2) 0.000
:0(hasattr) -> test_profile.py:115(__getattr__)(12) 0.028 :0(hasattr) -> test_profile.py:115(__getattr__)(12) 0.028
:0(setprofile) -> :0(setprofile) ->
<string>:1(<module>) -> test_profile.py:30(testfunc)(1) 1.000 <string>:1(<module>) -> test_profile.py:30(testfunc)(1) 1.000
io.py:1201(flush) -> io.py:259(flush)(1) 0.000 io.py:1211(flush) -> io.py:269(flush)(1) 0.000
io.py:864(flush)(1) 0.000 io.py:874(flush)(1) 0.000
io.py:259(flush) -> io.py:269(flush) ->
io.py:646(closed) -> io.py:656(closed) ->
io.py:864(flush) -> io.py:646(closed)(1) 0.000 io.py:874(flush) -> io.py:656(closed)(1) 0.000
profile:0(profiler) -> profile:0(testfunc())(1) 1.000 profile:0(profiler) -> profile:0(testfunc())(1) 1.000
profile:0(testfunc()) -> :0(exec)(1) 1.000 profile:0(testfunc()) -> :0(exec)(1) 1.000
:0(setprofile)(1) 0.000 :0(setprofile)(1) 0.000
@ -74,10 +74,10 @@ Function was called by...
test_profile.py:93(helper2)(8) 0.400 test_profile.py:93(helper2)(8) 0.400
:0(setprofile) <- profile:0(testfunc())(1) 1.000 :0(setprofile) <- profile:0(testfunc())(1) 1.000
<string>:1(<module>) <- :0(exec)(1) 1.000 <string>:1(<module>) <- :0(exec)(1) 1.000
io.py:1201(flush) <- :0(exec)(2) 1.000 io.py:1211(flush) <- :0(exec)(2) 1.000
io.py:259(flush) <- io.py:1201(flush)(1) 0.000 io.py:269(flush) <- io.py:1211(flush)(1) 0.000
io.py:646(closed) <- io.py:864(flush)(1) 0.000 io.py:656(closed) <- io.py:874(flush)(1) 0.000
io.py:864(flush) <- io.py:1201(flush)(1) 0.000 io.py:874(flush) <- io.py:1211(flush)(1) 0.000
profile:0(profiler) <- profile:0(profiler) <-
profile:0(testfunc()) <- profile:0(profiler)(1) 0.000 profile:0(testfunc()) <- profile:0(profiler)(1) 0.000
test_profile.py:103(subhelper) <- test_profile.py:93(helper2)(8) 0.400 test_profile.py:103(subhelper) <- test_profile.py:93(helper2)(8) 0.400