[Python-3000-checkins] r58223 - in python/branches/py3k-importlib: Doc/c-api/concrete.rst Doc/library/cgi.rst Doc/library/collections.rst Doc/library/decimal.rst Doc/library/fileinput.rst Doc/library/functions.rst Doc/library/hashlib.rst Doc/library/operator.rst Doc/library/os.rst Doc/library/simplexmlrpcserver.rst Doc/library/ssl.rst Doc/library/stdtypes.rst Doc/library/undoc.rst Doc/reference/index.rst Doc/reference/simple_stmts.rst Doc/tutorial/inputoutput.rst Doc/whatsnew/2.5.rst Doc/whatsnew/2.6.rst Lib/cgi.py Lib/collections.py Lib/ctypes/test/test_cfuncs.py Lib/ctypes/test/test_functions.py Lib/ctypes/util.py Lib/decimal.py Lib/distutils/command/build_scripts.py Lib/httplib.py Lib/imaplib.py Lib/platform.py Lib/poplib.py Lib/repr.py Lib/smtplib.py Lib/socket.py Lib/ssl.py Lib/test/badcert.pem Lib/test/badkey.pem Lib/test/decimaltestdata/abs.decTest Lib/test/decimaltestdata/add.decTest Lib/test/decimaltestdata/and.decTest Lib/test/decimaltestdata/base.decTest Lib/test/decimaltestdata/clamp.decTest Lib/test/decimaltestdata/class.decTest Lib/test/decimaltestdata/compare.decTest Lib/test/decimaltestdata/comparetotal.decTest Lib/test/decimaltestdata/comparetotmag.decTest Lib/test/decimaltestdata/copy.decTest Lib/test/decimaltestdata/copyabs.decTest Lib/test/decimaltestdata/copynegate.decTest Lib/test/decimaltestdata/copysign.decTest Lib/test/decimaltestdata/ddAbs.decTest Lib/test/decimaltestdata/ddAdd.decTest Lib/test/decimaltestdata/ddAnd.decTest Lib/test/decimaltestdata/ddBase.decTest Lib/test/decimaltestdata/ddCanonical.decTest Lib/test/decimaltestdata/ddClass.decTest Lib/test/decimaltestdata/ddCompare.decTest Lib/test/decimaltestdata/ddCompareSig.decTest Lib/test/decimaltestdata/ddCompareTotal.decTest Lib/test/decimaltestdata/ddCompareTotalMag.decTest Lib/test/decimaltestdata/ddCopy.decTest Lib/test/decimaltestdata/ddCopyAbs.decTest Lib/test/decimaltestdata/ddCopyNegate.decTest Lib/test/decimaltestdata/ddCopySign.decTest Lib/test/decimaltestdata/ddDivide.decTest Lib/test/decimaltestdata/ddDivideInt.decTest Lib/test/decimaltestdata/ddEncode.decTest Lib/test/decimaltestdata/ddFMA.decTest Lib/test/decimaltestdata/ddInvert.decTest Lib/test/decimaltestdata/ddLogB.decTest Lib/test/decimaltestdata/ddMax.decTest Lib/test/decimaltestdata/ddMaxMag.decTest Lib/test/decimaltestdata/ddMin.decTest Lib/test/decimaltestdata/ddMinMag.decTest Lib/test/decimaltestdata/ddMinus.decTest Lib/test/decimaltestdata/ddMultiply.decTest Lib/test/decimaltestdata/ddNextMinus.decTest Lib/test/decimaltestdata/ddNextPlus.decTest Lib/test/decimaltestdata/ddNextToward.decTest Lib/test/decimaltestdata/ddOr.decTest Lib/test/decimaltestdata/ddPlus.decTest Lib/test/decimaltestdata/ddQuantize.decTest Lib/test/decimaltestdata/ddReduce.decTest Lib/test/decimaltestdata/ddRemainder.decTest Lib/test/decimaltestdata/ddRemainderNear.decTest Lib/test/decimaltestdata/ddRotate.decTest Lib/test/decimaltestdata/ddSameQuantum.decTest Lib/test/decimaltestdata/ddScaleB.decTest Lib/test/decimaltestdata/ddShift.decTest Lib/test/decimaltestdata/ddSubtract.decTest Lib/test/decimaltestdata/ddToIntegral.decTest Lib/test/decimaltestdata/ddXor.decTest Lib/test/decimaltestdata/decDouble.decTest Lib/test/decimaltestdata/decQuad.decTest Lib/test/decimaltestdata/decSingle.decTest Lib/test/decimaltestdata/decimal128.decTest Lib/test/decimaltestdata/decimal32.decTest Lib/test/decimaltestdata/decimal64.decTest Lib/test/decimaltestdata/divide.decTest Lib/test/decimaltestdata/divideint.decTest Lib/test/decimaltestdata/dqAbs.decTest Lib/test/decimaltestdata/dqAdd.decTest Lib/test/decimaltestdata/dqAnd.decTest Lib/test/decimaltestdata/dqBase.decTest Lib/test/decimaltestdata/dqCanonical.decTest Lib/test/decimaltestdata/dqClass.decTest Lib/test/decimaltestdata/dqCompare.decTest Lib/test/decimaltestdata/dqCompareSig.decTest Lib/test/decimaltestdata/dqCompareTotal.decTest Lib/test/decimaltestdata/dqCompareTotalMag.decTest Lib/test/decimaltestdata/dqCopy.decTest Lib/test/decimaltestdata/dqCopyAbs.decTest Lib/test/decimaltestdata/dqCopyNegate.decTest Lib/test/decimaltestdata/dqCopySign.decTest Lib/test/decimaltestdata/dqDivide.decTest Lib/test/decimaltestdata/dqDivideInt.decTest Lib/test/decimaltestdata/dqEncode.decTest Lib/test/decimaltestdata/dqFMA.decTest Lib/test/decimaltestdata/dqInvert.decTest Lib/test/decimaltestdata/dqLogB.decTest Lib/test/decimaltestdata/dqMax.decTest Lib/test/decimaltestdata/dqMaxMag.decTest Lib/test/decimaltestdata/dqMin.decTest Lib/test/decimaltestdata/dqMinMag.decTest Lib/test/decimaltestdata/dqMinus.decTest Lib/test/decimaltestdata/dqMultiply.decTest Lib/test/decimaltestdata/dqNextMinus.decTest Lib/test/decimaltestdata/dqNextPlus.decTest Lib/test/decimaltestdata/dqNextToward.decTest Lib/test/decimaltestdata/dqOr.decTest Lib/test/decimaltestdata/dqPlus.decTest Lib/test/decimaltestdata/dqQuantize.decTest Lib/test/decimaltestdata/dqReduce.decTest Lib/test/decimaltestdata/dqRemainder.decTest Lib/test/decimaltestdata/dqRemainderNear.decTest Lib/test/decimaltestdata/dqRotate.decTest Lib/test/decimaltestdata/dqSameQuantum.decTest Lib/test/decimaltestdata/dqScaleB.decTest Lib/test/decimaltestdata/dqShift.decTest Lib/test/decimaltestdata/dqSubtract.decTest Lib/test/decimaltestdata/dqToIntegral.decTest Lib/test/decimaltestdata/dqXor.decTest Lib/test/decimaltestdata/dsBase.decTest Lib/test/decimaltestdata/dsEncode.decTest Lib/test/decimaltestdata/exp.decTest Lib/test/decimaltestdata/extra.decTest Lib/test/decimaltestdata/fma.decTest Lib/test/decimaltestdata/inexact.decTest Lib/test/decimaltestdata/invert.decTest Lib/test/decimaltestdata/ln.decTest Lib/test/decimaltestdata/log10.decTest Lib/test/decimaltestdata/logb.decTest Lib/test/decimaltestdata/max.decTest Lib/test/decimaltestdata/maxmag.decTest Lib/test/decimaltestdata/min.decTest Lib/test/decimaltestdata/minmag.decTest Lib/test/decimaltestdata/minus.decTest Lib/test/decimaltestdata/multiply.decTest Lib/test/decimaltestdata/nextminus.decTest Lib/test/decimaltestdata/nextplus.decTest Lib/test/decimaltestdata/nexttoward.decTest Lib/test/decimaltestdata/normalize.decTest Lib/test/decimaltestdata/or.decTest Lib/test/decimaltestdata/plus.decTest Lib/test/decimaltestdata/power.decTest Lib/test/decimaltestdata/powersqrt.decTest Lib/test/decimaltestdata/quantize.decTest Lib/test/decimaltestdata/randomBound32.decTest Lib/test/decimaltestdata/randoms.decTest Lib/test/decimaltestdata/reduce.decTest Lib/test/decimaltestdata/remainder.decTest Lib/test/decimaltestdata/remainderNear.decTest Lib/test/decimaltestdata/rescale.decTest Lib/test/decimaltestdata/rotate.decTest Lib/test/decimaltestdata/rounding.decTest Lib/test/decimaltestdata/samequantum.decTest Lib/test/decimaltestdata/scaleb.decTest Lib/test/decimaltestdata/shift.decTest Lib/test/decimaltestdata/squareroot.decTest Lib/test/decimaltestdata/subtract.decTest Lib/test/decimaltestdata/testall.decTest Lib/test/decimaltestdata/tointegral.decTest Lib/test/decimaltestdata/tointegralx.decTest Lib/test/decimaltestdata/xor.decTest Lib/test/https_svn_python_org_root.pem Lib/test/list_tests.py Lib/test/nullcert.pem Lib/test/regrtest.py Lib/test/test_cmd_line.py Lib/test/test_collections.py Lib/test/test_decimal.py Lib/test/test_hash.py Lib/test/test_re.py Lib/test/test_repr.py Lib/test/test_socket_ssl.py Lib/test/test_ssl.py Lib/urllib.py Mac/Modules/cf/_CFmodule.c Mac/Modules/cf/cfsupport.py Mac/Modules/cf/pycfbridge.c Modules/_sre.c Modules/_ssl.c Modules/bz2module.c Objects/dictobject.c Objects/genobject.c Objects/listobject.c Objects/longobject.c Objects/object.c Objects/unicodeobject.c Python/ceval.c Python/compile.c
brett.cannon
python-3000-checkins at python.org
Fri Sep 21 03:17:15 CEST 2007
Author: brett.cannon
Date: Fri Sep 21 03:17:09 2007
New Revision: 58223
Added:
python/branches/py3k-importlib/Lib/test/badcert.pem
- copied unchanged from r58222, python/branches/py3k/Lib/test/badcert.pem
python/branches/py3k-importlib/Lib/test/badkey.pem
- copied unchanged from r58222, python/branches/py3k/Lib/test/badkey.pem
python/branches/py3k-importlib/Lib/test/decimaltestdata/and.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/and.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/class.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/class.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/comparetotal.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/comparetotal.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/comparetotmag.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/comparetotmag.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/copy.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/copy.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/copyabs.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/copyabs.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/copynegate.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/copynegate.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/copysign.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/copysign.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddAbs.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddAbs.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddAdd.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddAdd.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddAnd.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddAnd.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddBase.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddBase.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCanonical.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddCanonical.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddClass.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddClass.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCompare.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddCompare.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCompareSig.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddCompareSig.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCompareTotal.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddCompareTotal.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCompareTotalMag.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddCompareTotalMag.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCopy.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddCopy.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCopyAbs.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddCopyAbs.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCopyNegate.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddCopyNegate.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddCopySign.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddCopySign.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddDivide.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddDivide.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddDivideInt.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddDivideInt.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddEncode.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddEncode.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddFMA.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddFMA.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddInvert.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddInvert.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddLogB.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddLogB.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMax.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddMax.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMaxMag.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddMaxMag.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMin.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddMin.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMinMag.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddMinMag.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMinus.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddMinus.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddMultiply.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddMultiply.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddNextMinus.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddNextMinus.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddNextPlus.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddNextPlus.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddNextToward.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddNextToward.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddOr.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddOr.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddPlus.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddPlus.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddQuantize.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddQuantize.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddReduce.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddReduce.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddRemainder.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddRemainder.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddRemainderNear.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddRemainderNear.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddRotate.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddRotate.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddSameQuantum.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddSameQuantum.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddScaleB.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddScaleB.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddShift.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddShift.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddSubtract.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddSubtract.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddToIntegral.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddToIntegral.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ddXor.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ddXor.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/decDouble.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/decDouble.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/decQuad.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/decQuad.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/decSingle.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/decSingle.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqAbs.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqAbs.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqAdd.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqAdd.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqAnd.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqAnd.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqBase.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqBase.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCanonical.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqCanonical.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqClass.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqClass.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCompare.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqCompare.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCompareSig.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqCompareSig.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCompareTotal.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqCompareTotal.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCompareTotalMag.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqCompareTotalMag.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCopy.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqCopy.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCopyAbs.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqCopyAbs.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCopyNegate.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqCopyNegate.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqCopySign.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqCopySign.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqDivide.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqDivide.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqDivideInt.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqDivideInt.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqEncode.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqEncode.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqFMA.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqFMA.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqInvert.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqInvert.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqLogB.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqLogB.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMax.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqMax.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMaxMag.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqMaxMag.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMin.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqMin.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMinMag.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqMinMag.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMinus.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqMinus.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqMultiply.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqMultiply.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqNextMinus.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqNextMinus.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqNextPlus.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqNextPlus.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqNextToward.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqNextToward.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqOr.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqOr.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqPlus.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqPlus.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqQuantize.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqQuantize.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqReduce.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqReduce.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqRemainder.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqRemainder.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqRemainderNear.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqRemainderNear.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqRotate.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqRotate.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqSameQuantum.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqSameQuantum.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqScaleB.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqScaleB.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqShift.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqShift.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqSubtract.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqSubtract.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqToIntegral.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqToIntegral.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dqXor.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dqXor.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dsBase.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dsBase.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/dsEncode.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/dsEncode.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/exp.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/exp.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/extra.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/extra.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/fma.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/fma.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/invert.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/invert.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/ln.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/ln.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/log10.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/log10.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/logb.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/logb.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/maxmag.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/maxmag.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/minmag.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/minmag.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/nextminus.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/nextminus.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/nextplus.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/nextplus.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/nexttoward.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/nexttoward.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/or.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/or.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/powersqrt.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/powersqrt.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/reduce.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/reduce.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/rotate.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/rotate.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/scaleb.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/scaleb.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/shift.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/shift.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/tointegralx.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/tointegralx.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/xor.decTest
- copied unchanged from r58222, python/branches/py3k/Lib/test/decimaltestdata/xor.decTest
python/branches/py3k-importlib/Lib/test/https_svn_python_org_root.pem
- copied unchanged from r58222, python/branches/py3k/Lib/test/https_svn_python_org_root.pem
python/branches/py3k-importlib/Lib/test/nullcert.pem
- copied unchanged from r58222, python/branches/py3k/Lib/test/nullcert.pem
Removed:
python/branches/py3k-importlib/Lib/test/decimaltestdata/decimal128.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/decimal32.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/decimal64.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/normalize.decTest
Modified:
python/branches/py3k-importlib/ (props changed)
python/branches/py3k-importlib/Doc/c-api/concrete.rst
python/branches/py3k-importlib/Doc/library/cgi.rst
python/branches/py3k-importlib/Doc/library/collections.rst
python/branches/py3k-importlib/Doc/library/decimal.rst
python/branches/py3k-importlib/Doc/library/fileinput.rst
python/branches/py3k-importlib/Doc/library/functions.rst
python/branches/py3k-importlib/Doc/library/hashlib.rst
python/branches/py3k-importlib/Doc/library/operator.rst
python/branches/py3k-importlib/Doc/library/os.rst
python/branches/py3k-importlib/Doc/library/simplexmlrpcserver.rst
python/branches/py3k-importlib/Doc/library/ssl.rst
python/branches/py3k-importlib/Doc/library/stdtypes.rst
python/branches/py3k-importlib/Doc/library/undoc.rst
python/branches/py3k-importlib/Doc/reference/index.rst
python/branches/py3k-importlib/Doc/reference/simple_stmts.rst
python/branches/py3k-importlib/Doc/tutorial/inputoutput.rst
python/branches/py3k-importlib/Doc/whatsnew/2.5.rst
python/branches/py3k-importlib/Doc/whatsnew/2.6.rst
python/branches/py3k-importlib/Lib/cgi.py
python/branches/py3k-importlib/Lib/collections.py
python/branches/py3k-importlib/Lib/ctypes/test/test_cfuncs.py
python/branches/py3k-importlib/Lib/ctypes/test/test_functions.py
python/branches/py3k-importlib/Lib/ctypes/util.py
python/branches/py3k-importlib/Lib/decimal.py
python/branches/py3k-importlib/Lib/distutils/command/build_scripts.py
python/branches/py3k-importlib/Lib/httplib.py
python/branches/py3k-importlib/Lib/imaplib.py
python/branches/py3k-importlib/Lib/platform.py
python/branches/py3k-importlib/Lib/poplib.py
python/branches/py3k-importlib/Lib/repr.py
python/branches/py3k-importlib/Lib/smtplib.py
python/branches/py3k-importlib/Lib/socket.py
python/branches/py3k-importlib/Lib/ssl.py
python/branches/py3k-importlib/Lib/test/decimaltestdata/abs.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/add.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/base.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/clamp.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/compare.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/divide.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/divideint.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/inexact.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/max.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/min.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/minus.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/multiply.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/plus.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/power.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/quantize.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/randomBound32.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/randoms.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/remainder.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/remainderNear.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/rescale.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/rounding.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/samequantum.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/squareroot.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/subtract.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/testall.decTest
python/branches/py3k-importlib/Lib/test/decimaltestdata/tointegral.decTest
python/branches/py3k-importlib/Lib/test/list_tests.py
python/branches/py3k-importlib/Lib/test/regrtest.py
python/branches/py3k-importlib/Lib/test/test_cmd_line.py
python/branches/py3k-importlib/Lib/test/test_collections.py
python/branches/py3k-importlib/Lib/test/test_decimal.py
python/branches/py3k-importlib/Lib/test/test_hash.py
python/branches/py3k-importlib/Lib/test/test_re.py
python/branches/py3k-importlib/Lib/test/test_repr.py
python/branches/py3k-importlib/Lib/test/test_socket_ssl.py
python/branches/py3k-importlib/Lib/test/test_ssl.py
python/branches/py3k-importlib/Lib/urllib.py
python/branches/py3k-importlib/Mac/Modules/cf/_CFmodule.c
python/branches/py3k-importlib/Mac/Modules/cf/cfsupport.py
python/branches/py3k-importlib/Mac/Modules/cf/pycfbridge.c
python/branches/py3k-importlib/Modules/_sre.c
python/branches/py3k-importlib/Modules/_ssl.c
python/branches/py3k-importlib/Modules/bz2module.c
python/branches/py3k-importlib/Objects/dictobject.c
python/branches/py3k-importlib/Objects/genobject.c
python/branches/py3k-importlib/Objects/listobject.c
python/branches/py3k-importlib/Objects/longobject.c
python/branches/py3k-importlib/Objects/object.c
python/branches/py3k-importlib/Objects/unicodeobject.c
python/branches/py3k-importlib/Python/ceval.c
python/branches/py3k-importlib/Python/compile.c
Log:
Merged revisions 58188-58222 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
Modified: python/branches/py3k-importlib/Doc/c-api/concrete.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/c-api/concrete.rst (original)
+++ python/branches/py3k-importlib/Doc/c-api/concrete.rst Fri Sep 21 03:17:09 2007
@@ -1953,12 +1953,12 @@
``PyTuple_Pack(2, a, b)`` is equivalent to ``Py_BuildValue("(OO)", a, b)``.
-.. cfunction:: int PyTuple_Size(PyObject *p)
+.. cfunction:: Py_ssize_t PyTuple_Size(PyObject *p)
Take a pointer to a tuple object, and return the size of that tuple.
-.. cfunction:: int PyTuple_GET_SIZE(PyObject *p)
+.. cfunction:: Py_ssize_t PyTuple_GET_SIZE(PyObject *p)
Return the size of the tuple *p*, which must be non-*NULL* and point to a tuple;
no error checking is performed.
@@ -2458,7 +2458,7 @@
immediately after file object creation.
-.. cfunction:: int PyFile_Encoding(PyFileObject *p, char *enc)
+.. cfunction:: int PyFile_SetEncoding(PyFileObject *p, const char *enc)
Set the file's encoding for Unicode output to *enc*. Return 1 on success and 0
on failure.
@@ -3371,7 +3371,7 @@
or :class:`frozenset` or instances of their subtypes.
-.. cfunction:: int PySet_Size(PyObject *anyset)
+.. cfunction:: Py_ssize_t PySet_Size(PyObject *anyset)
.. index:: builtin: len
@@ -3380,7 +3380,7 @@
:class:`set`, :class:`frozenset`, or an instance of a subtype.
-.. cfunction:: int PySet_GET_SIZE(PyObject *anyset)
+.. cfunction:: Py_ssize_t PySet_GET_SIZE(PyObject *anyset)
Macro form of :cfunc:`PySet_Size` without error checking.
Modified: python/branches/py3k-importlib/Doc/library/cgi.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/cgi.rst (original)
+++ python/branches/py3k-importlib/Doc/library/cgi.rst Fri Sep 21 03:17:09 2007
@@ -147,6 +147,11 @@
if not line: break
linecount = linecount + 1
+If an error is encountered when obtaining the contents of an uploaded file
+(for example, when the user interrupts the form submission by clicking on
+a Back or Cancel button) the :attr:`done` attribute of the object for the
+field will be set to the value -1.
+
The file upload draft standard entertains the possibility of uploading multiple
files from one field (using a recursive :mimetype:`multipart/\*` encoding).
When this occurs, the item will be a dictionary-like :class:`FieldStorage` item.
Modified: python/branches/py3k-importlib/Doc/library/collections.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/collections.rst (original)
+++ python/branches/py3k-importlib/Doc/library/collections.rst Fri Sep 21 03:17:09 2007
@@ -395,11 +395,14 @@
.. _named-tuple-factory:
-:func:`NamedTuple` datatype factory function
---------------------------------------------
+:func:`NamedTuple` Factory Function for Tuples with Named Fields
+----------------------------------------------------------------
+Named tuples assign meaning to each position in a tuple and allow for more readable,
+self-documenting code. They can be used wherever regular tuples are used, and
+they add the ability to access fields by name instead of position index.
-.. function:: NamedTuple(typename, fieldnames)
+.. function:: NamedTuple(typename, fieldnames, [verbose])
Returns a new tuple subclass named *typename*. The new subclass is used to
create tuple-like objects that have fields accessable by attribute lookup as
@@ -407,43 +410,92 @@
helpful docstring (with typename and fieldnames) and a helpful :meth:`__repr__`
method which lists the tuple contents in a ``name=value`` format.
- The *fieldnames* are specified in a single string and are separated by spaces.
- Any valid Python identifier may be used for a field name.
+ The *fieldnames* are specified in a single string with each fieldname separated by
+ a space and/or comma. Any valid Python identifier may be used for a fieldname.
- Example::
+ If *verbose* is true, will print the class definition.
- >>> Point = NamedTuple('Point', 'x y')
- >>> Point.__doc__ # docstring for the new datatype
- 'Point(x, y)'
- >>> p = Point(11, y=22) # instantiate with positional or keyword arguments
- >>> p[0] + p[1] # works just like the tuple (11, 22)
- 33
- >>> x, y = p # unpacks just like a tuple
- >>> x, y
- (11, 22)
- >>> p.x + p.y # fields also accessable by name
- 33
- >>> p # readable __repr__ with name=value style
- Point(x=11, y=22)
-
- The use cases are the same as those for tuples. The named factories assign
- meaning to each tuple position and allow for more readable, self-documenting
- code. Named tuples can also be used to assign field names to tuples returned
- by the :mod:`csv` or :mod:`sqlite3` modules. For example::
-
- from itertools import starmap
- import csv
- EmployeeRecord = NamedTuple('EmployeeRecord', 'name age title department paygrade')
- for record in starmap(EmployeeRecord, csv.reader(open("employees.csv", "rb"))):
- print(record)
-
- To cast an individual record stored as :class:`list`, :class:`tuple`, or some
- other iterable type, use the star-operator [#]_ to unpack the values::
-
- >>> Color = NamedTuple('Color', 'name code')
- >>> m = dict(red=1, green=2, blue=3)
- >>> print(Color(*m.popitem()))
- Color(name='blue', code=3)
+ *NamedTuple* instances do not have per-instance dictionaries, so they are
+ lightweight and require no more memory than regular tuples.
+
+Example::
+
+ >>> Point = NamedTuple('Point', 'x y', True)
+ class Point(tuple):
+ 'Point(x, y)'
+ __slots__ = ()
+ __fields__ = ('x', 'y')
+ def __new__(cls, x, y):
+ return tuple.__new__(cls, (x, y))
+ def __repr__(self):
+ return 'Point(x=%r, y=%r)' % self
+ def __replace__(self, field, value):
+ 'Return a new Point object replacing one field with a new value'
+ return Point(**dict(zip(('x', 'y'), self) + [(field, value)]))
+ x = property(itemgetter(0))
+ y = property(itemgetter(1))
+
+ >>> p = Point(11, y=22) # instantiate with positional or keyword arguments
+ >>> p[0] + p[1] # indexable like the regular tuple (11, 22)
+ 33
+ >>> x, y = p # unpack like a regular tuple
+ >>> x, y
+ (11, 22)
+ >>> p.x + p.y # fields also accessable by name
+ 33
+ >>> p # readable __repr__ with a name=value style
+ Point(x=11, y=22)
+
+Named tuples are especially useful for assigning field names to result tuples returned
+by the :mod:`csv` or :mod:`sqlite3` modules::
+
+ from itertools import starmap
+ import csv
+ EmployeeRecord = NamedTuple('EmployeeRecord', 'name age title department paygrade')
+ for record in starmap(EmployeeRecord, csv.reader(open("employees.csv", "rb"))):
+ print(emp.name, emp.title)
+
+When casting a single record to a *NamedTuple*, use the star-operator [#]_ to unpack
+the values::
+
+ >>> t = [11, 22]
+ >>> Point(*t) # the star-operator unpacks any iterable object
+ Point(x=11, y=22)
+
+In addition to the methods inherited from tuples, named tuples support
+an additonal method and an informational read-only attribute.
+
+.. method:: somenamedtuple.replace(field, value)
+
+ Return a new instance of the named tuple replacing the named *field* with a new *value*:
+
+::
+
+ >>> p = Point(x=11, y=22)
+ >>> p.__replace__('x', 33)
+ Point(x=33, y=22)
+
+ >>> for recordnum, record in inventory:
+ ... inventory[recordnum] = record.replace('total', record.price * record.quantity)
+
+.. attribute:: somenamedtuple.__fields__
+
+ Return a tuple of strings listing the field names. This is useful for introspection,
+ for converting a named tuple instance to a dictionary, and for combining named tuple
+ types to create new named tuple types:
+
+::
+
+ >>> p.__fields__ # view the field names
+ ('x', 'y')
+ >>> dict(zip(p.__fields__, p)) # convert to a dictionary
+ {'y': 22, 'x': 11}
+
+ >>> Color = NamedTuple('Color', 'red green blue')
+ >>> pixel_fields = ' '.join(Point.__fields__ + Color.__fields__) # combine fields
+ >>> Pixel = NamedTuple('Pixel', pixel_fields)
+ >>> Pixel(11, 22, 128, 255, 0)
+ Pixel(x=11, y=22, red=128, green=255, blue=0)'
.. rubric:: Footnotes
Modified: python/branches/py3k-importlib/Doc/library/decimal.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/decimal.rst (original)
+++ python/branches/py3k-importlib/Doc/library/decimal.rst Fri Sep 21 03:17:09 2007
@@ -14,7 +14,7 @@
The :mod:`decimal` module provides support for decimal floating point
-arithmetic. It offers several advantages over the :class:`float()` datatype:
+arithmetic. It offers several advantages over the :class:`float` datatype:
* Decimal numbers can be represented exactly. In contrast, numbers like
:const:`1.1` do not have an exact representation in binary floating point. End
@@ -22,7 +22,7 @@
:const:`1.1000000000000001` as it does with binary floating point.
* The exactness carries over into arithmetic. In decimal floating point, ``0.1
- + 0.1 + 0.1 - 0.3`` is exactly equal to zero. In binary floating point, result
+ + 0.1 + 0.1 - 0.3`` is exactly equal to zero. In binary floating point, the result
is :const:`5.5511151231257827e-017`. While near to zero, the differences
prevent reliable equality testing and differences can accumulate. For this
reason, decimal would be preferred in accounting applications which have strict
@@ -36,7 +36,7 @@
1.20`` gives :const:`1.5600`.
* Unlike hardware based binary floating point, the decimal module has a user
- settable precision (defaulting to 28 places) which can be as large as needed for
+ alterable precision (defaulting to 28 places) which can be as large as needed for
a given problem::
>>> getcontext().prec = 6
@@ -56,7 +56,7 @@
A decimal number is immutable. It has a sign, coefficient digits, and an
exponent. To preserve significance, the coefficient digits do not truncate
-trailing zeroes. Decimals also include special values such as
+trailing zeros. Decimals also include special values such as
:const:`Infinity`, :const:`-Infinity`, and :const:`NaN`. The standard also
differentiates :const:`-0` from :const:`+0`.
@@ -65,7 +65,7 @@
enablers which determine whether signals are treated as exceptions. Rounding
options include :const:`ROUND_CEILING`, :const:`ROUND_DOWN`,
:const:`ROUND_FLOOR`, :const:`ROUND_HALF_DOWN`, :const:`ROUND_HALF_EVEN`,
-:const:`ROUND_HALF_UP`, and :const:`ROUND_UP`.
+:const:`ROUND_HALF_UP`, :const:`ROUND_UP`, and :const:`ROUND_05UP`.
Signals are groups of exceptional conditions arising during the course of
computation. Depending on the needs of the application, signals may be ignored,
@@ -82,11 +82,11 @@
.. seealso::
- IBM's General Decimal Arithmetic Specification, `The General Decimal Arithmetic
- Specification <http://www2.hursley.ibm.com/decimal/decarith.html>`_.
+ * IBM's General Decimal Arithmetic Specification, `The General Decimal Arithmetic
+ Specification <http://www2.hursley.ibm.com/decimal/decarith.html>`_.
- IEEE standard 854-1987, `Unofficial IEEE 854 Text
- <http://www.cs.berkeley.edu/~ejr/projects/754/private/drafts/854-1987/dir.html>`_.
+ * IEEE standard 854-1987, `Unofficial IEEE 854 Text
+ <http://www.cs.berkeley.edu/~ejr/projects/754/private/drafts/854-1987/dir.html>`_.
.. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -123,6 +123,8 @@
Decimal("3.14")
>>> Decimal(str(2.0 ** 0.5))
Decimal("1.41421356237")
+ >>> Decimal(2) ** Decimal("0.5")
+ Decimal("1.414213562373095048801688724")
>>> Decimal("NaN")
Decimal("NaN")
>>> Decimal("-Infinity")
@@ -172,6 +174,17 @@
>>> c % a
Decimal("0.77")
+And some mathematic functions are also available to Decimal::
+
+ >>> Decimal(2).sqrt()
+ Decimal("1.414213562373095048801688724")
+ >>> Decimal(1).exp()
+ Decimal("2.718281828459045235360287471")
+ >>> Decimal("10").ln()
+ Decimal("2.302585092994045684017991455")
+ >>> Decimal("10").log10()
+ Decimal("1")
+
The :meth:`quantize` method rounds a number to a fixed exponent. This method is
useful for monetary applications that often round results to a fixed number of
places::
@@ -285,7 +298,7 @@
The *context* precision does not affect how many digits are stored. That is
determined exclusively by the number of digits in *value*. For example,
- ``Decimal("3.00000")`` records all five zeroes even if the context precision is
+ ``Decimal("3.00000")`` records all five zeros even if the context precision is
only three.
The purpose of the *context* argument is determining what to do if *value* is a
@@ -295,7 +308,7 @@
Once constructed, :class:`Decimal` objects are immutable.
-Decimal floating point objects share many properties with the other builtin
+Decimal floating point objects share many properties with the other built-in
numeric types such as :class:`float` and :class:`int`. All of the usual math
operations and special methods apply. Likewise, decimal objects can be copied,
pickled, printed, used as dictionary keys, used as set elements, compared,
@@ -315,50 +328,363 @@
.. method:: Decimal.as_tuple()
- Returns a tuple representation of the number: ``(sign, digittuple, exponent)``.
+ Return a tuple representation of the number: ``(sign, digit_tuple, exponent)``.
+
+.. method:: Decimal.canonical()
+
+ Return the canonical encoding of the argument. Currently, the
+ encoding of a :class:`Decimal` instance is always canonical, so
+ this operation returns its argument unchanged.
+
+ .. versionadded:: 2.6
.. method:: Decimal.compare(other[, context])
- Compares like :meth:`__cmp__` but returns a decimal instance::
+ Compare the values of two Decimal instances. This operation
+ behaves in the same way as the usual comparison method
+ :meth:`__cmp__`, except that :meth:`compare` returns a Decimal
+ instance rather than an integer, and if either operand is a NaN
+ then the result is a NaN::
a or b is a NaN ==> Decimal("NaN")
a < b ==> Decimal("-1")
a == b ==> Decimal("0")
a > b ==> Decimal("1")
+.. method:: Decimal.compare_signal(other[, context])
+
+ This operation is identical to the :meth:`compare` method, except
+ that all NaNs signal. That is, if neither operand is a signaling
+ NaN then any quiet NaN operand is treated as though it were a
+ signaling NaN.
+
+ .. versionadded:: 2.6
+
+.. method:: Decimal.compare_total(other)
+
+ Compare two operands using their abstract representation rather
+ than their numerical value. Similar to the :meth:`compare` method,
+ but the result gives a total ordering on :class:`Decimal`
+ instances. Two :class:`Decimal` instances with the same numeric
+ value but different representations compare unequal in this
+ ordering::
+
+ >>> Decimal("12.0").compare_total(Decimal("12"))
+ Decimal("-1")
+
+ Quiet and signaling NaNs are also included in the total ordering.
+ The result of this function is ``Decimal("0")`` if both operands
+ have the same representation, ``Decimal("-1")`` if the first
+ operand is lower in the total order than the second, and
+ ``Decimal("1")`` if the first operand is higher in the total order
+ than the second operand. See the specification for details of the
+ total order.
+
+ .. versionadded:: 2.6
+
+.. method:: Decimal.compare_total_mag(other)
+
+ Compare two operands using their abstract representation rather
+ than their value as in :meth:`compare_total`, but ignoring the sign
+ of each operand. ``x.compare_total_mag(y)`` is equivalent to
+ ``x.copy_abs().compare_total(y.copy_abs())``.
+
+ .. versionadded:: 2.6
+
+.. method:: Decimal.copy_abs()
+
+ Return the absolute value of the argument. This operation is
+ unaffected by the context and is quiet: no flags are changed and no
+ rounding is performed.
+
+ .. versionadded:: 2.6
+
+.. method:: Decimal.copy_negate()
+
+ Return the negation of the argument. This operation is unaffected
+ by the context and is quiet: no flags are changed and no rounding
+ is performed.
+
+ .. versionadded:: 2.6
+
+.. method:: Decimal.copy_sign(other)
+
+ Return a copy of the first operand with the sign set to be the
+ same as the sign of the second operand. For example::
+
+ >>> Decimal("2.3").copy_sign(Decimal("-1.5"))
+ Decimal("-2.3")
+
+ This operation is unaffected by the context and is quiet: no flags
+ are changed and no rounding is performed.
+
+ .. versionadded:: 2.6
+
+.. method:: Decimal.exp([context])
+
+ Return the value of the (natural) exponential function ``e**x`` at the
+ given number. The result is correctly rounded using the
+ :const:`ROUND_HALF_EVEN` rounding mode.
+
+ >>> Decimal(1).exp()
+ Decimal("2.718281828459045235360287471")
+ >>> Decimal(321).exp()
+ Decimal("2.561702493119680037517373933E+139")
+
+ .. versionadded:: 2.6
+
+.. method:: Decimal.fma(other, third[, context])
+
+ Fused multiply-add. Return self*other+third with no rounding of
+ the intermediate product self*other.
+
+ >>> Decimal(2).fma(3, 5)
+ Decimal("11")
+
+ .. versionadded:: 2.6
+
+.. method:: Decimal.is_canonical()
+
+ Return :const:`True` if the argument is canonical and
+ :const:`False` otherwise. Currently, a :class:`Decimal` instance
+ is always canonical, so this operation always returns
+ :const:`True`.
+
+ .. versionadded:: 2.6
+
+.. method:: is_finite()
+
+ Return :const:`True` if the argument is a finite number, and
+ :const:`False` if the argument is an infinity or a NaN.
+
+ .. versionadded:: 2.6
+
+.. method:: is_infinite()
+
+ Return :const:`True` if the argument is either positive or
+ negative infinity and :const:`False` otherwise.
+
+ .. versionadded:: 2.6
+
+.. method:: is_nan()
+
+ Return :const:`True` if the argument is a (quiet or signaling)
+ NaN and :const:`False` otherwise.
+
+ .. versionadded:: 2.6
+
+.. method:: is_normal()
+
+ Return :const:`True` if the argument is a *normal* finite number.
+ Return :const:`False` if the argument is zero, subnormal, infinite
+ or a NaN.
+
+ .. versionadded:: 2.6
+
+.. method:: is_qnan()
+
+ Return :const:`True` if the argument is a quiet NaN, and
+ :const:`False` otherwise.
+
+ .. versionadded:: 2.6
+
+.. method:: is_signed()
+
+ Return :const:`True` if the argument has a negative sign and
+ :const:`False` otherwise. Note that zeros and NaNs can both carry
+ signs.
+
+ .. versionadded:: 2.6
+
+.. method:: is_snan()
+
+ Return :const:`True` if the argument is a signaling NaN and
+ :const:`False` otherwise.
+
+ .. versionadded:: 2.6
+
+.. method:: is_subnormal()
+
+ Return :const:`True` if the argument is subnormal, and
+ :const:`False` otherwise.
+
+ .. versionadded:: 2.6
+
+.. method:: is_zero()
+
+ Return :const:`True` if the argument is a (positive or negative)
+ zero and :const:`False` otherwise.
+
+ .. versionadded:: 2.6
+
+.. method:: Decimal.ln([context])
+
+ Return the natural (base e) logarithm of the operand. The result
+ is correctly rounded using the :const:`ROUND_HALF_EVEN` rounding
+ mode.
+
+ .. versionadded:: 2.6
+
+.. method:: Decimal.log10([context])
+
+ Return the base ten logarithm of the operand. The result is
+ correctly rounded using the :const:`ROUND_HALF_EVEN` rounding mode.
+
+ .. versionadded:: 2.6
+
+.. method: Decimal.logb([context])
+
+ For a nonzero number, return the adjusted exponent of its operand
+ as a :class:`Decimal` instance. If the operand is a zero then
+ ``Decimal("-Infinity")`` is returned and the
+ :const:`DivisionByZero` flag is raised. If the operand is an
+ infinity then ``Decimal("Infinity")`` is returned.
+
+ .. versionadded:: 2.6
+
+.. method:: Decimal.logical_and(other[, context])
+
+ :meth:`logical_and` is a logical operation which takes two
+ *logical operands* (see :ref:`logical_operands_label`). The result
+ is the digit-wise ``and`` of the two operands.
+
+ .. versionadded:: 2.6
+
+.. method:: Decimal.logical_invert(other[, context])
+
+ :meth:`logical_invert` is a logical operation. The argument must
+ be a *logical operand* (see :ref:`logical_operands_label`). The
+ result is the digit-wise inversion of the operand.
+
+ .. versionadded:: 2.6
+
+.. method:: Decimal.logical_or(other[, context])
+
+ :meth:`logical_or` is a logical operation which takes two *logical
+ operands* (see :ref:`logical_operands_label`). The result is the
+ digit-wise ``or`` of the two operands.
+
+ .. versionadded:: 2.6
+
+.. method:: Decimal.logical_xor(other[, context])
+
+ :meth:`logical_xor` is a logical operation which takes two
+ *logical operands* (see :ref:`logical_operands_label`). The result
+ is the digit-wise exclusive or of the two operands.
+
+ .. versionadded:: 2.6
.. method:: Decimal.max(other[, context])
Like ``max(self, other)`` except that the context rounding rule is applied
- before returning and that :const:`NaN` values are either signalled or ignored
+ before returning and that :const:`NaN` values are either signaled or ignored
(depending on the context and whether they are signaling or quiet).
+.. method:: Decimal.max_mag(other[, context])
+
+ Similar to the :meth:`max` method, but the comparison is done using
+ the absolute values of the operands.
+
+ .. versionadded:: 2.6
.. method:: Decimal.min(other[, context])
Like ``min(self, other)`` except that the context rounding rule is applied
- before returning and that :const:`NaN` values are either signalled or ignored
+ before returning and that :const:`NaN` values are either signaled or ignored
(depending on the context and whether they are signaling or quiet).
+.. method:: Decimal.min_mag(other[, context])
+
+ Similar to the :meth:`min` method, but the comparison is done using
+ the absolute values of the operands.
+
+ .. versionadded:: 2.6
+
+.. method:: Decimal.next_minus([context])
+
+ Return the largest number representable in the given context (or
+ in the current thread's context if no context is given) that is smaller
+ than the given operand.
+
+ .. versionadded:: 2.6
+
+.. method:: Decimal.next_plus([context])
+
+ Return the smallest number representable in the given context (or
+ in the current thread's context if no context is given) that is
+ larger than the given operand.
+
+ .. versionadded:: 2.6
+
+.. method:: Decimal.next_toward(other[, context])
+
+ If the two operands are unequal, return the number closest to the
+ first operand in the direction of the second operand. If both
+ operands are numerically equal, return a copy of the first operand
+ with the sign set to be the same as the sign of the second operand.
+
+ .. versionadded:: 2.6
.. method:: Decimal.normalize([context])
- Normalize the number by stripping the rightmost trailing zeroes and converting
+ Normalize the number by stripping the rightmost trailing zeros and converting
any result equal to :const:`Decimal("0")` to :const:`Decimal("0e0")`. Used for
producing canonical values for members of an equivalence class. For example,
``Decimal("32.100")`` and ``Decimal("0.321000e+2")`` both normalize to the
equivalent value ``Decimal("32.1")``.
+.. method:: Decimal.number_class([context])
+
+ Return a string describing the *class* of the operand. The
+ returned value is one of the following ten strings.
+
+ * ``"-Infinity"``, indicating that the operand is negative infinity.
+ * ``"-Normal"``, indicating that the operand is a negative normal number.
+ * ``"-Subnormal"``, indicating that the operand is negative and subnormal.
+ * ``"-Zero"``, indicating that the operand is a negative zero.
+ * ``"+Zero"``, indicating that the operand is a positive zero.
+ * ``"+Subnormal"``, indicating that the operand is positive and subnormal.
+ * ``"+Normal"``, indicating that the operand is a positive normal number.
+ * ``"+Infinity"``, indicating that the operand is positive infinity.
+ * ``"NaN"``, indicating that the operand is a quiet NaN (Not a Number).
+ * ``"sNaN"``, indicating that the operand is a signaling NaN.
-.. method:: Decimal.quantize(exp [, rounding[, context[, watchexp]]])
+ .. versionadded:: 2.6
- Quantize makes the exponent the same as *exp*. Searches for a rounding method
- in *rounding*, then in *context*, and then in the current context.
+.. method:: Decimal.quantize(exp[, rounding[, context[, watchexp]]])
- If *watchexp* is set (default), then an error is returned whenever the resulting
- exponent is greater than :attr:`Emax` or less than :attr:`Etiny`.
+ Returns a value equal to the first operand after rounding and
+ having the exponent of the second operand.
+ >>> Decimal("1.41421356").quantize(Decimal("1.000"))
+ Decimal("1.414")
+
+ Unlike other operations, if the length of the coefficient after the
+ quantize operation would be greater than precision, then an
+ :const:`InvalidOperation` is signaled. This guarantees that, unless
+ there is an error condition, the quantized exponent is always equal
+ to that of the right-hand operand.
+
+ Also unlike other operations, quantize never signals Underflow,
+ even if the result is subnormal and inexact.
+
+ If the exponent of the second operand is larger than that of the
+ first then rounding may be necessary. In this case, the rounding
+ mode is determined by the ``rounding`` argument if given, else by
+ the given ``context`` argument; if neither argument is given the
+ rounding mode of the current thread's context is used.
+
+ If watchexp is set (default), then an error is returned whenever
+ the resulting exponent is greater than Emax or less than Etiny.
+
+.. method:: Decimal.radix()
+
+ Return ``Decimal(10)``, the radix (base) in which the
+ :class:`Decimal` class does all its arithmetic. Included for
+ compatibility with the specification.
+
+ .. versionadded:: 2.6
.. method:: Decimal.remainder_near(other[, context])
@@ -368,16 +694,49 @@
If both are equally close, the one chosen will have the same sign as *self*.
+.. method:: Decimal.rotate(other[, context])
+
+ Return the result of rotating the digits of the first operand by
+ an amount specified by the second operand. The second operand
+ must be an integer in the range -precision through precision. The
+ absolute value of the second operand gives the number of places to
+ rotate. If the second operand is positive then rotation is to the
+ left; otherwise rotation is to the right. The coefficient of the
+ first operand is padded on the left with zeros to length precision
+ if necessary. The sign and exponent of the first operand are
+ unchanged.
+
+ .. versionadded:: 2.6
.. method:: Decimal.same_quantum(other[, context])
Test whether self and other have the same exponent or whether both are
:const:`NaN`.
+.. method:: Decimal.scaleb(other[, context])
+
+ Return the first operand with exponent adjusted by the second.
+ Equivalently, return the first operand multiplied by ``10**other``.
+ The second operand must be an integer.
+
+ .. versionadded:: 2.6
+
+.. method:: Decimal.shift(other[, context])
+
+ Return the result of shifting the digits of the first operand by
+ an amount specified by the second operand. The second operand must
+ be an integer in the range -precision through precision. The
+ absolute value of the second operand gives the number of places to
+ shift. If the second operand is positive then the shift is to the
+ left; otherwise the shift is to the right. Digits shifted into the
+ coefficient are zeros. The sign and exponent of the first operand
+ are unchanged.
+
+ .. versionadded:: 2.6
.. method:: Decimal.sqrt([context])
- Return the square root to full precision.
+ Return the square root of the argument to full precision.
.. method:: Decimal.to_eng_string([context])
@@ -388,13 +747,53 @@
to 3 digits left of the decimal place. For example, converts
``Decimal('123E+1')`` to ``Decimal("1.23E+3")``
-
.. method:: Decimal.to_integral([rounding[, context]])
+ Identical to the :meth:`to_integral_value` method. The ``to_integral``
+ name has been kept for compatibility with older versions.
+
+.. method:: Decimal.to_integral_exact([rounding[, context]])
+
+ Round the argument to the nearest integer, signaling
+ :const:`Inexact` or :const:`Rounded` as appropriate if rounding
+ occurs. The rounding mode is determined by the ``rounding``
+ parameter if given, else by the given ``context``. If neither
+ parameter is given then the rounding mode of the current context is
+ used.
+
+ .. versionadded:: 2.6
+
+.. method:: Decimal.to_integral_value([rounding[, context]])
+
Rounds to the nearest integer without signaling :const:`Inexact` or
:const:`Rounded`. If given, applies *rounding*; otherwise, uses the rounding
method in either the supplied *context* or the current context.
+ .. versionchanged:: 2.6
+ renamed from ``to_integral`` to ``to_integral_value``. The old name
+ remains valid for compatibility.
+
+.. method:: Decimal.trim()
+
+ Returns its argument with *insignificant* trailing zeros removed.
+ Here, a trailing zero is considered insignificant either if it
+ follows the decimal point, or if the exponent of the argument (that
+ is, the last element of the :meth:`as_tuple` representation) is
+ positive.
+
+ .. versionadded:: 2.6
+
+.. _logical_operands_label:
+
+Logical operands
+^^^^^^^^^^^^^^^^
+
+The :meth:`logical_and`, :meth:`logical_invert`, :meth:`logical_or`,
+and :meth:`logical_xor` methods expect their arguments to be *logical
+operands*. A *logical operand* is a :class:`Decimal` instance whose
+exponent and sign are both zero, and whose digits are all either
+:const:`0` or :const:`1`.
+
.. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -509,6 +908,8 @@
* :const:`ROUND_HALF_EVEN` (to nearest with ties going to nearest even integer),
* :const:`ROUND_HALF_UP` (to nearest with ties going away from zero), or
* :const:`ROUND_UP` (away from zero).
+ * :const:`ROUND_05UP` (away from zero if last digit after rounding towards zero
+ would have been 0 or 5; otherwise towards zero)
The *traps* and *flags* fields list any signals to be set. Generally, new
contexts should only set traps and leave the flags clear.
@@ -520,9 +921,16 @@
:const:`1`, exponents are printed with a capital :const:`E`; otherwise, a
lowercase :const:`e` is used: :const:`Decimal('6.02e+23')`.
-The :class:`Context` class defines several general purpose methods as well as a
-large number of methods for doing arithmetic directly in a given context.
+ .. versionchanged:: 2.6
+ The :const:`ROUND_05UP` rounding mode was added.
+The :class:`Context` class defines several general purpose methods as
+well as a large number of methods for doing arithmetic directly in a
+given context. In addition, for each of the :class:`Decimal` methods
+described above (with the exception of the :meth:`adjusted` and
+:meth:`as_tuple` methods) there is a corresponding :class:`Context`
+method. For example, ``C.exp(x)`` is equivalent to
+``x.exp(context=C)``.
.. method:: Context.clear_flags()
@@ -533,6 +941,9 @@
Return a duplicate of the context.
+.. method:: Context.copy_decimal(num)
+
+ Return a copy of the Decimal instance num.
.. method:: Context.create_decimal(num)
@@ -566,7 +977,7 @@
The usual approach to working with decimals is to create :class:`Decimal`
instances and then apply arithmetic operations which take place within the
-current context for the active thread. An alternate approach is to use context
+current context for the active thread. An alternative approach is to use context
methods for calculating within a specific context. The methods are similar to
those for the :class:`Decimal` class and are only briefly recounted here.
@@ -581,42 +992,19 @@
Return the sum of *x* and *y*.
-.. method:: Context.compare(x, y)
-
- Compares values numerically.
-
- Like :meth:`__cmp__` but returns a decimal instance::
-
- a or b is a NaN ==> Decimal("NaN")
- a < b ==> Decimal("-1")
- a == b ==> Decimal("0")
- a > b ==> Decimal("1")
-
-
.. method:: Context.divide(x, y)
Return *x* divided by *y*.
-.. method:: Context.divmod(x, y)
-
- Divides two numbers and returns the integer part of the result.
-
-
-.. method:: Context.max(x, y)
-
- Compare two values numerically and return the maximum.
-
- If they are numerically equal then the left-hand operand is chosen as the
- result.
+.. method:: Context.divide_int(x, y)
+ Return *x* divided by *y*, truncated to an integer.
-.. method:: Context.min(x, y)
- Compare two values numerically and return the minimum.
+.. method:: Context.divmod(x, y)
- If they are numerically equal then the left-hand operand is chosen as the
- result.
+ Divides two numbers and returns the integer part of the result.
.. method:: Context.minus(x)
@@ -629,14 +1017,6 @@
Return the product of *x* and *y*.
-.. method:: Context.normalize(x)
-
- Normalize reduces an operand to its simplest form.
-
- Essentially a :meth:`plus` operation with all trailing zeros removed from the
- result.
-
-
.. method:: Context.plus(x)
Plus corresponds to the unary prefix plus operator in Python. This operation
@@ -646,33 +1026,31 @@
.. method:: Context.power(x, y[, modulo])
- Return ``x ** y`` to the *modulo* if given.
-
- The right-hand operand must be a whole number whose integer part (after any
- exponent has been applied) has no more than 9 digits and whose fractional part
- (if any) is all zeros before any rounding. The operand may be positive,
- negative, or zero; if negative, the absolute value of the power is used, and the
- left-hand operand is inverted (divided into 1) before use.
-
- If the increased precision needed for the intermediate calculations exceeds the
- capabilities of the implementation then an :const:`InvalidOperation` condition
- is signaled.
+ Return ``x`` to the power of ``y``, reduced modulo ``modulo`` if
+ given.
- If, when raising to a negative power, an underflow occurs during the division
- into 1, the operation is not halted at that point but continues.
-
-
-.. method:: Context.quantize(x, y)
-
- Returns a value equal to *x* after rounding and having the exponent of *y*.
-
- Unlike other operations, if the length of the coefficient after the quantize
- operation would be greater than precision, then an :const:`InvalidOperation` is
- signaled. This guarantees that, unless there is an error condition, the
- quantized exponent is always equal to that of the right-hand operand.
-
- Also unlike other operations, quantize never signals Underflow, even if the
- result is subnormal and inexact.
+ With two arguments, compute ``x**y``. If ``x`` is negative then
+ ``y`` must be integral. The result will be inexact unless ``y`` is
+ integral and the result is finite and can be expressed exactly in
+ 'precision' digits. The result should always be correctly rounded,
+ using the rounding mode of the current thread's context.
+
+ With three arguments, compute ``(x**y) % modulo``. For the three
+ argument form, the following restrictions on the arguments hold:
+
+ - all three arguments must be integral
+ - ``y`` must be nonnegative
+ - at least one of ``x`` or ``y`` must be nonzero
+ - ``modulo`` must be nonzero and have at most 'precision' digits
+
+ The result of ``Context.power(x, y, modulo)`` is identical to
+ the result that would be obtained by computing ``(x**y) %
+ modulo`` with unbounded precision, but is computed more
+ efficiently. It is always exact.
+
+ .. versionchanged:: 2.6
+ ``y`` may now be nonintegral in ``x**y``.
+ Stricter requirements for the three-argument version.
.. method:: Context.remainder(x, y)
@@ -682,47 +1060,10 @@
The sign of the result, if non-zero, is the same as that of the original
dividend.
-
-.. method:: Context.remainder_near(x, y)
-
- Computed the modulo as either a positive or negative value depending on which is
- closest to zero. For instance, ``Decimal(10).remainder_near(6)`` returns
- ``Decimal("-2")`` which is closer to zero than ``Decimal("4")``.
-
- If both are equally close, the one chosen will have the same sign as *self*.
-
-
-.. method:: Context.same_quantum(x, y)
-
- Test whether *x* and *y* have the same exponent or whether both are
- :const:`NaN`.
-
-
-.. method:: Context.sqrt(x)
-
- Return the square root of *x* to full precision.
-
-
.. method:: Context.subtract(x, y)
Return the difference between *x* and *y*.
-
-.. method:: Context.to_eng_string()
-
- Convert to engineering-type string.
-
- Engineering notation has an exponent which is a multiple of 3, so there are up
- to 3 digits left of the decimal place. For example, converts
- ``Decimal('123E+1')`` to ``Decimal("1.23E+3")``
-
-
-.. method:: Context.to_integral(x)
-
- Rounds to the nearest integer without signaling :const:`Inexact` or
- :const:`Rounded`.
-
-
.. method:: Context.to_sci_string(x)
Converts a number to a string using scientific notation.
@@ -755,7 +1096,7 @@
Typically, clamping occurs when an exponent falls outside the context's
:attr:`Emin` and :attr:`Emax` limits. If possible, the exponent is reduced to
- fit by adding zeroes to the coefficient.
+ fit by adding zeros to the coefficient.
.. class:: DecimalException
@@ -908,7 +1249,7 @@
The number system for the :mod:`decimal` module provides special values
including :const:`NaN`, :const:`sNaN`, :const:`-Infinity`, :const:`Infinity`,
-and two zeroes, :const:`+0` and :const:`-0`.
+and two zeros, :const:`+0` and :const:`-0`.
Infinities can be constructed directly with: ``Decimal('Infinity')``. Also,
they can arise from dividing by zero when the :exc:`DivisionByZero` signal is
Modified: python/branches/py3k-importlib/Doc/library/fileinput.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/fileinput.rst (original)
+++ python/branches/py3k-importlib/Doc/library/fileinput.rst Fri Sep 21 03:17:09 2007
@@ -7,8 +7,9 @@
.. sectionauthor:: Fred L. Drake, Jr. <fdrake at acm.org>
-This module implements a helper class and functions to quickly write a loop over
-standard input or a list of files.
+This module implements a helper class and functions to quickly write a
+loop over standard input or a list of files. If you just want to read or
+write one file see :func:`open`.
The typical use is::
Modified: python/branches/py3k-importlib/Doc/library/functions.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/functions.rst (original)
+++ python/branches/py3k-importlib/Doc/library/functions.rst Fri Sep 21 03:17:09 2007
@@ -746,7 +746,8 @@
Python enforces that the mode, after stripping ``'U'``, begins with ``'r'``,
``'w'`` or ``'a'``.
- See also the :mod:`fileinput` module.
+ See also the :mod:`fileinput` module, the :mod:`os` module, and the
+ :mod:`os.path` module.
.. function:: ord(c)
Modified: python/branches/py3k-importlib/Doc/library/hashlib.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/hashlib.rst (original)
+++ python/branches/py3k-importlib/Doc/library/hashlib.rst Fri Sep 21 03:17:09 2007
@@ -36,7 +36,7 @@
Feeding string objects is to :meth:`update` is not supported, as hashes work
on bytes, not on characters.
-.. index:: single: OpenSSL
+.. index:: single: OpenSSL; (use in module hashlib)
Constructors for hash algorithms that are always present in this module are
:func:`md5`, :func:`sha1`, :func:`sha224`, :func:`sha256`, :func:`sha384`, and
Modified: python/branches/py3k-importlib/Doc/library/operator.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/operator.rst (original)
+++ python/branches/py3k-importlib/Doc/library/operator.rst Fri Sep 21 03:17:09 2007
@@ -47,18 +47,18 @@
truth tests, identity tests, and boolean operations:
-.. function:: not_(o)
- __not__(o)
+.. function:: not_(obj)
+ __not__(obj)
- Return the outcome of :keyword:`not` *o*. (Note that there is no
+ Return the outcome of :keyword:`not` *obj*. (Note that there is no
:meth:`__not__` method for object instances; only the interpreter core defines
this operation. The result is affected by the :meth:`__bool__` and
:meth:`__len__` methods.)
-.. function:: truth(o)
+.. function:: truth(obj)
- Return :const:`True` if *o* is true, and :const:`False` otherwise. This is
+ Return :const:`True` if *obj* is true, and :const:`False` otherwise. This is
equivalent to using the :class:`bool` constructor.
@@ -75,10 +75,10 @@
The mathematical and bitwise operations are the most numerous:
-.. function:: abs(o)
- __abs__(o)
+.. function:: abs(obj)
+ __abs__(obj)
- Return the absolute value of *o*.
+ Return the absolute value of *obj*.
.. function:: add(a, b)
@@ -106,12 +106,12 @@
Return ``a // b``.
-.. function:: inv(o)
- invert(o)
- __inv__(o)
- __invert__(o)
+.. function:: inv(obj)
+ invert(obj)
+ __inv__(obj)
+ __invert__(obj)
- Return the bitwise inverse of the number *o*. This is equivalent to ``~o``.
+ Return the bitwise inverse of the number *obj*. This is equivalent to ``~obj``.
.. function:: lshift(a, b)
@@ -132,10 +132,10 @@
Return ``a * b``, for *a* and *b* numbers.
-.. function:: neg(o)
- __neg__(o)
+.. function:: neg(obj)
+ __neg__(obj)
- Return *o* negated.
+ Return *obj* negated.
.. function:: or_(a, b)
@@ -144,10 +144,10 @@
Return the bitwise or of *a* and *b*.
-.. function:: pos(o)
- __pos__(o)
+.. function:: pos(obj)
+ __pos__(obj)
- Return *o* positive.
+ Return *obj* positive.
.. function:: pow(a, b)
@@ -373,24 +373,30 @@
... pass
...
>>> import operator
- >>> o = C()
- >>> operator.isMappingType(o)
+ >>> obj = C()
+ >>> operator.isMappingType(obj)
True
+.. note::
+
+ Python 3 is expected to introduce abstract base classes for
+ collection types, so it should be possible to write, for example,
+ ``isinstance(obj, collections.Mapping)`` and ``isinstance(obj,
+ collections.Sequence)``.
-.. function:: isCallable(o)
+.. function:: isCallable(obj)
.. deprecated:: 2.0
Use the :func:`callable` built-in function instead.
- Returns true if the object *o* can be called like a function, otherwise it
+ Returns true if the object *obj* can be called like a function, otherwise it
returns false. True is returned for functions, bound and unbound methods, class
objects, and instance objects which support the :meth:`__call__` method.
-.. function:: isMappingType(o)
+.. function:: isMappingType(obj)
- Returns true if the object *o* supports the mapping interface. This is true for
+ Returns true if the object *obj* supports the mapping interface. This is true for
dictionaries and all instance objects defining :meth:`__getitem__`.
.. warning::
@@ -400,9 +406,9 @@
useful than it otherwise might be.
-.. function:: isNumberType(o)
+.. function:: isNumberType(obj)
- Returns true if the object *o* represents a number. This is true for all
+ Returns true if the object *obj* represents a number. This is true for all
numeric types implemented in C.
.. warning::
@@ -412,9 +418,9 @@
useful than it otherwise might be.
-.. function:: isSequenceType(o)
+.. function:: isSequenceType(obj)
- Returns true if the object *o* supports the sequence protocol. This returns true
+ Returns true if the object *obj* supports the sequence protocol. This returns true
for all objects which define sequence methods in C, and for all instance objects
defining :meth:`__getitem__`.
@@ -484,7 +490,7 @@
+-----------------------+-------------------------+---------------------------------+
| Concatenation | ``seq1 + seq2`` | ``concat(seq1, seq2)`` |
+-----------------------+-------------------------+---------------------------------+
-| Containment Test | ``o in seq`` | ``contains(seq, o)`` |
+| Containment Test | ``obj in seq`` | ``contains(seq, obj)`` |
+-----------------------+-------------------------+---------------------------------+
| Division | ``a / b`` | ``div(a, b)`` (without |
| | | ``__future__.division``) |
@@ -508,11 +514,11 @@
+-----------------------+-------------------------+---------------------------------+
| Identity | ``a is not b`` | ``is_not(a, b)`` |
+-----------------------+-------------------------+---------------------------------+
-| Indexed Assignment | ``o[k] = v`` | ``setitem(o, k, v)`` |
+| Indexed Assignment | ``obj[k] = v`` | ``setitem(obj, k, v)`` |
+-----------------------+-------------------------+---------------------------------+
-| Indexed Deletion | ``del o[k]`` | ``delitem(o, k)`` |
+| Indexed Deletion | ``del obj[k]`` | ``delitem(obj, k)`` |
+-----------------------+-------------------------+---------------------------------+
-| Indexing | ``o[k]`` | ``getitem(o, k)`` |
+| Indexing | ``obj[k]`` | ``getitem(obj, k)`` |
+-----------------------+-------------------------+---------------------------------+
| Left Shift | ``a << b`` | ``lshift(a, b)`` |
+-----------------------+-------------------------+---------------------------------+
@@ -534,11 +540,11 @@
+-----------------------+-------------------------+---------------------------------+
| Slicing | ``seq[i:j]`` | ``getslice(seq, i, j)`` |
+-----------------------+-------------------------+---------------------------------+
-| String Formatting | ``s % o`` | ``mod(s, o)`` |
+| String Formatting | ``s % obj`` | ``mod(s, obj)`` |
+-----------------------+-------------------------+---------------------------------+
| Subtraction | ``a - b`` | ``sub(a, b)`` |
+-----------------------+-------------------------+---------------------------------+
-| Truth Test | ``o`` | ``truth(o)`` |
+| Truth Test | ``obj`` | ``truth(obj)`` |
+-----------------------+-------------------------+---------------------------------+
| Ordering | ``a < b`` | ``lt(a, b)`` |
+-----------------------+-------------------------+---------------------------------+
Modified: python/branches/py3k-importlib/Doc/library/os.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/os.rst (original)
+++ python/branches/py3k-importlib/Doc/library/os.rst Fri Sep 21 03:17:09 2007
@@ -8,9 +8,10 @@
This module provides a more portable way of using operating system dependent
functionality than importing a operating system dependent built-in module like
-:mod:`posix` or :mod:`nt`. (If you just want to read or write a file see
-:func:`open`, and if you want to manipulate paths, see the :mod:`os.path`
-module.)
+:mod:`posix` or :mod:`nt`. If you just want to read or write a file see
+:func:`open`, if you want to manipulate paths, see the :mod:`os.path`
+module, and if you want to read all the lines in all the files on the
+command line see the :mod:`fileinput` module.
This module searches for an operating system dependent built-in module like
:mod:`mac` or :mod:`posix` and exports the same functions and data as found
Modified: python/branches/py3k-importlib/Doc/library/simplexmlrpcserver.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/simplexmlrpcserver.rst (original)
+++ python/branches/py3k-importlib/Doc/library/simplexmlrpcserver.rst Fri Sep 21 03:17:09 2007
@@ -142,7 +142,7 @@
import xmlrpclib
- s = xmlrpclib.Server('http://localhost:8000')
+ s = xmlrpclib.ServerProxy('http://localhost:8000')
print(s.pow(2,3)) # Returns 2**3 = 8
print(s.add(2,3)) # Returns 5
print(s.div(5,2)) # Returns 5//2 = 2
Modified: python/branches/py3k-importlib/Doc/library/ssl.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/ssl.rst (original)
+++ python/branches/py3k-importlib/Doc/library/ssl.rst Fri Sep 21 03:17:09 2007
@@ -9,6 +9,10 @@
.. sectionauthor:: Bill Janssen <bill.janssen at gmail.com>
+.. index:: single: OpenSSL; (use in module ssl)
+
+.. index:: TLS, SSL, Transport Layer Security, Secure Sockets Layer
+
This module provides access to Transport Layer Security (often known
as "Secure Sockets Layer") encryption and peer authentication
facilities for network sockets, both client-side and server-side.
@@ -19,18 +23,125 @@
.. note::
Some behavior may be platform dependent, since calls are made to the operating
- system socket APIs.
+ system socket APIs. The installed version of OpenSSL may also cause
+ variations in behavior.
This section documents the objects and functions in the ``ssl`` module;
for more general information about TLS, SSL, and certificates, the
-reader is referred to the documents in the :ref:`ssl-references` section.
+reader is referred to the documents in the "See Also" section at
+the bottom.
-This module defines a class, :class:`ssl.sslsocket`, which is
-derived from the :class:`socket.socket` type, and supports additional
+This module provides a class, :class:`ssl.SSLSocket`, which is
+derived from the :class:`socket.socket` type, and provides
+a socket-like wrapper that also encrypts and decrypts the data
+going over the socket with SSL. It supports additional
:meth:`read` and :meth:`write` methods, along with a method, :meth:`getpeercert`,
-to retrieve the certificate of the other side of the connection.
+to retrieve the certificate of the other side of the connection, and
+a method, :meth:`cipher`, to retrieve the cipher being used for the
+secure connection.
+
+Functions, Constants, and Exceptions
+------------------------------------
+
+.. exception:: SSLError
+
+ Raised to signal an error from the underlying SSL implementation. This
+ signifies some problem in the higher-level
+ encryption and authentication layer that's superimposed on the underlying
+ network connection. This error is a subtype of :exc:`socket.error`, which
+ in turn is a subtype of :exc:`IOError`.
+
+.. function:: wrap_socket (sock, keyfile=None, certfile=None, server_side=False, cert_reqs=CERT_NONE, ssl_version={see docs}, ca_certs=None)
+
+ Takes an instance ``sock`` of :class:`socket.socket`, and returns an instance of :class:`ssl.SSLSocket`, a subtype
+ of :class:`socket.socket`, which wraps the underlying socket in an SSL context.
+ For client-side sockets, the context construction is lazy; if the underlying socket isn't
+ connected yet, the context construction will be performed after :meth:`connect` is called
+ on the socket. For server-side sockets, if the socket has no remote peer, it is assumed
+ to be a listening socket, and the server-side SSL wrapping is automatically performed
+ on client connections accepted via the :meth:`accept` method. :func:`wrap_socket` may
+ raise :exc:`SSLError`.
+
+ The ``keyfile`` and ``certfile`` parameters specify optional files which contain a certificate
+ to be used to identify the local side of the connection. See the discussion of :ref:`ssl-certificates`
+ for more information on how the certificate is stored in the ``certfile``.
+
+ Often the private key is stored
+ in the same file as the certificate; in this case, only the ``certfile`` parameter need be
+ passed. If the private key is stored in a separate file, both parameters must be used.
+ If the private key is stored in the ``certfile``, it should come before the first certificate
+ in the certificate chain::
+
+ -----BEGIN RSA PRIVATE KEY-----
+ ... (private key in base64 encoding) ...
+ -----END RSA PRIVATE KEY-----
+ -----BEGIN CERTIFICATE-----
+ ... (certificate in base64 PEM encoding) ...
+ -----END CERTIFICATE-----
+
+ The parameter ``server_side`` is a boolean which identifies whether server-side or client-side
+ behavior is desired from this socket.
-This module defines the following functions, exceptions, and constants:
+ The parameter ``cert_reqs`` specifies whether a certificate is
+ required from the other side of the connection, and whether it will
+ be validated if provided. It must be one of the three values
+ :const:`CERT_NONE` (certificates ignored), :const:`CERT_OPTIONAL` (not required,
+ but validated if provided), or :const:`CERT_REQUIRED` (required and
+ validated). If the value of this parameter is not :const:`CERT_NONE`, then
+ the ``ca_certs`` parameter must point to a file of CA certificates.
+
+ The ``ca_certs`` file contains a set of concatenated "certification authority" certificates,
+ which are used to validate certificates passed from the other end of the connection.
+ See the discussion of :ref:`ssl-certificates` for more information about how to arrange
+ the certificates in this file.
+
+ The parameter ``ssl_version`` specifies which version of the SSL protocol to use.
+ Typically, the server chooses a particular protocol version, and the client
+ must adapt to the server's choice. Most of the versions are not interoperable
+ with the other versions. If not specified, for client-side operation, the
+ default SSL version is SSLv3; for server-side operation, SSLv23. These
+ version selections provide the most compatibility with other versions.
+
+ Here's a table showing which versions in a client (down the side)
+ can connect to which versions in a server (along the top):
+
+ .. table::
+
+ ======================== ========= ========= ========== =========
+ *client* / **server** **SSLv2** **SSLv3** **SSLv23** **TLSv1**
+ *SSLv2* yes no yes* no
+ *SSLv3* yes yes yes no
+ *SSLv23* yes no yes no
+ *TLSv1* no no yes yes
+ ======================== ========= ========= ========== =========
+
+ `*` In some older versions of OpenSSL (for instance, 0.9.7l on OS X 10.4),
+ an SSLv2 client could not connect to an SSLv23 server.
+
+.. function:: RAND_status()
+
+ Returns True if the SSL pseudo-random number generator has been
+ seeded with 'enough' randomness, and False otherwise. You can use
+ :func:`ssl.RAND_egd` and :func:`ssl.RAND_add` to increase the randomness
+ of the pseudo-random number generator.
+
+.. function:: RAND_egd(path)
+
+ If you are running an entropy-gathering daemon (EGD) somewhere, and ``path``
+ is the pathname of a socket connection open to it, this will read
+ 256 bytes of randomness from the socket, and add it to the SSL pseudo-random number generator
+ to increase the security of generated secret keys. This is typically only
+ necessary on systems without better sources of randomness.
+
+ See http://egd.sourceforge.net/ or http://prngd.sourceforge.net/ for
+ sources of entropy-gathering daemons.
+
+.. function:: RAND_add(bytes, entropy)
+
+ Mixes the given ``bytes`` into the SSL pseudo-random number generator.
+ The parameter ``entropy`` (a float) is a lower bound on the entropy
+ contained in string (so you can always use :const:`0.0`).
+ See :rfc:`1750` for more information on sources of entropy.
.. function:: cert_time_to_seconds(timestring)
@@ -48,12 +159,27 @@
'Wed May 9 00:00:00 2007'
>>>
-.. exception:: sslerror
+.. function:: get_server_certificate (addr, ssl_version=PROTOCOL_SSLv3, ca_certs=None)
- Raised to signal an error from the underlying SSL implementation. This
- signifies some problem in the higher-level
- encryption and authentication layer that's superimposed on the underlying
- network connection.
+ Given the address ``addr`` of an SSL-protected server, as a
+ (*hostname*, *port-number*) pair, fetches the server's certificate,
+ and returns it as a PEM-encoded string. If ``ssl_version`` is
+ specified, uses that version of the SSL protocol to attempt to
+ connect to the server. If ``ca_certs`` is specified, it should be
+ a file containing a list of root certificates, the same format as
+ used for the same parameter in :func:`wrap_socket`. The call will
+ attempt to validate the server certificate against that set of root
+ certificates, and will fail if the validation attempt fails.
+
+.. function:: DER_cert_to_PEM_cert (DER_cert_bytes)
+
+ Given a certificate as a DER-encoded blob of bytes, returns a PEM-encoded
+ string version of the same certificate.
+
+.. function:: PEM_cert_to_DER_cert (PEM_cert_string)
+
+ Given a certificate as an ASCII PEM string, returns a DER-encoded
+ sequence of bytes for that same certificate.
.. data:: CERT_NONE
@@ -84,13 +210,16 @@
.. data:: PROTOCOL_SSLv23
- Selects SSL version 2 or 3 as the channel encryption protocol. This is a setting to use for maximum compatibility
- with the other end of an SSL connection, but it may cause the specific ciphers chosen for the encryption to be
- of fairly low quality.
+ Selects SSL version 2 or 3 as the channel encryption protocol.
+ This is a setting to use with servers for maximum compatibility
+ with the other end of an SSL connection, but it may cause the
+ specific ciphers chosen for the encryption to be of fairly low
+ quality.
.. data:: PROTOCOL_SSLv3
Selects SSL version 3 as the channel encryption protocol.
+ For clients, this is the maximally compatible SSL variant.
.. data:: PROTOCOL_TLSv1
@@ -99,6 +228,69 @@
protection, if both sides can speak it.
+SSLSocket Objects
+-----------------
+
+.. method:: SSLSocket.read([nbytes=1024])
+
+ Reads up to ``nbytes`` bytes from the SSL-encrypted channel and returns them.
+
+.. method:: SSLSocket.write(data)
+
+ Writes the ``data`` to the other side of the connection, using the
+ SSL channel to encrypt. Returns the number of bytes written.
+
+.. method:: SSLSocket.getpeercert(binary_form=False)
+
+ If there is no certificate for the peer on the other end of the
+ connection, returns ``None``.
+
+ If the the parameter ``binary_form`` is :const:`False`, and a
+ certificate was received from the peer, this method returns a
+ :class:`dict` instance. If the certificate was not validated, the
+ dict is empty. If the certificate was validated, it returns a dict
+ with the keys ``subject`` (the principal for which the certificate
+ was issued), and ``notAfter`` (the time after which the certificate
+ should not be trusted). The certificate was already validated, so
+ the ``notBefore`` and ``issuer`` fields are not returned. If a
+ certificate contains an instance of the *Subject Alternative Name*
+ extension (see :rfc:`3280`), there will also be a
+ ``subjectAltName`` key in the dictionary.
+
+ The "subject" field is a tuple containing the sequence of relative
+ distinguished names (RDNs) given in the certificate's data
+ structure for the principal, and each RDN is a sequence of
+ name-value pairs::
+
+ {'notAfter': 'Feb 16 16:54:50 2013 GMT',
+ 'subject': ((('countryName', u'US'),),
+ (('stateOrProvinceName', u'Delaware'),),
+ (('localityName', u'Wilmington'),),
+ (('organizationName', u'Python Software Foundation'),),
+ (('organizationalUnitName', u'SSL'),),
+ (('commonName', u'somemachine.python.org'),))}
+
+ If the ``binary_form`` parameter is :const:`True`, and a
+ certificate was provided, this method returns the DER-encoded form
+ of the entire certificate as a sequence of bytes, or :const:`None` if the
+ peer did not provide a certificate. This return
+ value is independent of validation; if validation was required
+ (:const:`CERT_OPTIONAL` or :const:`CERT_REQUIRED`), it will have
+ been validated, but if :const:`CERT_NONE` was used to establish the
+ connection, the certificate, if present, will not have been validated.
+
+.. method:: SSLSocket.cipher()
+
+ Returns a three-value tuple containing the name of the cipher being
+ used, the version of the SSL protocol that defines its use, and the
+ number of secret bits being used. If no connection has been
+ established, returns ``None``.
+
+
+.. index:: single: certificates
+
+.. index:: single: X509 certificate
+
.. _ssl-certificates:
Certificates
@@ -127,8 +319,12 @@
side of a network connection can also be required to produce a certificate,
and that certificate can be validated to the satisfaction
of the client or server that requires such validation.
-The connection can be set to fail automatically if such
-validation is not achieved.
+The connection attempt can be set to raise an exception if
+the validation fails. Validation is done
+automatically, by the underlying OpenSSL framework; the
+application need not concern itself with its mechanics.
+But the application does usually need to provide
+sets of certificates to allow this process to take place.
Python uses files to contain certificates. They should be formatted
as "PEM" (see :rfc:`1422`), which is a base-64 encoded form wrapped
@@ -167,108 +363,55 @@
chains for each issuer you are willing to trust. Again, this file just
contains these chains concatenated together. For validation, Python will
use the first chain it finds in the file which matches.
-Some "standard" root certificates are available at
-http://www.thawte.com/roots/ (for Thawte roots) and
-http://www.verisign.com/support/roots.html (for Verisign roots).
-See also :rfc:`4158` for more discussion of the way in which
+Some "standard" root certificates are available from various certification
+authorities:
+`CACert.org <http://www.cacert.org/index.php?id=3>`_,
+`Thawte <http://www.thawte.com/roots/>`_,
+`Verisign <http://www.verisign.com/support/roots.html>`_,
+`Positive SSL <http://www.PositiveSSL.com/ssl-certificate-support/cert_installation/UTN-USERFirst-Hardware.crt>`_ (used by python.org),
+`Equifax and GeoTrust <http://www.geotrust.com/resources/root_certificates/index.asp>`_.
+
+In general, if you are using
+SSL3 or TLS1, you don't need to put the full chain in your "CA certs" file;
+you only need the root certificates, and the remote peer is supposed to
+furnish the other certificates necessary to chain from its certificate to
+a root certificate.
+See :rfc:`4158` for more discussion of the way in which
certification chains can be built.
-
-sslsocket Objects
------------------
-
-.. class:: sslsocket(sock [, keyfile=None, certfile=None, server_side=False, cert_reqs=CERT_NONE, ssl_version=PROTOCOL_SSLv23, ca_certs=None])
-
- Takes an instance ``sock`` of :class:`socket.socket`, and returns an instance of a subtype
- of :class:`socket.socket` which wraps the underlying socket in an SSL context.
- For client-side sockets, the context construction is lazy; if the underlying socket isn't
- connected yet, the context construction will be performed after :meth:`connect` is called
- on the socket.
-
- The ``keyfile`` and ``certfile`` parameters specify optional files which contain a certificate
- to be used to identify the local side of the connection. See the above discussion of :ref:`ssl-certificates`
- for more information on how the certificate is stored in the ``certfile``.
-
- Often the private key is stored
- in the same file as the certificate; in this case, only the ``certfile`` parameter need be
- passed. If the private key is stored in a separate file, both parameters must be used.
- If the private key is stored in the ``certfile``, it should come before the first certificate
- in the certificate chain::
-
- -----BEGIN RSA PRIVATE KEY-----
- ... (private key in base64 encoding) ...
- -----END RSA PRIVATE KEY-----
- -----BEGIN CERTIFICATE-----
- ... (certificate in base64 PEM encoding) ...
- -----END CERTIFICATE-----
-
- The parameter ``server_side`` is a boolean which identifies whether server-side or client-side
- behavior is desired from this socket.
-
- The parameter ``cert_reqs`` specifies whether a certificate is
- required from the other side of the connection, and whether it will
- be validated if provided. It must be one of the three values
- :const:`CERT_NONE` (certificates ignored), :const:`CERT_OPTIONAL` (not required,
- but validated if provided), or :const:`CERT_REQUIRED` (required and
- validated). If the value of this parameter is not :const:`CERT_NONE`, then
- the ``ca_certs`` parameter must point to a file of CA certificates.
-
- The parameter ``ssl_version`` specifies which version of the SSL protocol to use. Typically,
- the server specifies this, and a client connecting to it must use the same protocol. An
- SSL server using :const:`PROTOCOL_SSLv23` can understand a client connecting via SSL2, SSL3, or TLS1,
- but a client using :const:`PROTOCOL_SSLv23` can only connect to an SSL2 server.
-
- The ``ca_certs`` file contains a set of concatenated "certification authority" certificates,
- which are used to validate certificates passed from the other end of the connection.
- See the above discussion of :ref:`ssl-certificates` for more information about how to arrange
- the certificates in this file.
-
-.. method:: sslsocket.read([nbytes])
-
- Reads up to ``nbytes`` bytes from the SSL-encrypted channel and returns them.
-
-.. method:: sslsocket.write(data)
-
- Writes the ``data`` to the other side of the connection, using the SSL channel to encrypt. Returns the number
- of bytes written.
-
-.. method:: sslsocket.getpeercert()
-
- If there is no certificate for the peer on the other end of the connection, returns ``None``.
- If a certificate was received from the peer, but not validated, returns an empty ``dict`` instance.
- If a certificate was received and validated, returns a ``dict`` instance with the fields
- ``subject`` (the principal for which the certificate was issued), ``issuer`` (the signer of
- the certificate), ``notBefore`` (the time before which the certificate should not be trusted),
- and ``notAfter`` (the time after which the certificate should not be trusted) filled in.
-
- The "subject" and "issuer" fields are tuples containing the name-value fields
- given in the certificate's data structure for each principal::
-
- {'issuer': (('countryName', u'US'),
- ('stateOrProvinceName', u'Delaware'),
- ('localityName', u'Wilmington'),
- ('organizationName', u'Python Software Foundation'),
- ('organizationalUnitName', u'SSL'),
- ('commonName', u'somemachine.python.org')),
- 'notAfter': 'Feb 16 16:54:50 2013 GMT',
- 'notBefore': 'Aug 27 16:54:50 2007 GMT',
- 'subject': (('countryName', u'US'),
- ('stateOrProvinceName', u'Delaware'),
- ('localityName', u'Wilmington'),
- ('organizationName', u'Python Software Foundation'),
- ('organizationalUnitName', u'SSL'),
- ('commonName', u'somemachine.python.org')),
- 'version': 2}
-
- This certificate is said to be *self-signed*, because the subject
- and issuer are the same entity. The *version* field refers to the X509 version
- that's used for the certificate.
-
-.. method:: sslsocket.ssl_shutdown()
-
- Closes the SSL context (if any) over the socket, but leaves the socket connection
- open for further use, if both sides are willing. This is different from :meth:`socket.socket.shutdown`,
- which will close the connection, but leave the local socket available for further use.
+If you are going to create a server that provides SSL-encrypted
+connection services, you will need to acquire a certificate for that
+service. There are many ways of acquiring appropriate certificates,
+such as buying one from a certification authority. Another common
+practice is to generate a self-signed certificate. The simplest
+way to do this is with the OpenSSL package, using something like
+the following::
+
+ % openssl req -new -x509 -days 365 -nodes -out cert.pem -keyout cert.pem
+ Generating a 1024 bit RSA private key
+ .......++++++
+ .............................++++++
+ writing new private key to 'cert.pem'
+ -----
+ You are about to be asked to enter information that will be incorporated
+ into your certificate request.
+ What you are about to enter is what is called a Distinguished Name or a DN.
+ There are quite a few fields but you can leave some blank
+ For some fields there will be a default value,
+ If you enter '.', the field will be left blank.
+ -----
+ Country Name (2 letter code) [AU]:US
+ State or Province Name (full name) [Some-State]:MyState
+ Locality Name (eg, city) []:Some City
+ Organization Name (eg, company) [Internet Widgits Pty Ltd]:My Organization, Inc.
+ Organizational Unit Name (eg, section) []:My Group
+ Common Name (eg, YOUR name) []:myserver.mygroup.myorganization.com
+ Email Address []:ops at myserver.mygroup.myorganization.com
+ %
+
+The disadvantage of a self-signed certificate is that it is its
+own root certificate, and no one else will have it in their cache
+of known (and trusted) root certificates.
Examples
@@ -295,12 +438,17 @@
import socket, ssl, pprint
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- ssl_sock = ssl.sslsocket(s, ca_certs="/etc/ca_certs_file", cert_reqs=ssl.CERT_REQUIRED)
+
+ # require a certificate from the server
+ ssl_sock = ssl.wrap_socket(s,
+ ca_certs="/etc/ca_certs_file",
+ cert_reqs=ssl.CERT_REQUIRED)
ssl_sock.connect(('www.verisign.com', 443))
print(repr(ssl_sock.getpeername()))
pprint.pprint(ssl_sock.getpeercert())
+ print(pprint.pformat(ssl_sock.getpeercert()))
# Set a simple HTTP request -- use httplib in actual code.
ssl_sock.write("""GET / HTTP/1.0\r
@@ -310,35 +458,29 @@
# read all the data returned by the server.
data = ssl_sock.read()
- # note that closing the sslsocket will also close the underlying socket
+ # note that closing the SSLSocket will also close the underlying socket
ssl_sock.close()
-As of September 4, 2007, the certificate printed by this program
+As of September 6, 2007, the certificate printed by this program
looked like this::
- {'issuer': (('countryName', u'US'),
- ('organizationName', u'VeriSign, Inc.'),
- ('organizationalUnitName', u'VeriSign Trust Network'),
- ('organizationalUnitName',
- u'Terms of use at https://www.verisign.com/rpa (c)06'),
- ('commonName',
- u'VeriSign Class 3 Extended Validation SSL SGC CA')),
- 'notAfter': 'May 8 23:59:59 2009 GMT',
- 'notBefore': 'May 9 00:00:00 2007 GMT',
- 'subject': (('serialNumber', u'2497886'),
- ('1.3.6.1.4.1.311.60.2.1.3', u'US'),
- ('1.3.6.1.4.1.311.60.2.1.2', u'Delaware'),
- ('countryName', u'US'),
- ('postalCode', u'94043'),
- ('stateOrProvinceName', u'California'),
- ('localityName', u'Mountain View'),
- ('streetAddress', u'487 East Middlefield Road'),
- ('organizationName', u'VeriSign, Inc.'),
- ('organizationalUnitName', u'Production Security Services'),
- ('organizationalUnitName',
- u'Terms of use at www.verisign.com/rpa (c)06'),
- ('commonName', u'www.verisign.com')),
- 'version': 2}
+ {'notAfter': 'May 8 23:59:59 2009 GMT',
+ 'subject': ((('serialNumber', u'2497886'),),
+ (('1.3.6.1.4.1.311.60.2.1.3', u'US'),),
+ (('1.3.6.1.4.1.311.60.2.1.2', u'Delaware'),),
+ (('countryName', u'US'),),
+ (('postalCode', u'94043'),),
+ (('stateOrProvinceName', u'California'),),
+ (('localityName', u'Mountain View'),),
+ (('streetAddress', u'487 East Middlefield Road'),),
+ (('organizationName', u'VeriSign, Inc.'),),
+ (('organizationalUnitName',
+ u'Production Security Services'),),
+ (('organizationalUnitName',
+ u'Terms of use at www.verisign.com/rpa (c)06'),),
+ (('commonName', u'www.verisign.com'),))}
+
+which is a fairly poorly-formed ``subject`` field.
Server-side operation
^^^^^^^^^^^^^^^^^^^^^
@@ -354,12 +496,15 @@
bindsocket.listen(5)
When one did, you'd call :meth:`accept` on the socket to get the new socket from the other
-end, and use :func:`sslsocket` to create a server-side SSL context for it::
+end, and use :func:`wrap_socket` to create a server-side SSL context for it::
while True:
newsocket, fromaddr = bindsocket.accept()
- connstream = ssl.sslsocket(newsocket, server_side=True, certfile="mycertfile",
- keyfile="mykeyfile", ssl_protocol=ssl.PROTOCOL_TLSv1)
+ connstream = ssl.wrap_socket(newsocket,
+ server_side=True,
+ certfile="mycertfile",
+ keyfile="mykeyfile",
+ ssl_protocol=ssl.PROTOCOL_TLSv1)
deal_with_client(connstream)
Then you'd read data from the ``connstream`` and do something with it till you are finished with the client (or the client is finished with you)::
@@ -370,7 +515,8 @@
# null data means the client is finished with us
while data:
if not do_something(connstream, data):
- # we'll assume do_something returns False when we're finished with client
+ # we'll assume do_something returns False
+ # when we're finished with client
break
data = connstream.read()
# finished with client
@@ -379,16 +525,19 @@
And go back to listening for new client connections.
-.. _ssl-references:
+.. seealso::
-References
-----------
+ Class :class:`socket.socket`
+ Documentation of underlying :mod:`socket` class
-Class :class:`socket.socket`
- Documentation of underlying :mod:`socket` class
+ `Introducing SSL and Certificates using OpenSSL <http://old.pseudonym.org/ssl/wwwj-index.html>`_
+ Frederick J. Hirsch
-`Introducing SSL and Certificates using OpenSSL <http://old.pseudonym.org/ssl/wwwj-index.html>`_, by Frederick J. Hirsch
+ `RFC 1422: Privacy Enhancement for Internet Electronic Mail: Part II: Certificate-Based Key Management <http://www.ietf.org/rfc/rfc1422>`_
+ Steve Kent
-`Privacy Enhancement for Internet Electronic Mail: Part II: Certificate-Based Key Management`, :rfc:`1422`, by Steve Kent
+ `RFC 1750: Randomness Recommendations for Security <http://www.ietf.org/rfc/rfc1750>`_
+ D. Eastlake et. al.
-`Internet X.509 Public Key Infrastructure Certificate and CRL Profile`, :rfc:`3280`, Housley et. al.
+ `RFC 3280: Internet X.509 Public Key Infrastructure Certificate and CRL Profile <http://www.ietf.org/rfc/rfc3280>`_
+ Housley et. al.
Modified: python/branches/py3k-importlib/Doc/library/stdtypes.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/stdtypes.rst (original)
+++ python/branches/py3k-importlib/Doc/library/stdtypes.rst Fri Sep 21 03:17:09 2007
@@ -657,10 +657,13 @@
.. index:: pair: string; methods
-String objects support the methods listed below. In addition, Python's strings
-support the sequence type methods described in the :ref:`typesseq` section. To
-output formatted strings, see the :ref:`string-formatting` section. Also, see
-the :mod:`re` module for string functions based on regular expressions.
+String objects support the methods listed below. Note that none of these
+methods take keyword arguments.
+
+In addition, Python's strings support the sequence type methods described in
+the :ref:`typesseq` section. To output formatted strings, see the
+:ref:`string-formatting` section. Also, see the :mod:`re` module for string
+functions based on regular expressions.
.. method:: str.capitalize()
Modified: python/branches/py3k-importlib/Doc/library/undoc.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/library/undoc.rst (original)
+++ python/branches/py3k-importlib/Doc/library/undoc.rst Fri Sep 21 03:17:09 2007
@@ -19,9 +19,6 @@
Some of these are very old and/or not very robust; marked with "hmm."
-:mod:`bdb`
- --- A generic Python debugger base class (used by pdb).
-
:mod:`ihooks`
--- Import hook support (for :mod:`rexec`; may become obsolete).
Modified: python/branches/py3k-importlib/Doc/reference/index.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/reference/index.rst (original)
+++ python/branches/py3k-importlib/Doc/reference/index.rst Fri Sep 21 03:17:09 2007
@@ -17,7 +17,7 @@
interfaces available to C/C++ programmers in detail.
.. toctree::
- :maxdepth: 2
+ :maxdepth: 3
introduction.rst
lexical_analysis.rst
Modified: python/branches/py3k-importlib/Doc/reference/simple_stmts.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/reference/simple_stmts.rst (original)
+++ python/branches/py3k-importlib/Doc/reference/simple_stmts.rst Fri Sep 21 03:17:09 2007
@@ -62,47 +62,6 @@
standard output on a line by itself (except if the result is ``None``, so that
procedure calls do not cause any output.)
-
-.. _assert:
-
-Assert statements
-=================
-
-.. index::
- statement: assert
- pair: debugging; assertions
- single: __debug__
- exception: AssertionError
-
-Assert statements are a convenient way to insert debugging assertions into a
-program:
-
-.. productionlist::
- assert_stmt: "assert" `expression` ["," `expression`]
-
-The simple form, ``assert expression``, is equivalent to ::
-
- if __debug__:
- if not expression: raise AssertionError
-
-The extended form, ``assert expression1, expression2``, is equivalent to ::
-
- if __debug__:
- if not expression1: raise AssertionError(expression2)
-
-These equivalences assume that :data:`__debug__` and :exc:`AssertionError` refer
-to the built-in variables with those names. In the current implementation, the
-built-in variable :data:`__debug__` is ``True`` under normal circumstances,
-``False`` when optimization is requested (command line option ``-O``). The
-current code generator emits no code for an assert statement when optimization
-is requested at compile time. Note that it is unnecessary to include the source
-code for the expression that failed in the error message; it will be displayed
-as part of the stack trace.
-
-Assignments to :data:`__debug__` are illegal. The value for the built-in
-variable is determined when the interpreter starts.
-
-
.. _assignment:
Assignment statements
@@ -308,6 +267,48 @@
a.x += 1 # writes a.x as 4 leaving A.x as 3
+.. _assert:
+
+The :keyword:`assert` statement
+===============================
+
+.. index::
+ statement: assert
+ pair: debugging; assertions
+
+Assert statements are a convenient way to insert debugging assertions into a
+program:
+
+.. productionlist::
+ assert_stmt: "assert" `expression` ["," `expression`]
+
+The simple form, ``assert expression``, is equivalent to ::
+
+ if __debug__:
+ if not expression: raise AssertionError
+
+The extended form, ``assert expression1, expression2``, is equivalent to ::
+
+ if __debug__:
+ if not expression1: raise AssertionError, expression2
+
+.. index::
+ single: __debug__
+ exception: AssertionError
+
+These equivalences assume that ``__debug__`` and :exc:`AssertionError` refer to
+the built-in variables with those names. In the current implementation, the
+built-in variable ``__debug__`` is ``True`` under normal circumstances,
+``False`` when optimization is requested (command line option -O). The current
+code generator emits no code for an assert statement when optimization is
+requested at compile time. Note that it is unnecessary to include the source
+code for the expression that failed in the error message; it will be displayed
+as part of the stack trace.
+
+Assignments to ``__debug__`` are illegal. The value for the built-in variable
+is determined when the interpreter starts.
+
+
.. _pass:
The :keyword:`pass` statement
Modified: python/branches/py3k-importlib/Doc/tutorial/inputoutput.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/tutorial/inputoutput.rst (original)
+++ python/branches/py3k-importlib/Doc/tutorial/inputoutput.rst Fri Sep 21 03:17:09 2007
@@ -252,7 +252,7 @@
>>> f.readlines()
['This is the first line of the file.\n', 'Second line of the file\n']
-An alternate approach to reading lines is to loop over the file object. This is
+An alternative approach to reading lines is to loop over the file object. This is
memory efficient, fast, and leads to simpler code::
>>> for line in f:
Modified: python/branches/py3k-importlib/Doc/whatsnew/2.5.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/whatsnew/2.5.rst (original)
+++ python/branches/py3k-importlib/Doc/whatsnew/2.5.rst Fri Sep 21 03:17:09 2007
@@ -637,7 +637,7 @@
print v.sqrt()
-.. _context-managers:
+.. _new-25-context-managers:
Writing Context Managers
------------------------
Modified: python/branches/py3k-importlib/Doc/whatsnew/2.6.rst
==============================================================================
--- python/branches/py3k-importlib/Doc/whatsnew/2.6.rst (original)
+++ python/branches/py3k-importlib/Doc/whatsnew/2.6.rst Fri Sep 21 03:17:09 2007
@@ -2,6 +2,9 @@
What's New in Python 2.6
****************************
+.. % XXX mention switch to reST for documentation
+.. % XXX mention switch to Roundup for bug tracking
+
:Author: A.M. Kuchling
:Release: |release|
:Date: |today|
@@ -67,12 +70,367 @@
.. % sets module deprecated
.. % ======================================================================
+Python 3.0
+================
+
+.. % XXX add general comment about Python 3.0 features in 2.6
+
+.. % XXX mention -3 switch
+
+A new command-line switch, :option:`-3`, enables warnings
+about features that will be removed in Python 3.0. You can run code
+with this switch to see how much work will be necessary to port
+code to 3.0.
+
+.. seealso::
+
+ The 3xxx series of PEPs, which describes the development process for
+ Python 3.0 and various features that have been accepted, rejected,
+ or are still under consideration.
+
+PEP 343: The 'with' statement
+=============================
+
+The previous version, Python 2.5, added the ':keyword:`with`'
+statement an optional feature, to be enabled by a ``from __future__
+import generators`` directive. In 2.6 the statement no longer need to
+be specially enabled; this means that :keyword:`with` is now always a
+keyword. The rest of this section is a copy of the corresponding
+section from "What's New in Python 2.5" document; if you read
+it back when Python 2.5 came out, you can skip the rest of this
+section.
+
+The ':keyword:`with`' statement clarifies code that previously would use
+``try...finally`` blocks to ensure that clean-up code is executed. In this
+section, I'll discuss the statement as it will commonly be used. In the next
+section, I'll examine the implementation details and show how to write objects
+for use with this statement.
+
+The ':keyword:`with`' statement is a new control-flow structure whose basic
+structure is::
+
+ with expression [as variable]:
+ with-block
+
+The expression is evaluated, and it should result in an object that supports the
+context management protocol (that is, has :meth:`__enter__` and :meth:`__exit__`
+methods.
+
+The object's :meth:`__enter__` is called before *with-block* is executed and
+therefore can run set-up code. It also may return a value that is bound to the
+name *variable*, if given. (Note carefully that *variable* is *not* assigned
+the result of *expression*.)
+
+After execution of the *with-block* is finished, the object's :meth:`__exit__`
+method is called, even if the block raised an exception, and can therefore run
+clean-up code.
+
+Some standard Python objects now support the context management protocol and can
+be used with the ':keyword:`with`' statement. File objects are one example::
+
+ with open('/etc/passwd', 'r') as f:
+ for line in f:
+ print line
+ ... more processing code ...
+
+After this statement has executed, the file object in *f* will have been
+automatically closed, even if the :keyword:`for` loop raised an exception part-
+way through the block.
+
+.. note::
+
+ In this case, *f* is the same object created by :func:`open`, because
+ :meth:`file.__enter__` returns *self*.
+
+The :mod:`threading` module's locks and condition variables also support the
+':keyword:`with`' statement::
+
+ lock = threading.Lock()
+ with lock:
+ # Critical section of code
+ ...
+
+The lock is acquired before the block is executed and always released once the
+block is complete.
+
+The new :func:`localcontext` function in the :mod:`decimal` module makes it easy
+to save and restore the current decimal context, which encapsulates the desired
+precision and rounding characteristics for computations::
+
+ from decimal import Decimal, Context, localcontext
+
+ # Displays with default precision of 28 digits
+ v = Decimal('578')
+ print v.sqrt()
+
+ with localcontext(Context(prec=16)):
+ # All code in this block uses a precision of 16 digits.
+ # The original context is restored on exiting the block.
+ print v.sqrt()
+
+
+.. _new-26-context-managers:
+
+Writing Context Managers
+------------------------
+
+Under the hood, the ':keyword:`with`' statement is fairly complicated. Most
+people will only use ':keyword:`with`' in company with existing objects and
+don't need to know these details, so you can skip the rest of this section if
+you like. Authors of new objects will need to understand the details of the
+underlying implementation and should keep reading.
+
+A high-level explanation of the context management protocol is:
+
+* The expression is evaluated and should result in an object called a "context
+ manager". The context manager must have :meth:`__enter__` and :meth:`__exit__`
+ methods.
+
+* The context manager's :meth:`__enter__` method is called. The value returned
+ is assigned to *VAR*. If no ``'as VAR'`` clause is present, the value is simply
+ discarded.
+
+* The code in *BLOCK* is executed.
+
+* If *BLOCK* raises an exception, the :meth:`__exit__(type, value, traceback)`
+ is called with the exception details, the same values returned by
+ :func:`sys.exc_info`. The method's return value controls whether the exception
+ is re-raised: any false value re-raises the exception, and ``True`` will result
+ in suppressing it. You'll only rarely want to suppress the exception, because
+ if you do the author of the code containing the ':keyword:`with`' statement will
+ never realize anything went wrong.
+
+* If *BLOCK* didn't raise an exception, the :meth:`__exit__` method is still
+ called, but *type*, *value*, and *traceback* are all ``None``.
+
+Let's think through an example. I won't present detailed code but will only
+sketch the methods necessary for a database that supports transactions.
+
+(For people unfamiliar with database terminology: a set of changes to the
+database are grouped into a transaction. Transactions can be either committed,
+meaning that all the changes are written into the database, or rolled back,
+meaning that the changes are all discarded and the database is unchanged. See
+any database textbook for more information.)
+
+Let's assume there's an object representing a database connection. Our goal will
+be to let the user write code like this::
+
+ db_connection = DatabaseConnection()
+ with db_connection as cursor:
+ cursor.execute('insert into ...')
+ cursor.execute('delete from ...')
+ # ... more operations ...
+
+The transaction should be committed if the code in the block runs flawlessly or
+rolled back if there's an exception. Here's the basic interface for
+:class:`DatabaseConnection` that I'll assume::
+
+ class DatabaseConnection:
+ # Database interface
+ def cursor (self):
+ "Returns a cursor object and starts a new transaction"
+ def commit (self):
+ "Commits current transaction"
+ def rollback (self):
+ "Rolls back current transaction"
+
+The :meth:`__enter__` method is pretty easy, having only to start a new
+transaction. For this application the resulting cursor object would be a useful
+result, so the method will return it. The user can then add ``as cursor`` to
+their ':keyword:`with`' statement to bind the cursor to a variable name. ::
+
+ class DatabaseConnection:
+ ...
+ def __enter__ (self):
+ # Code to start a new transaction
+ cursor = self.cursor()
+ return cursor
+
+The :meth:`__exit__` method is the most complicated because it's where most of
+the work has to be done. The method has to check if an exception occurred. If
+there was no exception, the transaction is committed. The transaction is rolled
+back if there was an exception.
+
+In the code below, execution will just fall off the end of the function,
+returning the default value of ``None``. ``None`` is false, so the exception
+will be re-raised automatically. If you wished, you could be more explicit and
+add a :keyword:`return` statement at the marked location. ::
+
+ class DatabaseConnection:
+ ...
+ def __exit__ (self, type, value, tb):
+ if tb is None:
+ # No exception, so commit
+ self.commit()
+ else:
+ # Exception occurred, so rollback.
+ self.rollback()
+ # return False
+
+
+.. _module-contextlib:
+
+The contextlib module
+---------------------
+
+The new :mod:`contextlib` module provides some functions and a decorator that
+are useful for writing objects for use with the ':keyword:`with`' statement.
+
+The decorator is called :func:`contextmanager`, and lets you write a single
+generator function instead of defining a new class. The generator should yield
+exactly one value. The code up to the :keyword:`yield` will be executed as the
+:meth:`__enter__` method, and the value yielded will be the method's return
+value that will get bound to the variable in the ':keyword:`with`' statement's
+:keyword:`as` clause, if any. The code after the :keyword:`yield` will be
+executed in the :meth:`__exit__` method. Any exception raised in the block will
+be raised by the :keyword:`yield` statement.
+
+Our database example from the previous section could be written using this
+decorator as::
+
+ from contextlib import contextmanager
+
+ @contextmanager
+ def db_transaction (connection):
+ cursor = connection.cursor()
+ try:
+ yield cursor
+ except:
+ connection.rollback()
+ raise
+ else:
+ connection.commit()
+
+ db = DatabaseConnection()
+ with db_transaction(db) as cursor:
+ ...
+
+The :mod:`contextlib` module also has a :func:`nested(mgr1, mgr2, ...)` function
+that combines a number of context managers so you don't need to write nested
+':keyword:`with`' statements. In this example, the single ':keyword:`with`'
+statement both starts a database transaction and acquires a thread lock::
+
+ lock = threading.Lock()
+ with nested (db_transaction(db), lock) as (cursor, locked):
+ ...
+
+Finally, the :func:`closing(object)` function returns *object* so that it can be
+bound to a variable, and calls ``object.close`` at the end of the block. ::
+
+ import urllib, sys
+ from contextlib import closing
+
+ with closing(urllib.urlopen('http://www.yahoo.com')) as f:
+ for line in f:
+ sys.stdout.write(line)
+
+
+.. seealso::
+
+ :pep:`343` - The "with" statement
+ PEP written by Guido van Rossum and Nick Coghlan; implemented by Mike Bland,
+ Guido van Rossum, and Neal Norwitz. The PEP shows the code generated for a
+ ':keyword:`with`' statement, which can be helpful in learning how the statement
+ works.
+
+ The documentation for the :mod:`contextlib` module.
+
+.. % ======================================================================
+
+.. _pep-3110:
+
+PEP 3110: Exception-Handling Changes
+=====================================================
+
+One error that Python programmers occasionally make
+is the following::
+
+ try:
+ ...
+ except TypeError, ValueError:
+ ...
+
+The author is probably trying to catch both
+:exc:`TypeError` and :exc:`ValueError` exceptions, but this code
+actually does something different: it will catch
+:exc:`TypeError` and bind the resulting exception object
+to the local name ``"ValueError"``. The correct code
+would have specified a tuple::
+
+ try:
+ ...
+ except (TypeError, ValueError):
+ ...
+
+This error is possible because the use of the comma here is ambiguous:
+does it indicate two different nodes in the parse tree, or a single
+node that's a tuple.
+
+Python 3.0 changes the syntax to make this unambiguous by replacing
+the comma with the word "as". To catch an exception and store the
+exception object in the variable ``exc``, you must write::
+
+ try:
+ ...
+ except TypeError as exc:
+ ...
+
+Python 3.0 will only support the use of "as", and therefore interprets
+the first example as catching two different exceptions. Python 2.6
+supports both the comma and "as", so existing code will continue to
+work.
+
+.. seealso::
+
+ :pep:`3110` - Catching Exceptions in Python 3000
+ PEP written and implemented by Collin Winter.
+
+.. % ======================================================================
+
+.. _pep-3119:
+
+PEP 3119: Abstract Base Classes
+=====================================================
+
+XXX
+
+.. seealso::
+
+ :pep:`3119` - Introducing Abstract Base Classes
+ PEP written by Guido van Rossum and Talin.
+ Implemented by XXX.
+ Backported to 2.6 by Benjamin Aranguren (with Alex Martelli).
Other Language Changes
======================
Here are all of the changes that Python 2.6 makes to the core Python language.
+* Changes to the :class:`Exception` interface
+ as dictated by :pep:`352` continue to be made. For 2.6,
+ the :attr:`message` attribute is being deprecated in favor of the
+ :attr:`args` attribute.
+
+* When calling a function using the ``**`` syntax to provide keyword
+ arguments, you are no longer required to use a Python dictionary;
+ any mapping will now work::
+
+ >>> def f(**kw):
+ ... print sorted(kw)
+ ...
+ >>> ud=UserDict.UserDict()
+ >>> ud['a'] = 1
+ >>> ud['b'] = 'string'
+ >>> f(**ud)
+ ['a', 'b']
+
+ .. % Patch 1686487
+
+* The :func:`compile` built-in function now accepts keyword arguments
+ as well as positional parameters. (Contributed by XXX.)
+
+ .. % Patch 1444529
+
* The :func:`complex` constructor now accepts strings containing
parenthesized complex numbers, letting ``complex(repr(cmplx))``
will now round-trip values. For example, ``complex('(3+4j)')``
@@ -87,6 +445,15 @@
.. % Patch 1193128
+* The built-in :func:`dir` function now checks for a :meth:`__dir__`
+ method on the objects it receives. This method must return a list
+ of strings containing the names of valid attributes for the object,
+ and lets the object control the value that :func:`dir` produces.
+ Objects that have :meth:`__getattr__` or :meth:`__getattribute__`
+ methods.
+
+ .. % Patch 1591665
+
* An obscure change: when you use the the :func:`locals` function inside a
:keyword:`class` statement, the resulting dictionary no longer returns free
variables. (Free variables, in this case, are variables referred to in the
@@ -160,6 +527,11 @@
(Contributed by Raymond Hettinger.)
+* An optional ``timeout`` parameter was added to the
+ :class:`httplib.HTTPConnection` and :class:`HTTPSConnection`
+ class constructors, specifying a timeout measured in seconds.
+ (Added by Facundo Batista.)
+
* A new function in the :mod:`itertools` module: ``izip_longest(iter1, iter2,
...[, fillvalue])`` makes tuples from each of the elements; if some of the
iterables are shorter than others, the missing values are set to *fillvalue*.
@@ -176,6 +548,15 @@
.. % Patch #1490190
+* The :func:`os.walk` function now has a "followlinks" parameter. If
+ set to True, it will follow symlinks pointing to directories and
+ visit the directory's contents. For backward compatibility, the
+ parameter's default value is false. Note that the function can fall
+ into an infinite recursion if there's a symlink that points to a
+ parent directory.
+
+ .. % Patch 1273829
+
* In the :mod:`os.path` module, the :func:`splitext` function
has been changed to not split on leading period characters.
This produces better results when operating on Unix's dot-files.
@@ -191,6 +572,12 @@
.. % Patch 1339796
+ On Windows, :func:`os.path.expandvars` will now expand environment variables
+ in the form "%var%", and "~user" will be expanded into the
+ user's home directory path. (Contributed by XXX.)
+
+ .. % Patch 957650
+
* New functions in the :mod:`posix` module: :func:`chflags` and :func:`lchflags`
are wrappers for the corresponding system calls (where they're available).
Constants for the flag values are defined in the :mod:`stat` module; some
@@ -217,13 +604,78 @@
.. % Patch #957003
+* The :mod:`tarfile` module now supports POSIX.1-2001 (pax) and
+ POSIX.1-1988 (ustar) format tarfiles, in addition to the GNU tar
+ format that was already supported. The default format
+ is GNU tar; specify the ``format`` parameter to open a file
+ using a different format::
+
+ tar = tarfile.open("output.tar", "w", format=tarfile.PAX_FORMAT)
+
+ The new ``errors`` parameter lets you specify an error handling
+ scheme for character conversions: the three standard ways Python can
+ handle errors ``'strict'``, ``'ignore'``, ``'replace'`` , or the
+ special value ``'utf-8'``, which replaces bad characters with their
+ UTF-8 representation. Character conversions occur because the PAX
+ format supports Unicode filenames, defaulting to UTF-8 encoding.
+
+ The :meth:`TarFile.add` method now accepts a ``exclude`` argument that's
+ a function that can be used to exclude certain filenames from
+ an archive.
+ The function must take a filename and return true if the file
+ should be excluded or false if it should be archived.
+ The function is applied to both the name initially passed to :meth:`add`
+ and to the names of files in recursively-added directories.
+
+ (All changes contributed by Lars Gustäbel).
+
* An optional ``timeout`` parameter was added to the
:class:`telnetlib.Telnet` class constructor, specifying a timeout
measured in seconds. (Added by Facundo Batista.)
-* The :mod:`test.test_support` module now contains a :func:`EnvironmentVarGuard`
+* The :class:`tempfile.NamedTemporaryFile` class usually deletes
+ the temporary file it created when the file is closed. This
+ behaviour can now be changed by passing ``delete=False`` to the
+ constructor. (Contributed by Damien Miller.)
+
+ .. % Patch #1537850
+
+* The :mod:`test.test_support` module now contains a
+ :func:`EnvironmentVarGuard`
context manager that supports temporarily changing environment variables and
- automatically restores them to their old values. (Contributed by Brett Cannon.)
+ automatically restores them to their old values.
+
+ Another context manager, :class:`TransientResource`, can surround calls
+ to resources that may or may not be available; it will catch and
+ ignore a specified list of exceptions. For example,
+ a network test may ignore certain failures when connecting to an
+ external web site::
+
+ with test_support.TransientResource(IOError, errno=errno.ETIMEDOUT):
+ f = urllib.urlopen('https://sf.net')
+ ...
+
+ (Contributed by Brett Cannon.)
+
+* The :mod:`textwrap` module can now preserve existing whitespace
+ at the beginnings and ends of the newly-created lines
+ by specifying ``drop_whitespace=False``
+ as an argument::
+
+ >>> S = """This sentence has a bunch of extra whitespace."""
+ >>> print textwrap.fill(S, width=15)
+ This sentence
+ has a bunch
+ of extra
+ whitespace.
+ >>> print textwrap.fill(S, drop_whitespace=False, width=15)
+ This sentence
+ has a bunch
+ of extra
+ whitespace.
+ >>>
+
+ .. % Patch #1581073
* The :mod:`timeit` module now accepts callables as well as strings
for the statement being timed and for the setup code.
@@ -235,6 +687,20 @@
.. % Patch #1533909
+* An optional ``timeout`` parameter was added to the
+ :func:`urllib.urlopen` function and the
+ :class:`urllib.ftpwrapper` class constructor, as well as the
+ :func:`urllib2.urlopen` function. The parameter specifies a timeout
+ measured in seconds. For example::
+
+ >>> u = urllib2.urlopen("http://slow.example.com", timeout=3)
+ Traceback (most recent call last):
+ ...
+ urllib2.URLError: <urlopen error timed out>
+ >>>
+
+ (Added by Facundo Batista.)
+
.. % ======================================================================
.. % whole new modules get described in \subsections here
Modified: python/branches/py3k-importlib/Lib/cgi.py
==============================================================================
--- python/branches/py3k-importlib/Lib/cgi.py (original)
+++ python/branches/py3k-importlib/Lib/cgi.py Fri Sep 21 03:17:09 2007
@@ -604,23 +604,21 @@
"""Dictionary style keys() method."""
if self.list is None:
raise TypeError("not indexable")
- keys = []
- for item in self.list:
- if item.name not in keys: keys.append(item.name)
- return keys
+ return list(set(item.name for item in self.list))
def __contains__(self, key):
"""Dictionary style __contains__ method."""
if self.list is None:
raise TypeError("not indexable")
- for item in self.list:
- if item.name == key: return True
- return False
+ return any(item.name == key for item in self.list)
def __len__(self):
"""Dictionary style len(x) support."""
return len(self.keys())
+ def __nonzero__(self):
+ return bool(self.list)
+
def read_urlencoded(self):
"""Internal: read data in query string format."""
qs = self.fp.read(self.length)
Modified: python/branches/py3k-importlib/Lib/collections.py
==============================================================================
--- python/branches/py3k-importlib/Lib/collections.py (original)
+++ python/branches/py3k-importlib/Lib/collections.py Fri Sep 21 03:17:09 2007
@@ -11,40 +11,50 @@
__all__ += _abcoll.__all__
-def NamedTuple(typename, s):
+def NamedTuple(typename, s, verbose=False):
"""Returns a new subclass of tuple with named fields.
>>> Point = NamedTuple('Point', 'x y')
- >>> Point.__doc__ # docstring for the new class
+ >>> Point.__doc__ # docstring for the new class
'Point(x, y)'
- >>> p = Point(11, y=22) # instantiate with positional args or keywords
- >>> p[0] + p[1] # works just like the tuple (11, 22)
+ >>> p = Point(11, y=22) # instantiate with positional args or keywords
+ >>> p[0] + p[1] # works just like the tuple (11, 22)
33
- >>> x, y = p # unpacks just like a tuple
+ >>> x, y = p # unpacks just like a tuple
>>> x, y
(11, 22)
- >>> p.x + p.y # fields also accessable by name
+ >>> p.x + p.y # fields also accessable by name
33
- >>> p # readable __repr__ with name=value style
+ >>> p # readable __repr__ with name=value style
Point(x=11, y=22)
+ >>> p.__replace__('x', 100) # __replace__() is like str.replace() but targets a named field
+ Point(x=100, y=22)
+ >>> d = dict(zip(p.__fields__, p)) # use __fields__ to make a dictionary
+ >>> d['x']
+ 11
"""
- field_names = s.split()
- if not ''.join([typename] + field_names).replace('_', '').isalnum():
+ field_names = tuple(s.replace(',', ' ').split()) # names separated by spaces and/or commas
+ if not ''.join((typename,) + field_names).replace('_', '').isalnum():
raise ValueError('Type names and field names can only contain alphanumeric characters and underscores')
- argtxt = ', '.join(field_names)
+ argtxt = repr(field_names).replace("'", "")[1:-1] # tuple repr without parens or quotes
reprtxt = ', '.join('%s=%%r' % name for name in field_names)
template = '''class %(typename)s(tuple):
'%(typename)s(%(argtxt)s)'
__slots__ = ()
+ __fields__ = %(field_names)r
def __new__(cls, %(argtxt)s):
- return tuple.__new__(cls, (%(argtxt)s,))
+ return tuple.__new__(cls, (%(argtxt)s))
def __repr__(self):
return '%(typename)s(%(reprtxt)s)' %% self
- ''' % locals()
+ def __replace__(self, field, value):
+ 'Return a new %(typename)s object replacing one field with a new value'
+ return %(typename)s(**dict(list(zip(%(field_names)r, self)) + [(field, value)])) \n''' % locals()
for i, name in enumerate(field_names):
- template += '\n %s = property(itemgetter(%d))\n' % (name, i)
+ template += ' %s = property(itemgetter(%d))\n' % (name, i)
+ if verbose:
+ print(template)
m = dict(itemgetter=_itemgetter)
exec(template, m)
result = m[typename]
@@ -57,9 +67,9 @@
if __name__ == '__main__':
- # verify that instances are pickable
+ # verify that instances can be pickled
from pickle import loads, dumps
- Point = NamedTuple('Point', 'x y')
+ Point = NamedTuple('Point', 'x, y', True)
p = Point(x=10, y=20)
assert p == loads(dumps(p))
Modified: python/branches/py3k-importlib/Lib/ctypes/test/test_cfuncs.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/test/test_cfuncs.py (original)
+++ python/branches/py3k-importlib/Lib/ctypes/test/test_cfuncs.py Fri Sep 21 03:17:09 2007
@@ -158,17 +158,17 @@
self.failUnlessEqual(self._dll.tf_bd(0, 42.), 14.)
self.failUnlessEqual(self.S(), 42)
- def test_longdouble(self):
- self._dll.tf_D.restype = c_longdouble
- self._dll.tf_D.argtypes = (c_longdouble,)
- self.failUnlessEqual(self._dll.tf_D(42.), 14.)
- self.failUnlessEqual(self.S(), 42)
-
- def test_longdouble_plus(self):
- self._dll.tf_bD.restype = c_longdouble
- self._dll.tf_bD.argtypes = (c_byte, c_longdouble)
- self.failUnlessEqual(self._dll.tf_bD(0, 42.), 14.)
- self.failUnlessEqual(self.S(), 42)
+## def test_longdouble(self):
+## self._dll.tf_D.restype = c_longdouble
+## self._dll.tf_D.argtypes = (c_longdouble,)
+## self.failUnlessEqual(self._dll.tf_D(42.), 14.)
+## self.failUnlessEqual(self.S(), 42)
+
+## def test_longdouble_plus(self):
+## self._dll.tf_bD.restype = c_longdouble
+## self._dll.tf_bD.argtypes = (c_byte, c_longdouble)
+## self.failUnlessEqual(self._dll.tf_bD(0, 42.), 14.)
+## self.failUnlessEqual(self.S(), 42)
def test_callwithresult(self):
def process_result(result):
Modified: python/branches/py3k-importlib/Lib/ctypes/test/test_functions.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/test/test_functions.py (original)
+++ python/branches/py3k-importlib/Lib/ctypes/test/test_functions.py Fri Sep 21 03:17:09 2007
@@ -143,17 +143,17 @@
self.failUnlessEqual(result, -21)
self.failUnlessEqual(type(result), float)
- def test_longdoubleresult(self):
- f = dll._testfunc_D_bhilfD
- f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_longdouble]
- f.restype = c_longdouble
- result = f(1, 2, 3, 4, 5.0, 6.0)
- self.failUnlessEqual(result, 21)
- self.failUnlessEqual(type(result), float)
-
- result = f(-1, -2, -3, -4, -5.0, -6.0)
- self.failUnlessEqual(result, -21)
- self.failUnlessEqual(type(result), float)
+## def test_longdoubleresult(self):
+## f = dll._testfunc_D_bhilfD
+## f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_longdouble]
+## f.restype = c_longdouble
+## result = f(1, 2, 3, 4, 5.0, 6.0)
+## self.failUnlessEqual(result, 21)
+## self.failUnlessEqual(type(result), float)
+
+## result = f(-1, -2, -3, -4, -5.0, -6.0)
+## self.failUnlessEqual(result, -21)
+## self.failUnlessEqual(type(result), float)
def test_longlongresult(self):
try:
Modified: python/branches/py3k-importlib/Lib/ctypes/util.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ctypes/util.py (original)
+++ python/branches/py3k-importlib/Lib/ctypes/util.py Fri Sep 21 03:17:09 2007
@@ -63,15 +63,27 @@
return None
return res.group(0)
- def _get_soname(f):
- # assuming GNU binutils / ELF
- if not f:
- return None
- cmd = "objdump -p -j .dynamic 2>/dev/null " + f
- res = re.search(r'\sSONAME\s+([^\s]+)', os.popen(cmd).read())
- if not res:
- return None
- return res.group(1)
+
+ if sys.platform == "sunos5":
+ # use /usr/ccs/bin/dump on solaris
+ def _get_soname(f):
+ if not f:
+ return None
+ cmd = "/usr/ccs/bin/dump -Lpv 2>/dev/null " + f
+ res = re.search(r'\[.*\]\sSONAME\s+([^\s]+)', os.popen(cmd).read())
+ if not res:
+ return None
+ return res.group(1)
+ else:
+ def _get_soname(f):
+ # assuming GNU binutils / ELF
+ if not f:
+ return None
+ cmd = "objdump -p -j .dynamic 2>/dev/null " + f
+ res = re.search(r'\sSONAME\s+([^\s]+)', os.popen(cmd).read())
+ if not res:
+ return None
+ return res.group(1)
if (sys.platform.startswith("freebsd")
or sys.platform.startswith("openbsd")
Modified: python/branches/py3k-importlib/Lib/decimal.py
==============================================================================
--- python/branches/py3k-importlib/Lib/decimal.py (original)
+++ python/branches/py3k-importlib/Lib/decimal.py Fri Sep 21 03:17:09 2007
@@ -128,7 +128,7 @@
# Constants for use in setting up contexts
'ROUND_DOWN', 'ROUND_HALF_UP', 'ROUND_HALF_EVEN', 'ROUND_CEILING',
- 'ROUND_FLOOR', 'ROUND_UP', 'ROUND_HALF_DOWN',
+ 'ROUND_FLOOR', 'ROUND_UP', 'ROUND_HALF_DOWN', 'ROUND_05UP',
# Functions for manipulating contexts
'setcontext', 'getcontext', 'localcontext'
@@ -144,6 +144,7 @@
ROUND_FLOOR = 'ROUND_FLOOR'
ROUND_UP = 'ROUND_UP'
ROUND_HALF_DOWN = 'ROUND_HALF_DOWN'
+ROUND_05UP = 'ROUND_05UP'
# Rounding decision (not part of the public API)
NEVER_ROUND = 'NEVER_ROUND' # Round in division (non-divmod), sqrt ONLY
@@ -204,13 +205,22 @@
x ** (non-integer)
x ** (+-)INF
An operand is invalid
+
+ The result of the operation after these is a quiet positive NaN,
+ except when the cause is a signaling NaN, in which case the result is
+ also a quiet NaN, but with the original sign, and an optional
+ diagnostic information.
"""
def handle(self, context, *args):
if args:
if args[0] == 1: # sNaN, must drop 's' but keep diagnostics
- return Decimal( (args[1]._sign, args[1]._int, 'n') )
+ ans = Decimal((args[1]._sign, args[1]._int, 'n'))
+ return ans._fix_nan(context)
+ elif args[0] == 2:
+ return Decimal( (args[1], args[2], 'n') )
return NaN
+
class ConversionSyntax(InvalidOperation):
"""Trying to convert badly formed string.
@@ -218,9 +228,8 @@
converted to a number and it does not conform to the numeric string
syntax. The result is [0,qNaN].
"""
-
def handle(self, context, *args):
- return (0, (0,), 'n') # Passed to something which uses a tuple.
+ return NaN
class DivisionByZero(DecimalException, ZeroDivisionError):
"""Division by 0.
@@ -235,9 +244,7 @@
-0, for power.
"""
- def handle(self, context, sign, double = None, *args):
- if double is not None:
- return (Infsign[sign],)*2
+ def handle(self, context, sign, *args):
return Infsign[sign]
class DivisionImpossible(InvalidOperation):
@@ -249,7 +256,7 @@
"""
def handle(self, context, *args):
- return (NaN, NaN)
+ return NaN
class DivisionUndefined(InvalidOperation, ZeroDivisionError):
"""Undefined result of division.
@@ -259,9 +266,7 @@
the dividend is also zero. The result is [0,qNaN].
"""
- def handle(self, context, tup=None, *args):
- if tup is not None:
- return (NaN, NaN) # for 0 %0, 0 // 0
+ def handle(self, context, *args):
return NaN
class Inexact(DecimalException):
@@ -340,7 +345,7 @@
def handle(self, context, sign, *args):
if context.rounding in (ROUND_HALF_UP, ROUND_HALF_EVEN,
- ROUND_HALF_DOWN, ROUND_UP):
+ ROUND_HALF_DOWN, ROUND_UP):
return Infsign[sign]
if sign == 0:
if context.rounding == ROUND_CEILING:
@@ -520,7 +525,7 @@
Decimal("3.14")
>>> Decimal((0, (3, 1, 4), -2)) # tuple (sign, digit_tuple, exponent)
Decimal("3.14")
- >>> Decimal(314) # int or long
+ >>> Decimal(314) # int
Decimal("314")
>>> Decimal(Decimal(314)) # another decimal instance
Decimal("314")
@@ -545,7 +550,7 @@
return self
# From an integer
- if isinstance(value, (int,int)):
+ if isinstance(value, int):
if value >= 0:
self._sign = 0
else:
@@ -561,8 +566,8 @@
if value[0] not in (0,1):
raise ValueError('Invalid sign')
for digit in value[1]:
- if not isinstance(digit, (int,int)) or digit < 0:
- raise ValueError("The second value in the tuple must be"
+ if not isinstance(digit, int) or digit < 0:
+ raise ValueError("The second value in the tuple must be "
"composed of non negative integer elements.")
self._sign = value[0]
self._int = tuple(value[1])
@@ -596,10 +601,6 @@
if _isnan(value):
sig, sign, diag = _isnan(value)
self._is_special = True
- if len(diag) > context.prec: # Diagnostic info too long
- self._sign, self._int, self._exp = \
- context._raise_error(ConversionSyntax)
- return self
if sig == 1:
self._exp = 'n' # qNaN
else: # sig == 2
@@ -611,9 +612,8 @@
self._sign, self._int, self._exp = _string2exact(value)
except ValueError:
self._is_special = True
- self._sign, self._int, self._exp = \
- context._raise_error(ConversionSyntax,
- "Invalid literal for Decimal: %r" % value)
+ return context._raise_error(ConversionSyntax,
+ "Invalid literal for Decimal: %r" % value)
return self
raise TypeError("Cannot convert %r to Decimal" % value)
@@ -622,7 +622,7 @@
"""Returns whether the number is not actually one.
0 if a number
- 1 if NaN
+ 1 if NaN (it could be a normal quiet NaN or a phantom one)
2 if sNaN
"""
if self._is_special:
@@ -646,7 +646,7 @@
return 1
return 0
- def _check_nans(self, other = None, context=None):
+ def _check_nans(self, other=None, context=None):
"""Returns whether the number is not actually one.
if self, other are sNaN, signal
@@ -673,9 +673,9 @@
return context._raise_error(InvalidOperation, 'sNaN',
1, other)
if self_is_nan:
- return self
+ return self._fix_nan(context)
- return other
+ return other._fix_nan(context)
return 0
def __bool__(self):
@@ -688,21 +688,28 @@
return True
return sum(self._int) != 0
- def __cmp__(self, other, context=None):
+ def __cmp__(self, other):
other = _convert_other(other)
if other is NotImplemented:
- return other
+ # Never return NotImplemented
+ return 1
if self._is_special or other._is_special:
- ans = self._check_nans(other, context)
- if ans:
+ # check for nans, without raising on a signaling nan
+ if self._isnan() or other._isnan():
return 1 # Comparison involving NaN's always reports self > other
# INF = INF
return cmp(self._isinfinity(), other._isinfinity())
- if not self and not other:
- return 0 # If both 0, sign comparison isn't certain.
+ # check for zeros; note that cmp(0, -0) should return 0
+ if not self:
+ if not other:
+ return 0
+ else:
+ return -((-1)**other._sign)
+ if not other:
+ return (-1)**self._sign
# If different signs, neg one is less
if other._sign < self._sign:
@@ -712,35 +719,15 @@
self_adjusted = self.adjusted()
other_adjusted = other.adjusted()
- if self_adjusted == other_adjusted and \
- self._int + (0,)*(self._exp - other._exp) == \
- other._int + (0,)*(other._exp - self._exp):
- return 0 # equal, except in precision. ([0]*(-x) = [])
- elif self_adjusted > other_adjusted and self._int[0] != 0:
+ if self_adjusted == other_adjusted:
+ self_padded = self._int + (0,)*(self._exp - other._exp)
+ other_padded = other._int + (0,)*(other._exp - self._exp)
+ return cmp(self_padded, other_padded) * (-1)**self._sign
+ elif self_adjusted > other_adjusted:
return (-1)**self._sign
- elif self_adjusted < other_adjusted and other._int[0] != 0:
+ else: # self_adjusted < other_adjusted
return -((-1)**self._sign)
- # Need to round, so make sure we have a valid context
- if context is None:
- context = getcontext()
-
- context = context._shallow_copy()
- rounding = context._set_rounding(ROUND_UP) # round away from 0
-
- flags = context._ignore_all_flags()
- res = self.__sub__(other, context=context)
-
- context._regard_flags(*flags)
-
- context.rounding = rounding
-
- if not res:
- return 0
- elif res._sign:
- return -1
- return 1
-
def __eq__(self, other):
if not isinstance(other, (Decimal, int)):
return NotImplemented
@@ -780,9 +767,7 @@
NaN => one is NaN
Like __cmp__, but returns Decimal instances.
"""
- other = _convert_other(other)
- if other is NotImplemented:
- return other
+ other = _convert_other(other, raiseit=True)
# Compare(NaN, NaN) = NaN
if (self._is_special or other and other._is_special):
@@ -790,7 +775,7 @@
if ans:
return ans
- return Decimal(self.__cmp__(other, context))
+ return Decimal(self.__cmp__(other))
def __hash__(self):
"""x.__hash__() <==> hash(x)"""
@@ -801,10 +786,17 @@
if self._isnan():
raise TypeError('Cannot hash a NaN value.')
return hash(str(self))
- i = int(self)
- if self == Decimal(i):
- return hash(i)
- assert self.__bool__() # '-0' handled by integer case
+ if not self:
+ return 0
+ if self._isinteger():
+ op = _WorkRep(self.to_integral_value())
+ # to make computation feasible for Decimals with large
+ # exponent, we use the fact that hash(n) == hash(m) for
+ # any two nonzero integers n and m such that (i) n and m
+ # have the same sign, and (ii) n is congruent to m modulo
+ # 2**64-1. So we can replace hash((-1)**s*c*10**e) with
+ # hash((-1)**s*c*pow(10, e, 2**64-1).
+ return hash((-1)**op.sign*op.int*pow(10, op.exp, 2**64-1))
return hash(str(self.normalize()))
def as_tuple(self):
@@ -819,7 +811,7 @@
# Invariant: eval(repr(d)) == d
return 'Decimal("%s")' % str(self)
- def __str__(self, eng = 0, context=None):
+ def __str__(self, eng=False, context=None):
"""Return string representation of the number in scientific notation.
Captures all of the information in the underlying representation.
@@ -909,7 +901,7 @@
Same rules for when in exponential and when as a value as in __str__.
"""
- return self.__str__(eng=1, context=context)
+ return self.__str__(eng=True, context=context)
def __neg__(self, context=None):
"""Returns a copy with the sign switched.
@@ -923,17 +915,15 @@
if not self:
# -Decimal('0') is Decimal('0'), not Decimal('-0')
- sign = 0
- elif self._sign:
- sign = 0
+ ans = self.copy_sign(Dec_0)
else:
- sign = 1
+ ans = self.copy_negate()
if context is None:
context = getcontext()
if context._rounding_decision == ALWAYS_ROUND:
- return Decimal((sign, self._int, self._exp))._fix(context)
- return Decimal( (sign, self._int, self._exp))
+ return ans._fix(context)
+ return ans
def __pos__(self, context=None):
"""Returns a copy, unless it is a sNaN.
@@ -945,19 +935,16 @@
if ans:
return ans
- sign = self._sign
if not self:
# + (-0) = 0
- sign = 0
+ ans = self.copy_sign(Dec_0)
+ else:
+ ans = Decimal(self)
if context is None:
context = getcontext()
-
if context._rounding_decision == ALWAYS_ROUND:
- ans = self._fix(context)
- else:
- ans = Decimal(self)
- ans._sign = sign
+ return ans._fix(context)
return ans
def __abs__(self, round=1, context=None):
@@ -1020,16 +1007,19 @@
sign = min(self._sign, other._sign)
if negativezero:
sign = 1
- return Decimal( (sign, (0,), exp))
+ ans = Decimal( (sign, (0,), exp))
+ if shouldround:
+ ans = ans._fix(context)
+ return ans
if not self:
exp = max(exp, other._exp - context.prec-1)
- ans = other._rescale(exp, watchexp=0, context=context)
+ ans = other._rescale(exp, context.rounding)
if shouldround:
ans = ans._fix(context)
return ans
if not other:
exp = max(exp, self._exp - context.prec-1)
- ans = self._rescale(exp, watchexp=0, context=context)
+ ans = self._rescale(exp, context.rounding)
if shouldround:
ans = ans._fix(context)
return ans
@@ -1042,10 +1032,10 @@
if op1.sign != op2.sign:
# Equal and opposite
if op1.int == op2.int:
- if exp < context.Etiny():
- exp = context.Etiny()
- context._raise_error(Clamped)
- return Decimal((negativezero, (0,), exp))
+ ans = Decimal((negativezero, (0,), exp))
+ if shouldround:
+ ans = ans._fix(context)
+ return ans
if op1.int < op2.int:
op1, op2 = op2, op1
# OK, now abs(op1) > abs(op2)
@@ -1076,7 +1066,7 @@
__radd__ = __add__
def __sub__(self, other, context=None):
- """Return self + (-other)"""
+ """Return self - other"""
other = _convert_other(other)
if other is NotImplemented:
return other
@@ -1086,41 +1076,28 @@
if ans:
return ans
- # -Decimal(0) = Decimal(0), which we don't want since
- # (-0 - 0 = -0 + (-0) = -0, but -0 + 0 = 0.)
- # so we change the sign directly to a copy
- tmp = Decimal(other)
- tmp._sign = 1-tmp._sign
-
- return self.__add__(tmp, context=context)
+ # self - other is computed as self + other.copy_negate()
+ return self.__add__(other.copy_negate(), context=context)
def __rsub__(self, other, context=None):
- """Return other + (-self)"""
+ """Return other - self"""
other = _convert_other(other)
if other is NotImplemented:
return other
- tmp = Decimal(self)
- tmp._sign = 1 - tmp._sign
- return other.__add__(tmp, context=context)
+ return other.__sub__(self, context=context)
- def _increment(self, round=1, context=None):
+ def _increment(self):
"""Special case of add, adding 1eExponent
Since it is common, (rounding, for example) this adds
(sign)*one E self._exp to the number more efficiently than add.
+ Assumes that self is nonspecial.
+
For example:
Decimal('5.624e10')._increment() == Decimal('5.625e10')
"""
- if self._is_special:
- ans = self._check_nans(context=context)
- if ans:
- return ans
-
- # Must be infinite, and incrementing makes no difference
- return Decimal(self)
-
L = list(self._int)
L[-1] += 1
spot = len(L)-1
@@ -1131,13 +1108,7 @@
break
L[spot-1] += 1
spot -= 1
- ans = Decimal((self._sign, L, self._exp))
-
- if context is None:
- context = getcontext()
- if round and context._rounding_decision == ALWAYS_ROUND:
- ans = ans._fix(context)
- return ans
+ return Decimal((self._sign, L, self._exp))
def __mul__(self, other, context=None):
"""Return self * other.
@@ -1205,25 +1176,9 @@
def __truediv__(self, other, context=None):
"""Return self / other."""
- return self._divide(other, context=context)
-
- def _divide(self, other, divmod = 0, context=None):
- """Return a / b, to context.prec precision.
-
- divmod:
- 0 => true division
- 1 => (a //b, a%b)
- 2 => a //b
- 3 => a%b
-
- Actually, if divmod is 2 or 3 a tuple is returned, but errors for
- computing the other value are not raised.
- """
other = _convert_other(other)
if other is NotImplemented:
- if divmod in (0, 1):
- return NotImplemented
- return (NotImplemented, NotImplemented)
+ return NotImplemented
if context is None:
context = getcontext()
@@ -1233,144 +1188,84 @@
if self._is_special or other._is_special:
ans = self._check_nans(other, context)
if ans:
- if divmod:
- return (ans, ans)
return ans
if self._isinfinity() and other._isinfinity():
- if divmod:
- return (context._raise_error(InvalidOperation,
- '(+-)INF // (+-)INF'),
- context._raise_error(InvalidOperation,
- '(+-)INF % (+-)INF'))
return context._raise_error(InvalidOperation, '(+-)INF/(+-)INF')
if self._isinfinity():
- if divmod == 1:
- return (Infsign[sign],
- context._raise_error(InvalidOperation, 'INF % x'))
- elif divmod == 2:
- return (Infsign[sign], NaN)
- elif divmod == 3:
- return (Infsign[sign],
- context._raise_error(InvalidOperation, 'INF % x'))
return Infsign[sign]
if other._isinfinity():
- if divmod:
- return (Decimal((sign, (0,), 0)), Decimal(self))
context._raise_error(Clamped, 'Division by infinity')
return Decimal((sign, (0,), context.Etiny()))
# Special cases for zeroes
- if not self and not other:
- if divmod:
- return context._raise_error(DivisionUndefined, '0 / 0', 1)
- return context._raise_error(DivisionUndefined, '0 / 0')
-
- if not self:
- if divmod:
- otherside = Decimal(self)
- otherside._exp = min(self._exp, other._exp)
- return (Decimal((sign, (0,), 0)), otherside)
- exp = self._exp - other._exp
- if exp < context.Etiny():
- exp = context.Etiny()
- context._raise_error(Clamped, '0e-x / y')
- if exp > context.Emax:
- exp = context.Emax
- context._raise_error(Clamped, '0e+x / y')
- return Decimal( (sign, (0,), exp) )
-
if not other:
- if divmod:
- return context._raise_error(DivisionByZero, 'divmod(x,0)',
- sign, 1)
+ if not self:
+ return context._raise_error(DivisionUndefined, '0 / 0')
return context._raise_error(DivisionByZero, 'x / 0', sign)
- # OK, so neither = 0, INF or NaN
- shouldround = context._rounding_decision == ALWAYS_ROUND
-
- # If we're dividing into ints, and self < other, stop.
- # self.__abs__(0) does not round.
- if divmod and (self.__abs__(0, context) < other.__abs__(0, context)):
-
- if divmod == 1 or divmod == 3:
- exp = min(self._exp, other._exp)
- ans2 = self._rescale(exp, context=context, watchexp=0)
- if shouldround:
- ans2 = ans2._fix(context)
- return (Decimal( (sign, (0,), 0) ),
- ans2)
-
- elif divmod == 2:
- # Don't round the mod part, if we don't need it.
- return (Decimal( (sign, (0,), 0) ), Decimal(self))
-
- op1 = _WorkRep(self)
- op2 = _WorkRep(other)
- op1, op2, adjust = _adjust_coefficients(op1, op2)
- res = _WorkRep( (sign, 0, (op1.exp - op2.exp)) )
- if divmod and res.exp > context.prec + 1:
- return context._raise_error(DivisionImpossible)
-
- prec_limit = 10 ** context.prec
- while 1:
- while op2.int <= op1.int:
- res.int += 1
- op1.int -= op2.int
- if res.exp == 0 and divmod:
- if res.int >= prec_limit and shouldround:
- return context._raise_error(DivisionImpossible)
- otherside = Decimal(op1)
- frozen = context._ignore_all_flags()
-
- exp = min(self._exp, other._exp)
- otherside = otherside._rescale(exp, context=context, watchexp=0)
- context._regard_flags(*frozen)
- if shouldround:
- otherside = otherside._fix(context)
- return (Decimal(res), otherside)
-
- if op1.int == 0 and adjust >= 0 and not divmod:
- break
- if res.int >= prec_limit and shouldround:
- if divmod:
- return context._raise_error(DivisionImpossible)
- shouldround=1
- # Really, the answer is a bit higher, so adding a one to
- # the end will make sure the rounding is right.
- if op1.int != 0:
- res.int *= 10
- res.int += 1
- res.exp -= 1
-
- break
- res.int *= 10
- res.exp -= 1
- adjust += 1
- op1.int *= 10
- op1.exp -= 1
-
- if res.exp == 0 and divmod and op2.int > op1.int:
- # Solves an error in precision. Same as a previous block.
-
- if res.int >= prec_limit and shouldround:
- return context._raise_error(DivisionImpossible)
- otherside = Decimal(op1)
- frozen = context._ignore_all_flags()
+ if not self:
+ exp = self._exp - other._exp
+ coeff = 0
+ else:
+ # OK, so neither = 0, INF or NaN
+ shift = len(other._int) - len(self._int) + context.prec + 1
+ exp = self._exp - other._exp - shift
+ op1 = _WorkRep(self)
+ op2 = _WorkRep(other)
+ if shift >= 0:
+ coeff, remainder = divmod(op1.int * 10**shift, op2.int)
+ else:
+ coeff, remainder = divmod(op1.int, op2.int * 10**-shift)
+ if remainder:
+ # result is not exact; adjust to ensure correct rounding
+ if coeff % 5 == 0:
+ coeff += 1
+ else:
+ # result is exact; get as close to ideal exponent as possible
+ ideal_exp = self._exp - other._exp
+ while exp < ideal_exp and coeff % 10 == 0:
+ coeff //= 10
+ exp += 1
- exp = min(self._exp, other._exp)
- otherside = otherside._rescale(exp, context=context)
+ ans = Decimal((sign, list(map(int, str(coeff))), exp))
+ return ans._fix(context)
- context._regard_flags(*frozen)
+ def _divide(self, other, context):
+ """Return (self // other, self % other), to context.prec precision.
- return (Decimal(res), otherside)
+ Assumes that neither self nor other is a NaN, that self is not
+ infinite and that other is nonzero.
+ """
+ sign = self._sign ^ other._sign
+ if other._isinfinity():
+ ideal_exp = self._exp
+ else:
+ ideal_exp = min(self._exp, other._exp)
- ans = Decimal(res)
- if shouldround:
- ans = ans._fix(context)
- return ans
+ expdiff = self.adjusted() - other.adjusted()
+ if not self or other._isinfinity() or expdiff <= -2:
+ return (Decimal((sign, (0,), 0)),
+ self._rescale(ideal_exp, context.rounding))
+ if expdiff <= context.prec:
+ op1 = _WorkRep(self)
+ op2 = _WorkRep(other)
+ if op1.exp >= op2.exp:
+ op1.int *= 10**(op1.exp - op2.exp)
+ else:
+ op2.int *= 10**(op2.exp - op1.exp)
+ q, r = divmod(op1.int, op2.int)
+ if q < 10**context.prec:
+ return (Decimal((sign, list(map(int, str(q))), 0)),
+ Decimal((self._sign, list(map(int, str(r))),
+ ideal_exp)))
+
+ # Here the quotient is too large to be representable
+ ans = context._raise_error(DivisionImpossible,
+ 'quotient too large in //, % or divmod')
+ return ans, ans
def __rtruediv__(self, other, context=None):
"""Swaps self/other and returns __truediv__."""
@@ -1381,9 +1276,40 @@
def __divmod__(self, other, context=None):
"""
- (self // other, self % other)
+ Return (self // other, self % other)
"""
- return self._divide(other, 1, context)
+ other = _convert_other(other)
+ if other is NotImplemented:
+ return other
+
+ if context is None:
+ context = getcontext()
+
+ ans = self._check_nans(other, context)
+ if ans:
+ return (ans, ans)
+
+ sign = self._sign ^ other._sign
+ if self._isinfinity():
+ if other._isinfinity():
+ ans = context._raise_error(InvalidOperation, 'divmod(INF, INF)')
+ return ans, ans
+ else:
+ return (Infsign[sign],
+ context._raise_error(InvalidOperation, 'INF % x'))
+
+ if not other:
+ if not self:
+ ans = context._raise_error(DivisionUndefined, 'divmod(0, 0)')
+ return ans, ans
+ else:
+ return (context._raise_error(DivisionByZero, 'x // 0', sign),
+ context._raise_error(InvalidOperation, 'x % 0'))
+
+ quotient, remainder = self._divide(other, context)
+ if context._rounding_decision == ALWAYS_ROUND:
+ remainder = remainder._fix(context)
+ return quotient, remainder
def __rdivmod__(self, other, context=None):
"""Swaps self/other and returns __divmod__."""
@@ -1400,15 +1326,25 @@
if other is NotImplemented:
return other
- if self._is_special or other._is_special:
- ans = self._check_nans(other, context)
- if ans:
- return ans
+ if context is None:
+ context = getcontext()
- if self and not other:
- return context._raise_error(InvalidOperation, 'x % 0')
+ ans = self._check_nans(other, context)
+ if ans:
+ return ans
+
+ if self._isinfinity():
+ return context._raise_error(InvalidOperation, 'INF % x')
+ elif not other:
+ if self:
+ return context._raise_error(InvalidOperation, 'x % 0')
+ else:
+ return context._raise_error(DivisionUndefined, '0 % 0')
- return self._divide(other, 3, context)[1]
+ remainder = self._divide(other, context)[1]
+ if context._rounding_decision == ALWAYS_ROUND:
+ remainder = remainder._fix(context)
+ return remainder
def __rmod__(self, other, context=None):
"""Swaps self/other and returns __mod__."""
@@ -1421,85 +1357,104 @@
"""
Remainder nearest to 0- abs(remainder-near) <= other/2
"""
- other = _convert_other(other)
- if other is NotImplemented:
- return other
-
- if self._is_special or other._is_special:
- ans = self._check_nans(other, context)
- if ans:
- return ans
- if self and not other:
- return context._raise_error(InvalidOperation, 'x % 0')
-
if context is None:
context = getcontext()
- # If DivisionImpossible causes an error, do not leave Rounded/Inexact
- # ignored in the calling function.
- context = context._shallow_copy()
- flags = context._ignore_flags(Rounded, Inexact)
- # Keep DivisionImpossible flags
- (side, r) = self.__divmod__(other, context=context)
-
- if r._isnan():
- context._regard_flags(*flags)
- return r
-
- context = context._shallow_copy()
- rounding = context._set_rounding_decision(NEVER_ROUND)
- if other._sign:
- comparison = other.__truediv__(Decimal(-2), context=context)
- else:
- comparison = other.__truediv__(Decimal(2), context=context)
+ other = _convert_other(other, raiseit=True)
- context._set_rounding_decision(rounding)
- context._regard_flags(*flags)
+ ans = self._check_nans(other, context)
+ if ans:
+ return ans
- s1, s2 = r._sign, comparison._sign
- r._sign, comparison._sign = 0, 0
+ # self == +/-infinity -> InvalidOperation
+ if self._isinfinity():
+ return context._raise_error(InvalidOperation,
+ 'remainder_near(infinity, x)')
- if r < comparison:
- r._sign, comparison._sign = s1, s2
- # Get flags now
- self.__divmod__(other, context=context)
- return r._fix(context)
- r._sign, comparison._sign = s1, s2
+ # other == 0 -> either InvalidOperation or DivisionUndefined
+ if not other:
+ if self:
+ return context._raise_error(InvalidOperation,
+ 'remainder_near(x, 0)')
+ else:
+ return context._raise_error(DivisionUndefined,
+ 'remainder_near(0, 0)')
- rounding = context._set_rounding_decision(NEVER_ROUND)
+ # other = +/-infinity -> remainder = self
+ if other._isinfinity():
+ ans = Decimal(self)
+ return ans._fix(context)
- (side, r) = self.__divmod__(other, context=context)
- context._set_rounding_decision(rounding)
- if r._isnan():
- return r
+ # self = 0 -> remainder = self, with ideal exponent
+ ideal_exponent = min(self._exp, other._exp)
+ if not self:
+ ans = Decimal((self._sign, (0,), ideal_exponent))
+ return ans._fix(context)
- decrease = not side._iseven()
- rounding = context._set_rounding_decision(NEVER_ROUND)
- side = side.__abs__(context=context)
- context._set_rounding_decision(rounding)
+ # catch most cases of large or small quotient
+ expdiff = self.adjusted() - other.adjusted()
+ if expdiff >= context.prec + 1:
+ # expdiff >= prec+1 => abs(self/other) > 10**prec
+ return context._raise_error(DivisionImpossible)
+ if expdiff <= -2:
+ # expdiff <= -2 => abs(self/other) < 0.1
+ ans = self._rescale(ideal_exponent, context.rounding)
+ return ans._fix(context)
- s1, s2 = r._sign, comparison._sign
- r._sign, comparison._sign = 0, 0
- if r > comparison or decrease and r == comparison:
- r._sign, comparison._sign = s1, s2
- context.prec += 1
- numbsquant = len(side.__add__(Decimal(1), context=context)._int)
- if numbsquant >= context.prec:
- context.prec -= 1
- return context._raise_error(DivisionImpossible)[1]
- context.prec -= 1
- if self._sign == other._sign:
- r = r.__sub__(other, context=context)
- else:
- r = r.__add__(other, context=context)
+ # adjust both arguments to have the same exponent, then divide
+ op1 = _WorkRep(self)
+ op2 = _WorkRep(other)
+ if op1.exp >= op2.exp:
+ op1.int *= 10**(op1.exp - op2.exp)
else:
- r._sign, comparison._sign = s1, s2
+ op2.int *= 10**(op2.exp - op1.exp)
+ q, r = divmod(op1.int, op2.int)
+ # remainder is r*10**ideal_exponent; other is +/-op2.int *
+ # 10**ideal_exponent. Apply correction to ensure that
+ # abs(remainder) <= abs(other)/2
+ if 2*r + (q&1) > op2.int:
+ r -= op2.int
+ q += 1
+
+ if q >= 10**context.prec:
+ return context._raise_error(DivisionImpossible)
- return r._fix(context)
+ # result has same sign as self unless r is negative
+ sign = self._sign
+ if r < 0:
+ sign = 1-sign
+ r = -r
+
+ ans = Decimal((sign, list(map(int, str(r))), ideal_exponent))
+ return ans._fix(context)
def __floordiv__(self, other, context=None):
"""self // other"""
- return self._divide(other, 2, context)[0]
+ other = _convert_other(other)
+ if other is NotImplemented:
+ return other
+
+ if context is None:
+ context = getcontext()
+
+ ans = self._check_nans(other, context)
+ if ans:
+ return ans
+
+ if self._isinfinity():
+ if other._isinfinity():
+ return context._raise_error(InvalidOperation, 'INF // INF')
+ else:
+ return Infsign[self._sign ^ other._sign]
+
+ if not other:
+ if self:
+ return context._raise_error(DivisionByZero, 'x // 0',
+ self._sign ^ other._sign)
+ else:
+ return context._raise_error(DivisionUndefined, '0 // 0')
+
+ return self._divide(other, context)[0]
def __rfloordiv__(self, other, context=None):
"""Swaps self/other and returns __floordiv__."""
@@ -1519,22 +1474,27 @@
context = getcontext()
return context._raise_error(InvalidContext)
elif self._isinfinity():
- raise OverflowError("Cannot convert infinity to long")
+ raise OverflowError("Cannot convert infinity to int")
+ s = (-1)**self._sign
if self._exp >= 0:
- s = ''.join(map(str, self._int)) + '0'*self._exp
+ return s*int(''.join(map(str, self._int)))*10**self._exp
else:
- s = ''.join(map(str, self._int))[:self._exp]
- if s == '':
- s = '0'
- sign = '-'*self._sign
- return int(sign + s)
-
- def __long__(self):
- """Converts to a long.
+ return s*int(''.join(map(str, self._int))[:self._exp] or '0')
- Equivalent to long(int(self))
- """
- return int(self.__int__())
+ def _fix_nan(self, context):
+ """Decapitate the payload of a NaN to fit the context"""
+ payload = self._int
+
+ # maximum length of payload is precision if _clamp=0,
+ # precision-1 if _clamp=1.
+ max_payload_len = context.prec - context._clamp
+ if len(payload) > max_payload_len:
+ pos = len(payload)-max_payload_len
+ while pos < len(payload) and payload[pos] == 0:
+ pos += 1
+ payload = payload[pos:]
+ return Decimal((self._sign, payload, self._exp))
+ return Decimal(self)
def _fix(self, context):
"""Round if it is necessary to keep self within prec precision.
@@ -1545,303 +1505,649 @@
self - Decimal instance
context - context used.
"""
- if self._is_special:
- return self
+
if context is None:
context = getcontext()
- prec = context.prec
- ans = self._fixexponents(context)
- if len(ans._int) > prec:
- ans = ans._round(prec, context=context)
- ans = ans._fixexponents(context)
- return ans
- def _fixexponents(self, context):
- """Fix the exponents and return a copy with the exponent in bounds.
- Only call if known to not be a special value.
- """
- folddown = context._clamp
- Emin = context.Emin
- ans = self
- ans_adjusted = ans.adjusted()
- if ans_adjusted < Emin:
- Etiny = context.Etiny()
- if ans._exp < Etiny:
- if not ans:
- ans = Decimal(self)
- ans._exp = Etiny
- context._raise_error(Clamped)
- return ans
- ans = ans._rescale(Etiny, context=context)
- # It isn't zero, and exp < Emin => subnormal
- context._raise_error(Subnormal)
- if context.flags[Inexact]:
- context._raise_error(Underflow)
+ if self._is_special:
+ if self._isnan():
+ # decapitate payload if necessary
+ return self._fix_nan(context)
else:
- if ans:
- # Only raise subnormal if non-zero.
- context._raise_error(Subnormal)
- else:
- Etop = context.Etop()
- if folddown and ans._exp > Etop:
+ # self is +/-Infinity; return unaltered
+ return Decimal(self)
+
+ # if self is zero then exponent should be between Etiny and
+ # Emax if _clamp==0, and between Etiny and Etop if _clamp==1.
+ Etiny = context.Etiny()
+ Etop = context.Etop()
+ if not self:
+ exp_max = [context.Emax, Etop][context._clamp]
+ new_exp = min(max(self._exp, Etiny), exp_max)
+ if new_exp != self._exp:
context._raise_error(Clamped)
- ans = ans._rescale(Etop, context=context)
+ return Decimal((self._sign, (0,), new_exp))
else:
- Emax = context.Emax
- if ans_adjusted > Emax:
- if not ans:
- ans = Decimal(self)
- ans._exp = Emax
- context._raise_error(Clamped)
- return ans
- context._raise_error(Inexact)
- context._raise_error(Rounded)
- c = context._raise_error(Overflow, 'above Emax', ans._sign)
- return c
- return ans
-
- def _round(self, prec=None, rounding=None, context=None):
- """Returns a rounded version of self.
-
- You can specify the precision or rounding method. Otherwise, the
- context determines it.
- """
-
- if self._is_special:
- ans = self._check_nans(context=context)
- if ans:
- return ans
-
- if self._isinfinity():
return Decimal(self)
- if context is None:
- context = getcontext()
-
- if rounding is None:
- rounding = context.rounding
- if prec is None:
- prec = context.prec
-
- if not self:
- if prec <= 0:
- dig = (0,)
- exp = len(self._int) - prec + self._exp
- else:
- dig = (0,) * prec
- exp = len(self._int) + self._exp - prec
- ans = Decimal((self._sign, dig, exp))
+ # exp_min is the smallest allowable exponent of the result,
+ # equal to max(self.adjusted()-context.prec+1, Etiny)
+ exp_min = len(self._int) + self._exp - context.prec
+ if exp_min > Etop:
+ # overflow: exp_min > Etop iff self.adjusted() > Emax
+ context._raise_error(Inexact)
context._raise_error(Rounded)
- return ans
+ return context._raise_error(Overflow, 'above Emax', self._sign)
+ self_is_subnormal = exp_min < Etiny
+ if self_is_subnormal:
+ context._raise_error(Subnormal)
+ exp_min = Etiny
- if prec == 0:
- temp = Decimal(self)
- temp._int = (0,)+temp._int
- prec = 1
- elif prec < 0:
- exp = self._exp + len(self._int) - prec - 1
- temp = Decimal( (self._sign, (0, 1), exp))
- prec = 1
- else:
- temp = Decimal(self)
-
- numdigits = len(temp._int)
- if prec == numdigits:
- return temp
-
- # See if we need to extend precision
- expdiff = prec - numdigits
- if expdiff > 0:
- tmp = list(temp._int)
- tmp.extend([0] * expdiff)
- ans = Decimal( (temp._sign, tmp, temp._exp - expdiff))
- return ans
-
- # OK, but maybe all the lost digits are 0.
- lostdigits = self._int[expdiff:]
- if lostdigits == (0,) * len(lostdigits):
- ans = Decimal( (temp._sign, temp._int[:prec], temp._exp - expdiff))
- # Rounded, but not Inexact
+ # round if self has too many digits
+ if self._exp < exp_min:
context._raise_error(Rounded)
+ ans = self._rescale(exp_min, context.rounding)
+ if ans != self:
+ context._raise_error(Inexact)
+ if self_is_subnormal:
+ context._raise_error(Underflow)
+ if not ans:
+ # raise Clamped on underflow to 0
+ context._raise_error(Clamped)
+ elif len(ans._int) == context.prec+1:
+ # we get here only if rescaling rounds the
+ # cofficient up to exactly 10**context.prec
+ if ans._exp < Etop:
+ ans = Decimal((ans._sign, ans._int[:-1], ans._exp+1))
+ else:
+ # Inexact and Rounded have already been raised
+ ans = context._raise_error(Overflow, 'above Emax',
+ self._sign)
return ans
- # Okay, let's round and lose data
-
- this_function = getattr(temp, self._pick_rounding_function[rounding])
- # Now we've got the rounding function
-
- if prec != context.prec:
- context = context._shallow_copy()
- context.prec = prec
- ans = this_function(prec, expdiff, context)
- context._raise_error(Rounded)
- context._raise_error(Inexact, 'Changed in rounding')
+ # fold down if _clamp == 1 and self has too few digits
+ if context._clamp == 1 and self._exp > Etop:
+ context._raise_error(Clamped)
+ self_padded = self._int + (0,)*(self._exp - Etop)
+ return Decimal((self._sign, self_padded, Etop))
- return ans
+ # here self was representable to begin with; return unchanged
+ return Decimal(self)
_pick_rounding_function = {}
- def _round_down(self, prec, expdiff, context):
- """Also known as round-towards-0, truncate."""
- return Decimal( (self._sign, self._int[:prec], self._exp - expdiff) )
+ # for each of the rounding functions below:
+ # self is a finite, nonzero Decimal
+ # prec is an integer satisfying 0 <= prec < len(self._int)
+ # the rounded result will have exponent self._exp + len(self._int) - prec;
- def _round_half_up(self, prec, expdiff, context, tmp = None):
- """Rounds 5 up (away from 0)"""
+ def _round_down(self, prec):
+ """Also known as round-towards-0, truncate."""
+ newexp = self._exp + len(self._int) - prec
+ return Decimal((self._sign, self._int[:prec] or (0,), newexp))
- if tmp is None:
- tmp = Decimal( (self._sign,self._int[:prec], self._exp - expdiff))
- if self._int[prec] >= 5:
- tmp = tmp._increment(round=0, context=context)
- if len(tmp._int) > prec:
- return Decimal( (tmp._sign, tmp._int[:-1], tmp._exp + 1))
+ def _round_up(self, prec):
+ """Rounds away from 0."""
+ newexp = self._exp + len(self._int) - prec
+ tmp = Decimal((self._sign, self._int[:prec] or (0,), newexp))
+ for digit in self._int[prec:]:
+ if digit != 0:
+ return tmp._increment()
return tmp
- def _round_half_even(self, prec, expdiff, context):
- """Round 5 to even, rest to nearest."""
+ def _round_half_up(self, prec):
+ """Rounds 5 up (away from 0)"""
+ if self._int[prec] >= 5:
+ return self._round_up(prec)
+ else:
+ return self._round_down(prec)
- tmp = Decimal( (self._sign, self._int[:prec], self._exp - expdiff))
- half = (self._int[prec] == 5)
- if half:
+ def _round_half_down(self, prec):
+ """Round 5 down"""
+ if self._int[prec] == 5:
for digit in self._int[prec+1:]:
if digit != 0:
- half = 0
break
- if half:
- if self._int[prec-1] & 1 == 0:
- return tmp
- return self._round_half_up(prec, expdiff, context, tmp)
+ else:
+ return self._round_down(prec)
+ return self._round_half_up(prec)
- def _round_half_down(self, prec, expdiff, context):
- """Round 5 down"""
+ def _round_half_even(self, prec):
+ """Round 5 to even, rest to nearest."""
+ if prec and self._int[prec-1] & 1:
+ return self._round_half_up(prec)
+ else:
+ return self._round_half_down(prec)
- tmp = Decimal( (self._sign, self._int[:prec], self._exp - expdiff))
- half = (self._int[prec] == 5)
- if half:
- for digit in self._int[prec+1:]:
- if digit != 0:
- half = 0
- break
- if half:
- return tmp
- return self._round_half_up(prec, expdiff, context, tmp)
+ def _round_ceiling(self, prec):
+ """Rounds up (not away from 0 if negative.)"""
+ if self._sign:
+ return self._round_down(prec)
+ else:
+ return self._round_up(prec)
- def _round_up(self, prec, expdiff, context):
- """Rounds away from 0."""
- tmp = Decimal( (self._sign, self._int[:prec], self._exp - expdiff) )
- for digit in self._int[prec:]:
- if digit != 0:
- tmp = tmp._increment(round=1, context=context)
- if len(tmp._int) > prec:
- return Decimal( (tmp._sign, tmp._int[:-1], tmp._exp + 1))
- else:
- return tmp
- return tmp
-
- def _round_ceiling(self, prec, expdiff, context):
- """Rounds up (not away from 0 if negative.)"""
- if self._sign:
- return self._round_down(prec, expdiff, context)
- else:
- return self._round_up(prec, expdiff, context)
-
- def _round_floor(self, prec, expdiff, context):
+ def _round_floor(self, prec):
"""Rounds down (not towards 0 if negative)"""
if not self._sign:
- return self._round_down(prec, expdiff, context)
+ return self._round_down(prec)
+ else:
+ return self._round_up(prec)
+
+ def _round_05up(self, prec):
+ """Round down unless digit prec-1 is 0 or 5."""
+ if prec == 0 or self._int[prec-1] in (0, 5):
+ return self._round_up(prec)
else:
- return self._round_up(prec, expdiff, context)
+ return self._round_down(prec)
- def __pow__(self, n, modulo = None, context=None):
- """Return self ** n (mod modulo)
+ def fma(self, other, third, context=None):
+ """Fused multiply-add.
- If modulo is None (default), don't take it mod modulo.
+ Returns self*other+third with no rounding of the intermediate
+ product self*other.
+
+ self and other are multiplied together, with no rounding of
+ the result. The third operand is then added to the result,
+ and a single final rounding is performed.
"""
- n = _convert_other(n)
- if n is NotImplemented:
- return n
+
+ other = _convert_other(other, raiseit=True)
+ third = _convert_other(third, raiseit=True)
if context is None:
context = getcontext()
- if self._is_special or n._is_special or n.adjusted() > 8:
- # Because the spot << doesn't work with really big exponents
- if n._isinfinity() or n.adjusted() > 8:
- return context._raise_error(InvalidOperation, 'x ** INF')
+ # 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)
- ans = self._check_nans(n, context)
- if ans:
- return ans
+ ans = product.__add__(third, context)
+ return ans
+
+ def _power_modulo(self, other, modulo, context=None):
+ """Three argument version of __pow__"""
+
+ # if can't convert other and modulo to Decimal, raise
+ # TypeError; there's no point returning NotImplemented (no
+ # equivalent of __rpow__ for three argument pow)
+ other = _convert_other(other, raiseit=True)
+ modulo = _convert_other(modulo, raiseit=True)
+
+ if context is None:
+ context = getcontext()
+
+ # deal with NaNs: if there are any sNaNs then first one wins,
+ # (i.e. behaviour for NaNs is identical to that of fma)
+ self_is_nan = self._isnan()
+ other_is_nan = other._isnan()
+ modulo_is_nan = modulo._isnan()
+ if self_is_nan or other_is_nan or modulo_is_nan:
+ if self_is_nan == 2:
+ return context._raise_error(InvalidOperation, 'sNaN',
+ 1, self)
+ if other_is_nan == 2:
+ return context._raise_error(InvalidOperation, 'sNaN',
+ 1, other)
+ if modulo_is_nan == 2:
+ return context._raise_error(InvalidOperation, 'sNaN',
+ 1, modulo)
+ if self_is_nan:
+ return self._fix_nan(context)
+ if other_is_nan:
+ return other._fix_nan(context)
+ return modulo._fix_nan(context)
+
+ # check inputs: we apply same restrictions as Python's pow()
+ if not (self._isinteger() and
+ other._isinteger() and
+ modulo._isinteger()):
+ return context._raise_error(InvalidOperation,
+ 'pow() 3rd argument not allowed '
+ 'unless all arguments are integers')
+ if other < 0:
+ return context._raise_error(InvalidOperation,
+ 'pow() 2nd argument cannot be '
+ 'negative when 3rd argument specified')
+ if not modulo:
+ return context._raise_error(InvalidOperation,
+ 'pow() 3rd argument cannot be 0')
+
+ # additional restriction for decimal: the modulus must be less
+ # than 10**prec in absolute value
+ if modulo.adjusted() >= context.prec:
+ return context._raise_error(InvalidOperation,
+ 'insufficient precision: pow() 3rd '
+ 'argument must not have more than '
+ 'precision digits')
+
+ # define 0**0 == NaN, for consistency with two-argument pow
+ # (even though it hurts!)
+ if not other and not self:
+ return context._raise_error(InvalidOperation,
+ 'at least one of pow() 1st argument '
+ 'and 2nd argument must be nonzero ;'
+ '0**0 is not defined')
+
+ # compute sign of result
+ if other._iseven():
+ sign = 0
+ else:
+ sign = self._sign
+
+ # convert modulo to a Python integer, and self and other to
+ # Decimal integers (i.e. force their exponents to be >= 0)
+ modulo = abs(int(modulo))
+ base = _WorkRep(self.to_integral_value())
+ exponent = _WorkRep(other.to_integral_value())
+
+ # compute result using integer pow()
+ base = (base.int % modulo * pow(10, base.exp, modulo)) % modulo
+ for i in range(exponent.exp):
+ base = pow(base, 10, modulo)
+ base = pow(base, exponent.int, modulo)
+
+ return Decimal((sign, list(map(int, str(base))), 0))
+
+ def _power_exact(self, other, p):
+ """Attempt to compute self**other exactly.
+
+ Given Decimals self and other and an integer p, attempt to
+ compute an exact result for the power self**other, with p
+ digits of precision. Return None if self**other is not
+ exactly representable in p digits.
+
+ Assumes that elimination of special cases has already been
+ performed: self and other must both be nonspecial; self must
+ be positive and not numerically equal to 1; other must be
+ nonzero. For efficiency, other._exp should not be too large,
+ so that 10**abs(other._exp) is a feasible calculation."""
+
+ # In the comments below, we write x for the value of self and
+ # y for the value of other. Write x = xc*10**xe and y =
+ # yc*10**ye.
+
+ # The main purpose of this method is to identify the *failure*
+ # of x**y to be exactly representable with as little effort as
+ # possible. So we look for cheap and easy tests that
+ # eliminate the possibility of x**y being exact. Only if all
+ # these tests are passed do we go on to actually compute x**y.
+
+ # Here's the main idea. First normalize both x and y. We
+ # express y as a rational m/n, with m and n relatively prime
+ # and n>0. Then for x**y to be exactly representable (at
+ # *any* precision), xc must be the nth power of a positive
+ # integer and xe must be divisible by n. If m is negative
+ # then additionally xc must be a power of either 2 or 5, hence
+ # a power of 2**n or 5**n.
+ #
+ # There's a limit to how small |y| can be: if y=m/n as above
+ # then:
+ #
+ # (1) if xc != 1 then for the result to be representable we
+ # need xc**(1/n) >= 2, and hence also xc**|y| >= 2. So
+ # if |y| <= 1/nbits(xc) then xc < 2**nbits(xc) <=
+ # 2**(1/|y|), hence xc**|y| < 2 and the result is not
+ # representable.
+ #
+ # (2) if xe != 0, |xe|*(1/n) >= 1, so |xe|*|y| >= 1. Hence if
+ # |y| < 1/|xe| then the result is not representable.
+ #
+ # Note that since x is not equal to 1, at least one of (1) and
+ # (2) must apply. Now |y| < 1/nbits(xc) iff |yc|*nbits(xc) <
+ # 10**-ye iff len(str(|yc|*nbits(xc)) <= -ye.
+ #
+ # There's also a limit to how large y can be, at least if it's
+ # positive: the normalized result will have coefficient xc**y,
+ # so if it's representable then xc**y < 10**p, and y <
+ # p/log10(xc). Hence if y*log10(xc) >= p then the result is
+ # not exactly representable.
+
+ # if len(str(abs(yc*xe)) <= -ye then abs(yc*xe) < 10**-ye,
+ # so |y| < 1/xe and the result is not representable.
+ # Similarly, len(str(abs(yc)*xc_bits)) <= -ye implies |y|
+ # < 1/nbits(xc).
+
+ x = _WorkRep(self)
+ xc, xe = x.int, x.exp
+ while xc % 10 == 0:
+ xc //= 10
+ xe += 1
+
+ y = _WorkRep(other)
+ yc, ye = y.int, y.exp
+ while yc % 10 == 0:
+ yc //= 10
+ ye += 1
+
+ # case where xc == 1: result is 10**(xe*y), with xe*y
+ # required to be an integer
+ if xc == 1:
+ if ye >= 0:
+ exponent = xe*yc*10**ye
+ else:
+ exponent, remainder = divmod(xe*yc, 10**-ye)
+ if remainder:
+ return None
+ if y.sign == 1:
+ exponent = -exponent
+ # if other is a nonnegative integer, use ideal exponent
+ if other._isinteger() and other._sign == 0:
+ ideal_exponent = self._exp*int(other)
+ zeros = min(exponent-ideal_exponent, p-1)
+ else:
+ zeros = 0
+ return Decimal((0, (1,) + (0,)*zeros, exponent-zeros))
+
+ # case where y is negative: xc must be either a power
+ # of 2 or a power of 5.
+ if y.sign == 1:
+ last_digit = xc % 10
+ if last_digit in (2,4,6,8):
+ # quick test for power of 2
+ if xc & -xc != xc:
+ return None
+ # now xc is a power of 2; e is its exponent
+ e = _nbits(xc)-1
+ # find e*y and xe*y; both must be integers
+ if ye >= 0:
+ y_as_int = yc*10**ye
+ e = e*y_as_int
+ xe = xe*y_as_int
+ else:
+ ten_pow = 10**-ye
+ e, remainder = divmod(e*yc, ten_pow)
+ if remainder:
+ return None
+ xe, remainder = divmod(xe*yc, ten_pow)
+ if remainder:
+ return None
+
+ if e*65 >= p*93: # 93/65 > log(10)/log(5)
+ return None
+ xc = 5**e
+
+ elif last_digit == 5:
+ # e >= log_5(xc) if xc is a power of 5; we have
+ # equality all the way up to xc=5**2658
+ e = _nbits(xc)*28//65
+ xc, remainder = divmod(5**e, xc)
+ if remainder:
+ return None
+ while xc % 5 == 0:
+ xc //= 5
+ e -= 1
+ if ye >= 0:
+ y_as_integer = yc*10**ye
+ e = e*y_as_integer
+ xe = xe*y_as_integer
+ else:
+ ten_pow = 10**-ye
+ e, remainder = divmod(e*yc, ten_pow)
+ if remainder:
+ return None
+ xe, remainder = divmod(xe*yc, ten_pow)
+ if remainder:
+ return None
+ if e*3 >= p*10: # 10/3 > log(10)/log(2)
+ return None
+ xc = 2**e
+ else:
+ return None
+
+ if xc >= 10**p:
+ return None
+ xe = -e-xe
+ return Decimal((0, list(map(int, str(xc))), xe))
+
+ # now y is positive; find m and n such that y = m/n
+ if ye >= 0:
+ m, n = yc*10**ye, 1
+ else:
+ if xe != 0 and len(str(abs(yc*xe))) <= -ye:
+ return None
+ xc_bits = _nbits(xc)
+ if xc != 1 and len(str(abs(yc)*xc_bits)) <= -ye:
+ return None
+ m, n = yc, 10**(-ye)
+ while m % 2 == n % 2 == 0:
+ m //= 2
+ n //= 2
+ while m % 5 == n % 5 == 0:
+ m //= 5
+ n //= 5
+
+ # compute nth root of xc*10**xe
+ if n > 1:
+ # if 1 < xc < 2**n then xc isn't an nth power
+ if xc != 1 and xc_bits <= n:
+ return None
+
+ xe, rem = divmod(xe, n)
+ if rem != 0:
+ return None
+
+ # compute nth root of xc using Newton's method
+ a = 1 << -(-_nbits(xc)//n) # initial estimate
+ while True:
+ q, r = divmod(xc, a**(n-1))
+ if a <= q:
+ break
+ else:
+ a = (a*(n-1) + q)//n
+ if not (a == q and r == 0):
+ return None
+ xc = a
+
+ # now xc*10**xe is the nth root of the original xc*10**xe
+ # compute mth power of xc*10**xe
+
+ # if m > p*100//_log10_lb(xc) then m > p/log10(xc), hence xc**m >
+ # 10**p and the result is not representable.
+ if xc > 1 and m > p*100//_log10_lb(xc):
+ return None
+ xc = xc**m
+ xe *= m
+ if xc > 10**p:
+ return None
+
+ # by this point the result *is* exactly representable
+ # adjust the exponent to get as close as possible to the ideal
+ # exponent, if necessary
+ str_xc = str(xc)
+ if other._isinteger() and other._sign == 0:
+ ideal_exponent = self._exp*int(other)
+ zeros = min(xe-ideal_exponent, p-len(str_xc))
+ else:
+ zeros = 0
+ return Decimal((0, list(map(int, str_xc))+[0,]*zeros, xe-zeros))
- if not n._isinteger():
- return context._raise_error(InvalidOperation, 'x ** (non-integer)')
+ def __pow__(self, other, modulo=None, context=None):
+ """Return self ** other [ % modulo].
- if not self and not n:
- return context._raise_error(InvalidOperation, '0 ** 0')
+ With two arguments, compute self**other.
+
+ With three arguments, compute (self**other) % modulo. For the
+ three argument form, the following restrictions on the
+ arguments hold:
+
+ - all three arguments must be integral
+ - other must be nonnegative
+ - either self or other (or both) must be nonzero
+ - modulo must be nonzero and must have at most p digits,
+ where p is the context precision.
+
+ If any of these restrictions is violated the InvalidOperation
+ flag is raised.
+
+ The result of pow(self, other, modulo) is identical to the
+ result that would be obtained by computing (self**other) %
+ modulo with unbounded precision, but is computed more
+ efficiently. It is always exact.
+ """
+
+ if modulo is not None:
+ return self._power_modulo(other, modulo, context)
+
+ other = _convert_other(other)
+ if other is NotImplemented:
+ return other
+
+ if context is None:
+ context = getcontext()
+
+ # either argument is a NaN => result is NaN
+ ans = self._check_nans(other, context)
+ if ans:
+ return ans
- if not n:
- return Decimal(1)
+ # 0**0 = NaN (!), x**0 = 1 for nonzero x (including +/-Infinity)
+ if not other:
+ if not self:
+ return context._raise_error(InvalidOperation, '0 ** 0')
+ else:
+ return Dec_p1
- if self == Decimal(1):
- return Decimal(1)
+ # result has sign 1 iff self._sign is 1 and other is an odd integer
+ result_sign = 0
+ if self._sign == 1:
+ if other._isinteger():
+ if not other._iseven():
+ result_sign = 1
+ else:
+ # -ve**noninteger = NaN
+ # (-0)**noninteger = 0**noninteger
+ if self:
+ return context._raise_error(InvalidOperation,
+ 'x ** y with x negative and y not an integer')
+ # negate self, without doing any unwanted rounding
+ self = Decimal((0, self._int, self._exp))
- sign = self._sign and not n._iseven()
- n = int(n)
+ # 0**(+ve or Inf)= 0; 0**(-ve or -Inf) = Infinity
+ if not self:
+ if other._sign == 0:
+ return Decimal((result_sign, (0,), 0))
+ else:
+ return Infsign[result_sign]
+ # Inf**(+ve or Inf) = Inf; Inf**(-ve or -Inf) = 0
if self._isinfinity():
- if modulo:
- return context._raise_error(InvalidOperation, 'INF % x')
- if n > 0:
- return Infsign[sign]
- return Decimal( (sign, (0,), 0) )
+ if other._sign == 0:
+ return Infsign[result_sign]
+ else:
+ return Decimal((result_sign, (0,), 0))
- # With ludicrously large exponent, just raise an overflow
- # and return inf.
- if not modulo and n > 0 and \
- (self._exp + len(self._int) - 1) * n > context.Emax and self:
+ # 1**other = 1, but the choice of exponent and the flags
+ # depend on the exponent of self, and on whether other is a
+ # positive integer, a negative integer, or neither
+ if self == Dec_p1:
+ if other._isinteger():
+ # exp = max(self._exp*max(int(other), 0),
+ # 1-context.prec) but evaluating int(other) directly
+ # is dangerous until we know other is small (other
+ # could be 1e999999999)
+ if other._sign == 1:
+ multiplier = 0
+ elif other > context.prec:
+ multiplier = context.prec
+ else:
+ multiplier = int(other)
- tmp = Decimal('inf')
- tmp._sign = sign
- context._raise_error(Rounded)
- context._raise_error(Inexact)
- context._raise_error(Overflow, 'Big power', sign)
- return tmp
+ exp = self._exp * multiplier
+ if exp < 1-context.prec:
+ exp = 1-context.prec
+ context._raise_error(Rounded)
+ else:
+ context._raise_error(Inexact)
+ context._raise_error(Rounded)
+ exp = 1-context.prec
+
+ return Decimal((result_sign, (1,)+(0,)*-exp, exp))
+
+ # compute adjusted exponent of self
+ self_adj = self.adjusted()
+
+ # self ** infinity is infinity if self > 1, 0 if self < 1
+ # self ** -infinity is infinity if self < 1, 0 if self > 1
+ if other._isinfinity():
+ if (other._sign == 0) == (self_adj < 0):
+ return Decimal((result_sign, (0,), 0))
+ else:
+ return Infsign[result_sign]
- elength = len(str(abs(n)))
- firstprec = context.prec
+ # from here on, the result always goes through the call
+ # to _fix at the end of this function.
+ ans = None
+
+ # crude test to catch cases of extreme overflow/underflow. If
+ # log10(self)*other >= 10**bound and bound >= len(str(Emax))
+ # then 10**bound >= 10**len(str(Emax)) >= Emax+1 and hence
+ # self**other >= 10**(Emax+1), so overflow occurs. The test
+ # for underflow is similar.
+ bound = self._log10_exp_bound() + other.adjusted()
+ if (self_adj >= 0) == (other._sign == 0):
+ # self > 1 and other +ve, or self < 1 and other -ve
+ # possibility of overflow
+ if bound >= len(str(context.Emax)):
+ ans = Decimal((result_sign, (1,), context.Emax+1))
+ else:
+ # self > 1 and other -ve, or self < 1 and other +ve
+ # possibility of underflow to 0
+ Etiny = context.Etiny()
+ if bound >= len(str(-Etiny)):
+ ans = Decimal((result_sign, (1,), Etiny-1))
- if not modulo and firstprec + elength + 1 > DefaultContext.Emax:
- return context._raise_error(Overflow, 'Too much precision.', sign)
+ # try for an exact result with precision +1
+ if ans is None:
+ ans = self._power_exact(other, context.prec + 1)
+ if ans is not None and result_sign == 1:
+ ans = Decimal((1, ans._int, ans._exp))
+
+ # usual case: inexact result, x**y computed directly as exp(y*log(x))
+ if ans is None:
+ p = context.prec
+ x = _WorkRep(self)
+ xc, xe = x.int, x.exp
+ y = _WorkRep(other)
+ yc, ye = y.int, y.exp
+ if y.sign == 1:
+ yc = -yc
+
+ # compute correctly rounded result: start with precision +3,
+ # then increase precision until result is unambiguously roundable
+ extra = 3
+ while True:
+ coeff, exp = _dpower(xc, xe, yc, ye, p+extra)
+ if coeff % (5*10**(len(str(coeff))-p-1)):
+ break
+ extra += 3
- mul = Decimal(self)
- val = Decimal(1)
- context = context._shallow_copy()
- context.prec = firstprec + elength + 1
- if n < 0:
- # n is a long now, not Decimal instance
- n = -n
- mul = Decimal(1).__truediv__(mul, context=context)
-
- spot = 1
- while spot <= n:
- spot <<= 1
-
- spot >>= 1
- # spot is the highest power of 2 less than n
- while spot:
- val = val.__mul__(val, context=context)
- if val._isinfinity():
- val = Infsign[sign]
- break
- if spot & n:
- val = val.__mul__(mul, context=context)
- if modulo is not None:
- val = val.__mod__(modulo, context=context)
- spot >>= 1
- context.prec = firstprec
+ ans = Decimal((result_sign, list(map(int, str(coeff))), exp))
- if context._rounding_decision == ALWAYS_ROUND:
- return val._fix(context)
- return val
+ # the specification says that for non-integer other we need to
+ # raise Inexact, even when the result is actually exact. In
+ # the same way, we need to raise Underflow here if the result
+ # is subnormal. (The call to _fix will take care of raising
+ # Rounded and Subnormal, as usual.)
+ if not other._isinteger():
+ context._raise_error(Inexact)
+ # pad with zeros up to length context.prec+1 if necessary
+ if len(ans._int) <= context.prec:
+ expdiff = context.prec+1 - len(ans._int)
+ ans = Decimal((ans._sign, ans._int+(0,)*expdiff, ans._exp-expdiff))
+ if ans.adjusted() < context.Emin:
+ context._raise_error(Underflow)
+
+ # unlike exp, ln and log10, the power function respects the
+ # rounding mode; no need to use ROUND_HALF_EVEN here
+ ans = ans._fix(context)
+ return ans
def __rpow__(self, other, context=None):
"""Swaps self/other and returns __pow__."""
@@ -1853,6 +2159,9 @@
def normalize(self, context=None):
"""Normalize- strip trailing 0s, change anything equal to 0 to 0e0"""
+ if context is None:
+ context = getcontext()
+
if self._is_special:
ans = self._check_nans(context=context)
if ans:
@@ -1864,19 +2173,26 @@
if not dup:
return Decimal( (dup._sign, (0,), 0) )
+ exp_max = [context.Emax, context.Etop()][context._clamp]
end = len(dup._int)
exp = dup._exp
- while dup._int[end-1] == 0:
+ while dup._int[end-1] == 0 and exp < exp_max:
exp += 1
end -= 1
return Decimal( (dup._sign, dup._int[:end], exp) )
-
- def quantize(self, exp, rounding=None, context=None, watchexp=1):
+ def quantize(self, exp, rounding=None, context=None, watchexp=True):
"""Quantize self so its exponent is the same as that of exp.
Similar to self._rescale(exp._exp) but with error checking.
"""
+ exp = _convert_other(exp, raiseit=True)
+
+ if context is None:
+ context = getcontext()
+ if rounding is None:
+ rounding = context.rounding
+
if self._is_special or exp._is_special:
ans = self._check_nans(exp, context)
if ans:
@@ -1884,12 +2200,56 @@
if exp._isinfinity() or self._isinfinity():
if exp._isinfinity() and self._isinfinity():
- return self # if both are inf, it is OK
- if context is None:
- context = getcontext()
+ return Decimal(self) # if both are inf, it is OK
return context._raise_error(InvalidOperation,
'quantize with one INF')
- return self._rescale(exp._exp, rounding, context, watchexp)
+
+ # if we're not watching exponents, do a simple rescale
+ if not watchexp:
+ ans = self._rescale(exp._exp, rounding)
+ # raise Inexact and Rounded where appropriate
+ if ans._exp > self._exp:
+ context._raise_error(Rounded)
+ if ans != self:
+ context._raise_error(Inexact)
+ return ans
+
+ # exp._exp should be between Etiny and Emax
+ if not (context.Etiny() <= exp._exp <= context.Emax):
+ return context._raise_error(InvalidOperation,
+ 'target exponent out of bounds in quantize')
+
+ if not self:
+ ans = Decimal((self._sign, (0,), exp._exp))
+ return ans._fix(context)
+
+ self_adjusted = self.adjusted()
+ if self_adjusted > context.Emax:
+ return context._raise_error(InvalidOperation,
+ 'exponent of quantize result too large for current context')
+ if self_adjusted - exp._exp + 1 > context.prec:
+ return context._raise_error(InvalidOperation,
+ 'quantize result has too many digits for current context')
+
+ ans = self._rescale(exp._exp, rounding)
+ if ans.adjusted() > context.Emax:
+ return context._raise_error(InvalidOperation,
+ 'exponent of quantize result too large for current context')
+ if len(ans._int) > context.prec:
+ return context._raise_error(InvalidOperation,
+ 'quantize result has too many digits for current context')
+
+ # raise appropriate flags
+ if ans._exp > self._exp:
+ context._raise_error(Rounded)
+ if ans != self:
+ context._raise_error(Inexact)
+ if ans and ans.adjusted() < context.Emin:
+ context._raise_error(Subnormal)
+
+ # call to fix takes care of any necessary folddown
+ ans = ans._fix(context)
+ return ans
def same_quantum(self, other):
"""Test whether self and other have the same exponent.
@@ -1903,83 +2263,85 @@
return self._isinfinity() and other._isinfinity() and True
return self._exp == other._exp
- def _rescale(self, exp, rounding=None, context=None, watchexp=1):
- """Rescales so that the exponent is exp.
+ def _rescale(self, exp, rounding):
+ """Rescale self so that the exponent is exp, either by padding with zeros
+ or by truncating digits, using the given rounding mode.
+
+ Specials are returned without change. This operation is
+ quiet: it raises no flags, and uses no information from the
+ context.
exp = exp to scale to (an integer)
- rounding = rounding version
- watchexp: if set (default) an error is returned if exp is greater
- than Emax or less than Etiny.
+ rounding = rounding mode
"""
- if context is None:
- context = getcontext()
-
if self._is_special:
- if self._isinfinity():
- return context._raise_error(InvalidOperation, 'rescale with an INF')
-
- ans = self._check_nans(context=context)
- if ans:
- return ans
-
- if watchexp and (context.Emax < exp or context.Etiny() > exp):
- return context._raise_error(InvalidOperation, 'rescale(a, INF)')
-
+ return Decimal(self)
if not self:
- ans = Decimal(self)
- ans._int = (0,)
- ans._exp = exp
- return ans
-
- diff = self._exp - exp
- digits = len(self._int) + diff
-
- if watchexp and digits > context.prec:
- return context._raise_error(InvalidOperation, 'Rescale > prec')
-
- tmp = Decimal(self)
- tmp._int = (0,) + tmp._int
- digits += 1
+ return Decimal((self._sign, (0,), exp))
+ if self._exp >= exp:
+ # pad answer with zeros if necessary
+ return Decimal((self._sign, self._int + (0,)*(self._exp - exp), exp))
+
+ # too many digits; round and lose data. If self.adjusted() <
+ # exp-1, replace self by 10**(exp-1) before rounding
+ digits = len(self._int) + self._exp - exp
if digits < 0:
- tmp._exp = -digits + tmp._exp
- tmp._int = (0,1)
- digits = 1
- tmp = tmp._round(digits, rounding, context=context)
-
- if tmp._int[0] == 0 and len(tmp._int) > 1:
- tmp._int = tmp._int[1:]
- tmp._exp = exp
-
- tmp_adjusted = tmp.adjusted()
- if tmp and tmp_adjusted < context.Emin:
- context._raise_error(Subnormal)
- elif tmp and tmp_adjusted > context.Emax:
- return context._raise_error(InvalidOperation, 'rescale(a, INF)')
- return tmp
+ self = Decimal((self._sign, (1,), exp-1))
+ digits = 0
+ this_function = getattr(self, self._pick_rounding_function[rounding])
+ return this_function(digits)
+
+ def to_integral_exact(self, rounding=None, context=None):
+ """Rounds to a nearby integer.
+
+ If no rounding mode is specified, take the rounding mode from
+ the context. This method raises the Rounded and Inexact flags
+ when appropriate.
- def to_integral(self, rounding=None, context=None):
- """Rounds to the nearest integer, without raising inexact, rounded."""
+ See also: to_integral_value, which does exactly the same as
+ this method except that it doesn't raise Inexact or Rounded.
+ """
if self._is_special:
ans = self._check_nans(context=context)
if ans:
return ans
- return self
+ return Decimal(self)
if self._exp >= 0:
- return self
+ return Decimal(self)
+ if not self:
+ return Decimal((self._sign, (0,), 0))
if context is None:
context = getcontext()
- flags = context._ignore_flags(Rounded, Inexact)
- ans = self._rescale(0, rounding, context=context)
- context._regard_flags(flags)
+ if rounding is None:
+ rounding = context.rounding
+ context._raise_error(Rounded)
+ ans = self._rescale(0, rounding)
+ if ans != self:
+ context._raise_error(Inexact)
return ans
- def sqrt(self, context=None):
- """Return the square root of self.
+ def to_integral_value(self, rounding=None, context=None):
+ """Rounds to the nearest integer, without raising inexact, rounded."""
+ if context is None:
+ context = getcontext()
+ if rounding is None:
+ rounding = context.rounding
+ if self._is_special:
+ ans = self._check_nans(context=context)
+ if ans:
+ return ans
+ return Decimal(self)
+ if self._exp >= 0:
+ return Decimal(self)
+ else:
+ return self._rescale(0, rounding)
- Uses a converging algorithm (Xn+1 = 0.5*(Xn + self / Xn))
- Should quadratically approach the right answer.
- """
+ # the method name changed, but we provide also the old one, for compatibility
+ to_integral = to_integral_value
+
+ def sqrt(self, context=None):
+ """Return the square root of self."""
if self._is_special:
ans = self._check_nans(context=context)
if ans:
@@ -1989,16 +2351,9 @@
return Decimal(self)
if not self:
- # exponent = self._exp / 2, using round_down.
- # if self._exp < 0:
- # exp = (self._exp+1) // 2
- # else:
- exp = (self._exp) // 2
- if self._sign == 1:
- # sqrt(-0) = -0
- return Decimal( (1, (0,), exp))
- else:
- return Decimal( (0, (0,), exp))
+ # exponent = self._exp // 2. sqrt(-0) = -0
+ ans = Decimal((self._sign, (0,), self._exp // 2))
+ return ans._fix(context)
if context is None:
context = getcontext()
@@ -2006,104 +2361,94 @@
if self._sign == 1:
return context._raise_error(InvalidOperation, 'sqrt(-x), x > 0')
- tmp = Decimal(self)
-
- expadd = tmp._exp // 2
- if tmp._exp & 1:
- tmp._int += (0,)
- tmp._exp = 0
+ # At this point self represents a positive number. Let p be
+ # the desired precision and express self in the form c*100**e
+ # with c a positive real number and e an integer, c and e
+ # being chosen so that 100**(p-1) <= c < 100**p. Then the
+ # (exact) square root of self is sqrt(c)*10**e, and 10**(p-1)
+ # <= sqrt(c) < 10**p, so the closest representable Decimal at
+ # precision p is n*10**e where n = round_half_even(sqrt(c)),
+ # the closest integer to sqrt(c) with the even integer chosen
+ # in the case of a tie.
+ #
+ # To ensure correct rounding in all cases, we use the
+ # following trick: we compute the square root to an extra
+ # place (precision p+1 instead of precision p), rounding down.
+ # Then, if the result is inexact and its last digit is 0 or 5,
+ # we increase the last digit to 1 or 6 respectively; if it's
+ # exact we leave the last digit alone. Now the final round to
+ # p places (or fewer in the case of underflow) will round
+ # correctly and raise the appropriate flags.
+
+ # use an extra digit of precision
+ prec = context.prec+1
+
+ # write argument in the form c*100**e where e = self._exp//2
+ # is the 'ideal' exponent, to be used if the square root is
+ # exactly representable. l is the number of 'digits' of c in
+ # base 100, so that 100**(l-1) <= c < 100**l.
+ op = _WorkRep(self)
+ e = op.exp >> 1
+ if op.exp & 1:
+ c = op.int * 10
+ l = (len(self._int) >> 1) + 1
else:
- tmp._exp = 0
-
- context = context._shallow_copy()
- flags = context._ignore_all_flags()
- firstprec = context.prec
- context.prec = 3
- if tmp.adjusted() & 1 == 0:
- ans = Decimal( (0, (8,1,9), tmp.adjusted() - 2) )
- ans = ans.__add__(tmp.__mul__(Decimal((0, (2,5,9), -2)),
- context=context), context=context)
- ans._exp -= 1 + tmp.adjusted() // 2
- else:
- ans = Decimal( (0, (2,5,9), tmp._exp + len(tmp._int)- 3) )
- ans = ans.__add__(tmp.__mul__(Decimal((0, (8,1,9), -3)),
- context=context), context=context)
- ans._exp -= 1 + tmp.adjusted() // 2
-
- # ans is now a linear approximation.
- Emax, Emin = context.Emax, context.Emin
- context.Emax, context.Emin = DefaultContext.Emax, DefaultContext.Emin
+ c = op.int
+ l = len(self._int)+1 >> 1
- half = Decimal('0.5')
-
- maxp = firstprec + 2
- rounding = context._set_rounding(ROUND_HALF_EVEN)
- while 1:
- context.prec = min(2*context.prec - 2, maxp)
- ans = half.__mul__(ans.__add__(tmp.__truediv__(ans, context=context),
- context=context), context=context)
- if context.prec == maxp:
+ # rescale so that c has exactly prec base 100 'digits'
+ shift = prec-l
+ if shift >= 0:
+ c *= 100**shift
+ exact = True
+ else:
+ c, remainder = divmod(c, 100**-shift)
+ exact = not remainder
+ e -= shift
+
+ # find n = floor(sqrt(c)) using Newton's method
+ n = 10**prec
+ while True:
+ q = c//n
+ if n <= q:
break
+ else:
+ n = n + q >> 1
+ exact = exact and n*n == c
- # Round to the answer's precision-- the only error can be 1 ulp.
- context.prec = firstprec
- prevexp = ans.adjusted()
- ans = ans._round(context=context)
-
- # Now, check if the other last digits are better.
- context.prec = firstprec + 1
- # In case we rounded up another digit and we should actually go lower.
- if prevexp != ans.adjusted():
- ans._int += (0,)
- ans._exp -= 1
-
-
- lower = ans.__sub__(Decimal((0, (5,), ans._exp-1)), context=context)
- context._set_rounding(ROUND_UP)
- if lower.__mul__(lower, context=context) > (tmp):
- ans = ans.__sub__(Decimal((0, (1,), ans._exp)), context=context)
-
+ if exact:
+ # result is exact; rescale to use ideal exponent e
+ if shift >= 0:
+ # assert n % 10**shift == 0
+ n //= 10**shift
+ else:
+ n *= 10**-shift
+ e += shift
else:
- upper = ans.__add__(Decimal((0, (5,), ans._exp-1)),context=context)
- context._set_rounding(ROUND_DOWN)
- if upper.__mul__(upper, context=context) < tmp:
- ans = ans.__add__(Decimal((0, (1,), ans._exp)),context=context)
+ # result is not exact; fix last digit as described above
+ if n % 5 == 0:
+ n += 1
- ans._exp += expadd
+ ans = Decimal((0, list(map(int, str(n))), e))
- context.prec = firstprec
- context.rounding = rounding
+ # round, and fit to current context
+ context = context._shallow_copy()
+ rounding = context._set_rounding(ROUND_HALF_EVEN)
ans = ans._fix(context)
+ context.rounding = rounding
- rounding = context._set_rounding_decision(NEVER_ROUND)
- if not ans.__mul__(ans, context=context) == self:
- # Only rounded/inexact if here.
- context._regard_flags(flags)
- context._raise_error(Rounded)
- context._raise_error(Inexact)
- else:
- # Exact answer, so let's set the exponent right.
- # if self._exp < 0:
- # exp = (self._exp +1)// 2
- # else:
- exp = self._exp // 2
- context.prec += ans._exp - exp
- ans = ans._rescale(exp, context=context)
- context.prec = firstprec
- context._regard_flags(flags)
- context.Emax, context.Emin = Emax, Emin
-
- return ans._fix(context)
+ return ans
def max(self, other, context=None):
"""Returns the larger value.
- like max(self, other) except if one is not a number, returns
+ Like max(self, other) except if one is not a number, returns
NaN (and signals if one is sNaN). Also rounds.
"""
- other = _convert_other(other)
- if other is NotImplemented:
- return other
+ other = _convert_other(other, raiseit=True)
+
+ if context is None:
+ context = getcontext()
if self._is_special or other._is_special:
# If one operand is a quiet NaN and the other is number, then the
@@ -2112,12 +2457,11 @@
on = other._isnan()
if sn or on:
if on == 1 and sn != 2:
- return self
+ return self._fix_nan(context)
if sn == 1 and on != 2:
- return other
+ return other._fix_nan(context)
return self._check_nans(other, context)
- ans = self
c = self.__cmp__(other)
if c == 0:
# If both operands are finite and equal in numerical value
@@ -2127,19 +2471,14 @@
# positive sign and min returns the operand with the negative sign
#
# If the signs are the same then the exponent is used to select
- # the result.
- if self._sign != other._sign:
- if self._sign:
- ans = other
- elif self._exp < other._exp and not self._sign:
- ans = other
- elif self._exp > other._exp and self._sign:
- ans = other
- elif c == -1:
+ # the result. This is exactly the ordering used in compare_total.
+ c = self.compare_total(other)
+
+ if c == -1:
ans = other
+ else:
+ ans = self
- if context is None:
- context = getcontext()
if context._rounding_decision == ALWAYS_ROUND:
return ans._fix(context)
return ans
@@ -2150,9 +2489,10 @@
Like min(self, other) except if one is not a number, returns
NaN (and signals if one is sNaN). Also rounds.
"""
- other = _convert_other(other)
- if other is NotImplemented:
- return other
+ other = _convert_other(other, raiseit=True)
+
+ if context is None:
+ context = getcontext()
if self._is_special or other._is_special:
# If one operand is a quiet NaN and the other is number, then the
@@ -2161,49 +2501,37 @@
on = other._isnan()
if sn or on:
if on == 1 and sn != 2:
- return self
+ return self._fix_nan(context)
if sn == 1 and on != 2:
- return other
+ return other._fix_nan(context)
return self._check_nans(other, context)
- ans = self
c = self.__cmp__(other)
if c == 0:
- # If both operands are finite and equal in numerical value
- # then an ordering is applied:
- #
- # If the signs differ then max returns the operand with the
- # positive sign and min returns the operand with the negative sign
- #
- # If the signs are the same then the exponent is used to select
- # the result.
- if self._sign != other._sign:
- if other._sign:
- ans = other
- elif self._exp > other._exp and not self._sign:
- ans = other
- elif self._exp < other._exp and self._sign:
- ans = other
- elif c == 1:
+ c = self.compare_total(other)
+
+ if c == -1:
+ ans = self
+ else:
ans = other
- if context is None:
- context = getcontext()
if context._rounding_decision == ALWAYS_ROUND:
return ans._fix(context)
return ans
def _isinteger(self):
"""Returns whether self is an integer"""
+ if self._is_special:
+ return False
if self._exp >= 0:
return True
rest = self._int[self._exp:]
return rest == (0,)*len(rest)
def _iseven(self):
- """Returns 1 if self is even. Assumes self is an integer."""
- if self._exp > 0:
- return 1
+ """Returns True if self is even. Assumes self is an integer."""
+ if not self or self._exp > 0:
+ return True
return self._int[-1+self._exp] & 1 == 0
def adjusted(self):
@@ -2214,6 +2542,875 @@
except TypeError:
return 0
+ def canonical(self, context=None):
+ """Returns the same Decimal object.
+
+ As we do not have different encodings for the same number, the
+ received object already is in its canonical form.
+ """
+ return self
+
+ def compare_signal(self, other, context=None):
+ """Compares self to the other operand numerically.
+
+ It's pretty much like compare(), but all NaNs signal, with signaling
+ NaNs taking precedence over quiet NaNs.
+ """
+ if context is None:
+ context = getcontext()
+
+ self_is_nan = self._isnan()
+ other_is_nan = other._isnan()
+ if self_is_nan == 2:
+ return context._raise_error(InvalidOperation, 'sNaN',
+ 1, self)
+ if other_is_nan == 2:
+ return context._raise_error(InvalidOperation, 'sNaN',
+ 1, other)
+ if self_is_nan:
+ return context._raise_error(InvalidOperation, 'NaN in compare_signal',
+ 1, self)
+ if other_is_nan:
+ return context._raise_error(InvalidOperation, 'NaN in compare_signal',
+ 1, other)
+ return self.compare(other, context=context)
+
+ def compare_total(self, other):
+ """Compares self to other using the abstract representations.
+
+ This is not like the standard compare, which use their numerical
+ value. Note that a total ordering is defined for all possible abstract
+ representations.
+ """
+ # if one is negative and the other is positive, it's easy
+ if self._sign and not other._sign:
+ return Dec_n1
+ if not self._sign and other._sign:
+ return Dec_p1
+ sign = self._sign
+
+ # let's handle both NaN types
+ self_nan = self._isnan()
+ other_nan = other._isnan()
+ if self_nan or other_nan:
+ if self_nan == other_nan:
+ if self._int < other._int:
+ if sign:
+ return Dec_p1
+ else:
+ return Dec_n1
+ if self._int > other._int:
+ if sign:
+ return Dec_n1
+ else:
+ return Dec_p1
+ return Dec_0
+
+ if sign:
+ if self_nan == 1:
+ return Dec_n1
+ if other_nan == 1:
+ return Dec_p1
+ if self_nan == 2:
+ return Dec_n1
+ if other_nan == 2:
+ return Dec_p1
+ else:
+ if self_nan == 1:
+ return Dec_p1
+ if other_nan == 1:
+ return Dec_n1
+ if self_nan == 2:
+ return Dec_p1
+ if other_nan == 2:
+ return Dec_n1
+
+ if self < other:
+ return Dec_n1
+ if self > other:
+ return Dec_p1
+
+ if self._exp < other._exp:
+ if sign:
+ return Dec_p1
+ else:
+ return Dec_n1
+ if self._exp > other._exp:
+ if sign:
+ return Dec_n1
+ else:
+ return Dec_p1
+ return Dec_0
+
+
+ def compare_total_mag(self, other):
+ """Compares self to other using abstract repr., ignoring sign.
+
+ Like compare_total, but with operand's sign ignored and assumed to be 0.
+ """
+ s = self.copy_abs()
+ o = other.copy_abs()
+ return s.compare_total(o)
+
+ def copy_abs(self):
+ """Returns a copy with the sign set to 0. """
+ return Decimal((0, self._int, self._exp))
+
+ def copy_negate(self):
+ """Returns a copy with the sign inverted."""
+ if self._sign:
+ return Decimal((0, self._int, self._exp))
+ else:
+ return Decimal((1, self._int, self._exp))
+
+ def copy_sign(self, other):
+ """Returns self with the sign of other."""
+ return Decimal((other._sign, self._int, self._exp))
+
+ def exp(self, context=None):
+ """Returns e ** self."""
+
+ if context is None:
+ context = getcontext()
+
+ # exp(NaN) = NaN
+ ans = self._check_nans(context=context)
+ if ans:
+ return ans
+
+ # exp(-Infinity) = 0
+ if self._isinfinity() == -1:
+ return Dec_0
+
+ # exp(0) = 1
+ if not self:
+ return Dec_p1
+
+ # exp(Infinity) = Infinity
+ if self._isinfinity() == 1:
+ return Decimal(self)
+
+ # the result is now guaranteed to be inexact (the true
+ # mathematical result is transcendental). There's no need to
+ # raise Rounded and Inexact here---they'll always be raised as
+ # a result of the call to _fix.
+ p = context.prec
+ adj = self.adjusted()
+
+ # we only need to do any computation for quite a small range
+ # of adjusted exponents---for example, -29 <= adj <= 10 for
+ # the default context. For smaller exponent the result is
+ # indistinguishable from 1 at the given precision, while for
+ # larger exponent the result either overflows or underflows.
+ if self._sign == 0 and adj > len(str((context.Emax+1)*3)):
+ # overflow
+ ans = Decimal((0, (1,), context.Emax+1))
+ elif self._sign == 1 and adj > len(str((-context.Etiny()+1)*3)):
+ # underflow to 0
+ ans = Decimal((0, (1,), context.Etiny()-1))
+ elif self._sign == 0 and adj < -p:
+ # p+1 digits; final round will raise correct flags
+ ans = Decimal((0, (1,) + (0,)*(p-1) + (1,), -p))
+ elif self._sign == 1 and adj < -p-1:
+ # p+1 digits; final round will raise correct flags
+ ans = Decimal((0, (9,)*(p+1), -p-1))
+ # general case
+ else:
+ op = _WorkRep(self)
+ c, e = op.int, op.exp
+ if op.sign == 1:
+ c = -c
+
+ # compute correctly rounded result: increase precision by
+ # 3 digits at a time until we get an unambiguously
+ # roundable result
+ extra = 3
+ while True:
+ coeff, exp = _dexp(c, e, p+extra)
+ if coeff % (5*10**(len(str(coeff))-p-1)):
+ break
+ extra += 3
+
+ ans = Decimal((0, list(map(int, str(coeff))), exp))
+
+ # at this stage, ans should round correctly with *any*
+ # rounding mode, not just with ROUND_HALF_EVEN
+ context = context._shallow_copy()
+ rounding = context._set_rounding(ROUND_HALF_EVEN)
+ ans = ans._fix(context)
+ context.rounding = rounding
+
+ return ans
+
+ def is_canonical(self):
+ """Returns 1 if self is canonical; otherwise returns 0."""
+ return Dec_p1
+
+ def is_finite(self):
+ """Returns 1 if self is finite, otherwise returns 0.
+
+ For it to be finite, it must be neither infinite nor a NaN.
+ """
+ if self._is_special:
+ return Dec_0
+ else:
+ return Dec_p1
+
+ def is_infinite(self):
+ """Returns 1 if self is an Infinite, otherwise returns 0."""
+ if self._isinfinity():
+ return Dec_p1
+ else:
+ return Dec_0
+
+ def is_nan(self):
+ """Returns 1 if self is qNaN or sNaN, otherwise returns 0."""
+ if self._isnan():
+ return Dec_p1
+ else:
+ return Dec_0
+
+ def is_normal(self, context=None):
+ """Returns 1 if self is a normal number, otherwise returns 0."""
+ if self._is_special:
+ return Dec_0
+ if not self:
+ return Dec_0
+ if context is None:
+ context = getcontext()
+ if context.Emin <= self.adjusted() <= context.Emax:
+ return Dec_p1
+ else:
+ return Dec_0
+
+ def is_qnan(self):
+ """Returns 1 if self is a quiet NaN, otherwise returns 0."""
+ if self._isnan() == 1:
+ return Dec_p1
+ else:
+ return Dec_0
+
+ def is_signed(self):
+ """Returns 1 if self is negative, otherwise returns 0."""
+ return Decimal(self._sign)
+
+ def is_snan(self):
+ """Returns 1 if self is a signaling NaN, otherwise returns 0."""
+ if self._isnan() == 2:
+ return Dec_p1
+ else:
+ return Dec_0
+
+ def is_subnormal(self, context=None):
+ """Returns 1 if self is subnormal, otherwise returns 0."""
+ if self._is_special:
+ return Dec_0
+ if not self:
+ return Dec_0
+ if context is None:
+ context = getcontext()
+
+ r = self._exp + len(self._int)
+ if r <= context.Emin:
+ return Dec_p1
+ return Dec_0
+
+ def is_zero(self):
+ """Returns 1 if self is a zero, otherwise returns 0."""
+ if self:
+ return Dec_0
+ else:
+ return Dec_p1
+
+ def _ln_exp_bound(self):
+ """Compute a lower bound for the adjusted exponent of self.ln().
+ In other words, compute r such that self.ln() >= 10**r. Assumes
+ that self is finite and positive and that self != 1.
+ """
+
+ # for 0.1 <= x <= 10 we use the inequalities 1-1/x <= ln(x) <= x-1
+ adj = self._exp + len(self._int) - 1
+ if adj >= 1:
+ # argument >= 10; we use 23/10 = 2.3 as a lower bound for ln(10)
+ return len(str(adj*23//10)) - 1
+ if adj <= -2:
+ # argument <= 0.1
+ return len(str((-1-adj)*23//10)) - 1
+ op = _WorkRep(self)
+ c, e = op.int, op.exp
+ if adj == 0:
+ # 1 < self < 10
+ num = str(c-10**-e)
+ den = str(c)
+ return len(num) - len(den) - (num < den)
+ # adj == -1, 0.1 <= self < 1
+ return e + len(str(10**-e - c)) - 1
+
+
+ def ln(self, context=None):
+ """Returns the natural (base e) logarithm of self."""
+
+ if context is None:
+ context = getcontext()
+
+ # ln(NaN) = NaN
+ ans = self._check_nans(context=context)
+ if ans:
+ return ans
+
+ # ln(0.0) == -Infinity
+ if not self:
+ return negInf
+
+ # ln(Infinity) = Infinity
+ if self._isinfinity() == 1:
+ return Inf
+
+ # ln(1.0) == 0.0
+ if self == Dec_p1:
+ return Dec_0
+
+ # ln(negative) raises InvalidOperation
+ if self._sign == 1:
+ return context._raise_error(InvalidOperation,
+ 'ln of a negative value')
+
+ # result is irrational, so necessarily inexact
+ op = _WorkRep(self)
+ c, e = op.int, op.exp
+ p = context.prec
+
+ # correctly rounded result: repeatedly increase precision by 3
+ # until we get an unambiguously roundable result
+ places = p - self._ln_exp_bound() + 2 # at least p+3 places
+ while True:
+ coeff = _dlog(c, e, places)
+ # assert len(str(abs(coeff)))-p >= 1
+ if coeff % (5*10**(len(str(abs(coeff)))-p-1)):
+ break
+ places += 3
+ ans = Decimal((int(coeff<0), list(map(int, str(abs(coeff)))), -places))
+
+ context = context._shallow_copy()
+ rounding = context._set_rounding(ROUND_HALF_EVEN)
+ ans = ans._fix(context)
+ context.rounding = rounding
+ return ans
+
+ def _log10_exp_bound(self):
+ """Compute a lower bound for the adjusted exponent of self.log10().
+ In other words, find r such that self.log10() >= 10**r.
+ Assumes that self is finite and positive and that self != 1.
+ """
+
+ # For x >= 10 or x < 0.1 we only need a bound on the integer
+ # part of log10(self), and this comes directly from the
+ # exponent of x. For 0.1 <= x <= 10 we use the inequalities
+ # 1-1/x <= log(x) <= x-1. If x > 1 we have |log10(x)| >
+ # (1-1/x)/2.31 > 0. If x < 1 then |log10(x)| > (1-x)/2.31 > 0
+
+ adj = self._exp + len(self._int) - 1
+ if adj >= 1:
+ # self >= 10
+ return len(str(adj))-1
+ if adj <= -2:
+ # self < 0.1
+ return len(str(-1-adj))-1
+ op = _WorkRep(self)
+ c, e = op.int, op.exp
+ if adj == 0:
+ # 1 < self < 10
+ num = str(c-10**-e)
+ den = str(231*c)
+ return len(num) - len(den) - (num < den) + 2
+ # adj == -1, 0.1 <= self < 1
+ num = str(10**-e-c)
+ return len(num) + e - (num < "231") - 1
+
+ def log10(self, context=None):
+ """Returns the base 10 logarithm of self."""
+
+ if context is None:
+ context = getcontext()
+
+ # log10(NaN) = NaN
+ ans = self._check_nans(context=context)
+ if ans:
+ return ans
+
+ # log10(0.0) == -Infinity
+ if not self:
+ return negInf
+
+ # log10(Infinity) = Infinity
+ if self._isinfinity() == 1:
+ return Inf
+
+ # log10(negative or -Infinity) raises InvalidOperation
+ if self._sign == 1:
+ return context._raise_error(InvalidOperation,
+ 'log10 of a negative value')
+
+ # log10(10**n) = n
+ if self._int[0] == 1 and self._int[1:] == (0,)*(len(self._int) - 1):
+ # answer may need rounding
+ ans = Decimal(self._exp + len(self._int) - 1)
+ else:
+ # result is irrational, so necessarily inexact
+ op = _WorkRep(self)
+ c, e = op.int, op.exp
+ p = context.prec
+
+ # correctly rounded result: repeatedly increase precision
+ # until result is unambiguously roundable
+ places = p-self._log10_exp_bound()+2
+ while True:
+ coeff = _dlog10(c, e, places)
+ # assert len(str(abs(coeff)))-p >= 1
+ if coeff % (5*10**(len(str(abs(coeff)))-p-1)):
+ break
+ places += 3
+ ans = Decimal((int(coeff<0), list(map(int, str(abs(coeff)))),
+ -places))
+
+ context = context._shallow_copy()
+ rounding = context._set_rounding(ROUND_HALF_EVEN)
+ ans = ans._fix(context)
+ context.rounding = rounding
+ return ans
+
+ def logb(self, context=None):
+ """ Returns the exponent of the magnitude of self's MSD.
+
+ The result is the integer which is the exponent of the magnitude
+ of the most significant digit of self (as though it were truncated
+ to a single digit while maintaining the value of that digit and
+ without limiting the resulting exponent).
+ """
+ # logb(NaN) = NaN
+ ans = self._check_nans(context=context)
+ if ans:
+ return ans
+
+ if context is None:
+ context = getcontext()
+
+ # logb(+/-Inf) = +Inf
+ if self._isinfinity():
+ return Inf
+
+ # logb(0) = -Inf, DivisionByZero
+ if not self:
+ return context._raise_error(DivisionByZero, 'logb(0)', 1)
+
+ # otherwise, simply return the adjusted exponent of self, as a
+ # Decimal. Note that no attempt is made to fit the result
+ # into the current context.
+ return Decimal(self.adjusted())
+
+ def _islogical(self):
+ """Return True if self is a logical operand.
+
+ For being logical, it must be a finite numbers with a sign of 0,
+ an exponent of 0, and a coefficient whose digits must all be
+ either 0 or 1.
+ """
+ if self._sign != 0 or self._exp != 0:
+ return False
+ for dig in self._int:
+ if dig not in (0, 1):
+ return False
+ return True
+
+ def _fill_logical(self, context, opa, opb):
+ dif = context.prec - len(opa)
+ if dif > 0:
+ opa = (0,)*dif + opa
+ elif dif < 0:
+ opa = opa[-context.prec:]
+ dif = context.prec - len(opb)
+ if dif > 0:
+ opb = (0,)*dif + opb
+ elif dif < 0:
+ opb = opb[-context.prec:]
+ return opa, opb
+
+ def logical_and(self, other, context=None):
+ """Applies an 'and' operation between self and other's digits."""
+ if context is None:
+ context = getcontext()
+ if not self._islogical() or not other._islogical():
+ return context._raise_error(InvalidOperation)
+
+ # fill to context.prec
+ (opa, opb) = self._fill_logical(context, self._int, other._int)
+
+ # make the operation, and clean starting zeroes
+ result = [a&b for a,b in zip(opa,opb)]
+ for i,d in enumerate(result):
+ if d == 1:
+ break
+ result = tuple(result[i:])
+
+ # if empty, we must have at least a zero
+ if not result:
+ result = (0,)
+ return Decimal((0, result, 0))
+
+ def logical_invert(self, context=None):
+ """Invert all its digits."""
+ if context is None:
+ context = getcontext()
+ return self.logical_xor(Decimal((0,(1,)*context.prec,0)), context)
+
+ def logical_or(self, other, context=None):
+ """Applies an 'or' operation between self and other's digits."""
+ if context is None:
+ context = getcontext()
+ if not self._islogical() or not other._islogical():
+ return context._raise_error(InvalidOperation)
+
+ # fill to context.prec
+ (opa, opb) = self._fill_logical(context, self._int, other._int)
+
+ # make the operation, and clean starting zeroes
+ result = [a|b for a,b in zip(opa,opb)]
+ for i,d in enumerate(result):
+ if d == 1:
+ break
+ result = tuple(result[i:])
+
+ # if empty, we must have at least a zero
+ if not result:
+ result = (0,)
+ return Decimal((0, result, 0))
+
+ def logical_xor(self, other, context=None):
+ """Applies an 'xor' operation between self and other's digits."""
+ if context is None:
+ context = getcontext()
+ if not self._islogical() or not other._islogical():
+ return context._raise_error(InvalidOperation)
+
+ # fill to context.prec
+ (opa, opb) = self._fill_logical(context, self._int, other._int)
+
+ # make the operation, and clean starting zeroes
+ result = [a^b for a,b in zip(opa,opb)]
+ for i,d in enumerate(result):
+ if d == 1:
+ break
+ result = tuple(result[i:])
+
+ # if empty, we must have at least a zero
+ if not result:
+ result = (0,)
+ return Decimal((0, result, 0))
+
+ def max_mag(self, other, context=None):
+ """Compares the values numerically with their sign ignored."""
+ other = _convert_other(other, raiseit=True)
+
+ if context is None:
+ context = getcontext()
+
+ if self._is_special or other._is_special:
+ # If one operand is a quiet NaN and the other is number, then the
+ # number is always returned
+ sn = self._isnan()
+ on = other._isnan()
+ if sn or on:
+ if on == 1 and sn != 2:
+ return self._fix_nan(context)
+ if sn == 1 and on != 2:
+ return other._fix_nan(context)
+ return self._check_nans(other, context)
+
+ c = self.copy_abs().__cmp__(other.copy_abs())
+ if c == 0:
+ c = self.compare_total(other)
+
+ if c == -1:
+ ans = other
+ else:
+ ans = self
+
+ if context._rounding_decision == ALWAYS_ROUND:
+ return ans._fix(context)
+ return ans
+
+ def min_mag(self, other, context=None):
+ """Compares the values numerically with their sign ignored."""
+ other = _convert_other(other, raiseit=True)
+
+ if context is None:
+ context = getcontext()
+
+ if self._is_special or other._is_special:
+ # If one operand is a quiet NaN and the other is number, then the
+ # number is always returned
+ sn = self._isnan()
+ on = other._isnan()
+ if sn or on:
+ if on == 1 and sn != 2:
+ return self._fix_nan(context)
+ if sn == 1 and on != 2:
+ return other._fix_nan(context)
+ return self._check_nans(other, context)
+
+ c = self.copy_abs().__cmp__(other.copy_abs())
+ if c == 0:
+ c = self.compare_total(other)
+
+ if c == -1:
+ ans = self
+ else:
+ ans = other
+
+ if context._rounding_decision == ALWAYS_ROUND:
+ return ans._fix(context)
+ return ans
+
+ def next_minus(self, context=None):
+ """Returns the largest representable number smaller than itself."""
+ if context is None:
+ context = getcontext()
+
+ ans = self._check_nans(context=context)
+ if ans:
+ return ans
+
+ if self._isinfinity() == -1:
+ return negInf
+ if self._isinfinity() == 1:
+ return Decimal((0, (9,)*context.prec, context.Etop()))
+
+ context = context.copy()
+ context._set_rounding(ROUND_FLOOR)
+ context._ignore_all_flags()
+ new_self = self._fix(context)
+ if new_self != self:
+ return new_self
+ return self.__sub__(Decimal((0, (1,), context.Etiny()-1)), context)
+
+ def next_plus(self, context=None):
+ """Returns the smallest representable number larger than itself."""
+ if context is None:
+ context = getcontext()
+
+ ans = self._check_nans(context=context)
+ if ans:
+ return ans
+
+ if self._isinfinity() == 1:
+ return Inf
+ if self._isinfinity() == -1:
+ return Decimal((1, (9,)*context.prec, context.Etop()))
+
+ context = context.copy()
+ context._set_rounding(ROUND_CEILING)
+ context._ignore_all_flags()
+ new_self = self._fix(context)
+ if new_self != self:
+ return new_self
+ return self.__add__(Decimal((0, (1,), context.Etiny()-1)), context)
+
+ def next_toward(self, other, context=None):
+ """Returns the number closest to self, in the direction towards other.
+
+ The result is the closest representable number to self
+ (excluding self) that is in the direction towards other,
+ unless both have the same value. If the two operands are
+ numerically equal, then the result is a copy of self with the
+ sign set to be the same as the sign of other.
+ """
+ other = _convert_other(other, raiseit=True)
+
+ if context is None:
+ context = getcontext()
+
+ ans = self._check_nans(other, context)
+ if ans:
+ return ans
+
+ comparison = self.__cmp__(other)
+ if comparison == 0:
+ return Decimal((other._sign, self._int, self._exp))
+
+ if comparison == -1:
+ ans = self.next_plus(context)
+ else: # comparison == 1
+ ans = self.next_minus(context)
+
+ # decide which flags to raise using value of ans
+ if ans._isinfinity():
+ context._raise_error(Overflow,
+ 'Infinite result from next_toward',
+ ans._sign)
+ context._raise_error(Rounded)
+ context._raise_error(Inexact)
+ elif ans.adjusted() < context.Emin:
+ context._raise_error(Underflow)
+ context._raise_error(Subnormal)
+ context._raise_error(Rounded)
+ context._raise_error(Inexact)
+ # if precision == 1 then we don't raise Clamped for a
+ # result 0E-Etiny.
+ if not ans:
+ context._raise_error(Clamped)
+
+ return ans
+
+ def number_class(self, context=None):
+ """Returns an indication of the class of self.
+
+ The class is one of the following strings:
+ -sNaN
+ -NaN
+ -Infinity
+ -Normal
+ -Subnormal
+ -Zero
+ +Zero
+ +Subnormal
+ +Normal
+ +Infinity
+ """
+ if self.is_snan():
+ return "sNaN"
+ if self.is_qnan():
+ return "NaN"
+ inf = self._isinfinity()
+ if inf == 1:
+ return "+Infinity"
+ if inf == -1:
+ return "-Infinity"
+ if self.is_zero():
+ if self._sign:
+ return "-Zero"
+ else:
+ return "+Zero"
+ if context is None:
+ context = getcontext()
+ if self.is_subnormal(context=context):
+ if self._sign:
+ return "-Subnormal"
+ else:
+ return "+Subnormal"
+ # just a normal, regular, boring number, :)
+ if self._sign:
+ return "-Normal"
+ else:
+ return "+Normal"
+
+ def radix(self):
+ """Just returns 10, as this is Decimal, :)"""
+ return Decimal(10)
+
+ def rotate(self, other, context=None):
+ """Returns a rotated copy of self, value-of-other times."""
+ if context is None:
+ context = getcontext()
+
+ ans = self._check_nans(other, context)
+ if ans:
+ return ans
+
+ if other._exp != 0:
+ return context._raise_error(InvalidOperation)
+ if not (-context.prec <= int(other) <= context.prec):
+ return context._raise_error(InvalidOperation)
+
+ if self._isinfinity():
+ return Decimal(self)
+
+ # get values, pad if necessary
+ torot = int(other)
+ rotdig = self._int
+ topad = context.prec - len(rotdig)
+ if topad:
+ rotdig = ((0,)*topad) + rotdig
+
+ # let's rotate!
+ rotated = rotdig[torot:] + rotdig[:torot]
+
+ # clean starting zeroes
+ for i,d in enumerate(rotated):
+ if d != 0:
+ break
+ rotated = rotated[i:]
+
+ return Decimal((self._sign, rotated, self._exp))
+
+
+ def scaleb (self, other, context=None):
+ """Returns self operand after adding the second value to its exp."""
+ if context is None:
+ context = getcontext()
+
+ ans = self._check_nans(other, context)
+ if ans:
+ return ans
+
+ if other._exp != 0:
+ return context._raise_error(InvalidOperation)
+ liminf = -2 * (context.Emax + context.prec)
+ limsup = 2 * (context.Emax + context.prec)
+ if not (liminf <= int(other) <= limsup):
+ return context._raise_error(InvalidOperation)
+
+ if self._isinfinity():
+ return Decimal(self)
+
+ d = Decimal((self._sign, self._int, self._exp + int(other)))
+ d = d._fix(context)
+ return d
+
+ def shift(self, other, context=None):
+ """Returns a shifted copy of self, value-of-other times."""
+ if context is None:
+ context = getcontext()
+
+ ans = self._check_nans(other, context)
+ if ans:
+ return ans
+
+ if other._exp != 0:
+ return context._raise_error(InvalidOperation)
+ if not (-context.prec <= int(other) <= context.prec):
+ return context._raise_error(InvalidOperation)
+
+ if self._isinfinity():
+ return Decimal(self)
+
+ # get values, pad if necessary
+ torot = int(other)
+ if not torot:
+ return Decimal(self)
+ rotdig = self._int
+ topad = context.prec - len(rotdig)
+ if topad:
+ rotdig = ((0,)*topad) + rotdig
+
+ # let's shift!
+ if torot < 0:
+ rotated = rotdig[:torot]
+ else:
+ rotated = (rotdig + ((0,) * torot))
+ rotated = rotated[-context.prec:]
+
+ # clean starting zeroes
+ if rotated:
+ for i,d in enumerate(rotated):
+ if d != 0:
+ break
+ rotated = rotated[i:]
+ else:
+ rotated = (0,)
+
+ return Decimal((self._sign, rotated, self._exp))
+
+
# Support for pickling, copy, and deepcopy
def __reduce__(self):
return (self.__class__, (str(self),))
@@ -2426,6 +3623,9 @@
def create_decimal(self, num='0'):
"""Creates a new Decimal instance but using self as context."""
d = Decimal(num, context=self)
+ if d._isnan() and len(d._int) > self.prec - self._clamp:
+ return self._raise_error(ConversionSyntax,
+ "diagnostic info too long in NaN")
return d._fix(self)
# Methods
@@ -2460,6 +3660,17 @@
def _apply(self, a):
return str(a._fix(self))
+ def canonical(self, a):
+ """Returns the same Decimal object.
+
+ As we do not have different encodings for the same number, the
+ received object already is in its canonical form.
+
+ >>> ExtendedContext.canonical(Decimal('2.50'))
+ Decimal("2.50")
+ """
+ return a.canonical(context=self)
+
def compare(self, a, b):
"""Compares values numerically.
@@ -2489,6 +3700,110 @@
"""
return a.compare(b, context=self)
+ def compare_signal(self, a, b):
+ """Compares the values of the two operands numerically.
+
+ It's pretty much like compare(), but all NaNs signal, with signaling
+ NaNs taking precedence over quiet NaNs.
+
+ >>> c = ExtendedContext
+ >>> c.compare_signal(Decimal('2.1'), Decimal('3'))
+ Decimal("-1")
+ >>> c.compare_signal(Decimal('2.1'), Decimal('2.1'))
+ Decimal("0")
+ >>> c.flags[InvalidOperation] = 0
+ >>> print(c.flags[InvalidOperation])
+ 0
+ >>> c.compare_signal(Decimal('NaN'), Decimal('2.1'))
+ Decimal("NaN")
+ >>> print(c.flags[InvalidOperation])
+ 1
+ >>> c.flags[InvalidOperation] = 0
+ >>> print(c.flags[InvalidOperation])
+ 0
+ >>> c.compare_signal(Decimal('sNaN'), Decimal('2.1'))
+ Decimal("NaN")
+ >>> print(c.flags[InvalidOperation])
+ 1
+ """
+ return a.compare_signal(b, context=self)
+
+ def compare_total(self, a, b):
+ """Compares two operands using their abstract representation.
+
+ This is not like the standard compare, which use their numerical
+ value. Note that a total ordering is defined for all possible abstract
+ representations.
+
+ >>> ExtendedContext.compare_total(Decimal('12.73'), Decimal('127.9'))
+ Decimal("-1")
+ >>> ExtendedContext.compare_total(Decimal('-127'), Decimal('12'))
+ Decimal("-1")
+ >>> ExtendedContext.compare_total(Decimal('12.30'), Decimal('12.3'))
+ Decimal("-1")
+ >>> ExtendedContext.compare_total(Decimal('12.30'), Decimal('12.30'))
+ Decimal("0")
+ >>> ExtendedContext.compare_total(Decimal('12.3'), Decimal('12.300'))
+ Decimal("1")
+ >>> ExtendedContext.compare_total(Decimal('12.3'), Decimal('NaN'))
+ Decimal("-1")
+ """
+ return a.compare_total(b)
+
+ def compare_total_mag(self, a, b):
+ """Compares two operands using their abstract representation ignoring sign.
+
+ Like compare_total, but with operand's sign ignored and assumed to be 0.
+ """
+ return a.compare_total_mag(b)
+
+ def copy_abs(self, a):
+ """Returns a copy of the operand with the sign set to 0.
+
+ >>> ExtendedContext.copy_abs(Decimal('2.1'))
+ Decimal("2.1")
+ >>> ExtendedContext.copy_abs(Decimal('-100'))
+ Decimal("100")
+ """
+ return a.copy_abs()
+
+ def copy_decimal(self, a):
+ """Returns a copy of the decimal objet.
+
+ >>> ExtendedContext.copy_decimal(Decimal('2.1'))
+ Decimal("2.1")
+ >>> ExtendedContext.copy_decimal(Decimal('-1.00'))
+ Decimal("-1.00")
+ """
+ return Decimal(a)
+
+ def copy_negate(self, a):
+ """Returns a copy of the operand with the sign inverted.
+
+ >>> ExtendedContext.copy_negate(Decimal('101.5'))
+ Decimal("-101.5")
+ >>> ExtendedContext.copy_negate(Decimal('-101.5'))
+ Decimal("101.5")
+ """
+ return a.copy_negate()
+
+ def copy_sign(self, a, b):
+ """Copies the second operand's sign to the first one.
+
+ In detail, it returns a copy of the first operand with the sign
+ equal to the sign of the second operand.
+
+ >>> ExtendedContext.copy_sign(Decimal( '1.50'), Decimal('7.33'))
+ Decimal("1.50")
+ >>> ExtendedContext.copy_sign(Decimal('-1.50'), Decimal('7.33'))
+ Decimal("1.50")
+ >>> ExtendedContext.copy_sign(Decimal( '1.50'), Decimal('-7.33'))
+ Decimal("-1.50")
+ >>> ExtendedContext.copy_sign(Decimal('-1.50'), Decimal('-7.33'))
+ Decimal("-1.50")
+ """
+ return a.copy_sign(b)
+
def divide(self, a, b):
"""Decimal division in a specified context.
@@ -2530,6 +3845,316 @@
def divmod(self, a, b):
return a.__divmod__(b, context=self)
+ def exp(self, a):
+ """Returns e ** a.
+
+ >>> c = ExtendedContext.copy()
+ >>> c.Emin = -999
+ >>> c.Emax = 999
+ >>> c.exp(Decimal('-Infinity'))
+ Decimal("0")
+ >>> c.exp(Decimal('-1'))
+ Decimal("0.367879441")
+ >>> c.exp(Decimal('0'))
+ Decimal("1")
+ >>> c.exp(Decimal('1'))
+ Decimal("2.71828183")
+ >>> c.exp(Decimal('0.693147181'))
+ Decimal("2.00000000")
+ >>> c.exp(Decimal('+Infinity'))
+ Decimal("Infinity")
+ """
+ return a.exp(context=self)
+
+ def fma(self, a, b, c):
+ """Returns a multiplied by b, plus c.
+
+ The first two operands are multiplied together, using multiply,
+ the third operand is then added to the result of that
+ multiplication, using add, all with only one final rounding.
+
+ >>> ExtendedContext.fma(Decimal('3'), Decimal('5'), Decimal('7'))
+ Decimal("22")
+ >>> ExtendedContext.fma(Decimal('3'), Decimal('-5'), Decimal('7'))
+ Decimal("-8")
+ >>> ExtendedContext.fma(Decimal('888565290'), Decimal('1557.96930'), Decimal('-86087.7578'))
+ Decimal("1.38435736E+12")
+ """
+ return a.fma(b, c, context=self)
+
+ def is_canonical(self, a):
+ """Returns 1 if the operand is canonical; otherwise returns 0.
+
+ >>> ExtendedContext.is_canonical(Decimal('2.50'))
+ Decimal("1")
+ """
+ return Dec_p1
+
+ def is_finite(self, a):
+ """Returns 1 if the operand is finite, otherwise returns 0.
+
+ For it to be finite, it must be neither infinite nor a NaN.
+
+ >>> ExtendedContext.is_finite(Decimal('2.50'))
+ Decimal("1")
+ >>> ExtendedContext.is_finite(Decimal('-0.3'))
+ Decimal("1")
+ >>> ExtendedContext.is_finite(Decimal('0'))
+ Decimal("1")
+ >>> ExtendedContext.is_finite(Decimal('Inf'))
+ Decimal("0")
+ >>> ExtendedContext.is_finite(Decimal('NaN'))
+ Decimal("0")
+ """
+ return a.is_finite()
+
+ def is_infinite(self, a):
+ """Returns 1 if the operand is an Infinite, otherwise returns 0.
+
+ >>> ExtendedContext.is_infinite(Decimal('2.50'))
+ Decimal("0")
+ >>> ExtendedContext.is_infinite(Decimal('-Inf'))
+ Decimal("1")
+ >>> ExtendedContext.is_infinite(Decimal('NaN'))
+ Decimal("0")
+ """
+ return a.is_infinite()
+
+ def is_nan(self, a):
+ """Returns 1 if the operand is qNaN or sNaN, otherwise returns 0.
+
+ >>> ExtendedContext.is_nan(Decimal('2.50'))
+ Decimal("0")
+ >>> ExtendedContext.is_nan(Decimal('NaN'))
+ Decimal("1")
+ >>> ExtendedContext.is_nan(Decimal('-sNaN'))
+ Decimal("1")
+ """
+ return a.is_nan()
+
+ def is_normal(self, a):
+ """Returns 1 if the operand is a normal number, otherwise returns 0.
+
+ >>> c = ExtendedContext.copy()
+ >>> c.Emin = -999
+ >>> c.Emax = 999
+ >>> c.is_normal(Decimal('2.50'))
+ Decimal("1")
+ >>> c.is_normal(Decimal('0.1E-999'))
+ Decimal("0")
+ >>> c.is_normal(Decimal('0.00'))
+ Decimal("0")
+ >>> c.is_normal(Decimal('-Inf'))
+ Decimal("0")
+ >>> c.is_normal(Decimal('NaN'))
+ Decimal("0")
+ """
+ return a.is_normal(context=self)
+
+ def is_qnan(self, a):
+ """Returns 1 if the operand is a quiet NaN, otherwise returns 0.
+
+ >>> ExtendedContext.is_qnan(Decimal('2.50'))
+ Decimal("0")
+ >>> ExtendedContext.is_qnan(Decimal('NaN'))
+ Decimal("1")
+ >>> ExtendedContext.is_qnan(Decimal('sNaN'))
+ Decimal("0")
+ """
+ return a.is_qnan()
+
+ def is_signed(self, a):
+ """Returns 1 if the operand is negative, otherwise returns 0.
+
+ >>> ExtendedContext.is_signed(Decimal('2.50'))
+ Decimal("0")
+ >>> ExtendedContext.is_signed(Decimal('-12'))
+ Decimal("1")
+ >>> ExtendedContext.is_signed(Decimal('-0'))
+ Decimal("1")
+ """
+ return a.is_signed()
+
+ def is_snan(self, a):
+ """Returns 1 if the operand is a signaling NaN, otherwise returns 0.
+
+ >>> ExtendedContext.is_snan(Decimal('2.50'))
+ Decimal("0")
+ >>> ExtendedContext.is_snan(Decimal('NaN'))
+ Decimal("0")
+ >>> ExtendedContext.is_snan(Decimal('sNaN'))
+ Decimal("1")
+ """
+ return a.is_snan()
+
+ def is_subnormal(self, a):
+ """Returns 1 if the operand is subnormal, otherwise returns 0.
+
+ >>> c = ExtendedContext.copy()
+ >>> c.Emin = -999
+ >>> c.Emax = 999
+ >>> c.is_subnormal(Decimal('2.50'))
+ Decimal("0")
+ >>> c.is_subnormal(Decimal('0.1E-999'))
+ Decimal("1")
+ >>> c.is_subnormal(Decimal('0.00'))
+ Decimal("0")
+ >>> c.is_subnormal(Decimal('-Inf'))
+ Decimal("0")
+ >>> c.is_subnormal(Decimal('NaN'))
+ Decimal("0")
+ """
+ return a.is_subnormal(context=self)
+
+ def is_zero(self, a):
+ """Returns 1 if the operand is a zero, otherwise returns 0.
+
+ >>> ExtendedContext.is_zero(Decimal('0'))
+ Decimal("1")
+ >>> ExtendedContext.is_zero(Decimal('2.50'))
+ Decimal("0")
+ >>> ExtendedContext.is_zero(Decimal('-0E+2'))
+ Decimal("1")
+ """
+ return a.is_zero()
+
+ def ln(self, a):
+ """Returns the natural (base e) logarithm of the operand.
+
+ >>> c = ExtendedContext.copy()
+ >>> c.Emin = -999
+ >>> c.Emax = 999
+ >>> c.ln(Decimal('0'))
+ Decimal("-Infinity")
+ >>> c.ln(Decimal('1.000'))
+ Decimal("0")
+ >>> c.ln(Decimal('2.71828183'))
+ Decimal("1.00000000")
+ >>> c.ln(Decimal('10'))
+ Decimal("2.30258509")
+ >>> c.ln(Decimal('+Infinity'))
+ Decimal("Infinity")
+ """
+ return a.ln(context=self)
+
+ def log10(self, a):
+ """Returns the base 10 logarithm of the operand.
+
+ >>> c = ExtendedContext.copy()
+ >>> c.Emin = -999
+ >>> c.Emax = 999
+ >>> c.log10(Decimal('0'))
+ Decimal("-Infinity")
+ >>> c.log10(Decimal('0.001'))
+ Decimal("-3")
+ >>> c.log10(Decimal('1.000'))
+ Decimal("0")
+ >>> c.log10(Decimal('2'))
+ Decimal("0.301029996")
+ >>> c.log10(Decimal('10'))
+ Decimal("1")
+ >>> c.log10(Decimal('70'))
+ Decimal("1.84509804")
+ >>> c.log10(Decimal('+Infinity'))
+ Decimal("Infinity")
+ """
+ return a.log10(context=self)
+
+ def logb(self, a):
+ """ Returns the exponent of the magnitude of the operand's MSD.
+
+ The result is the integer which is the exponent of the magnitude
+ of the most significant digit of the operand (as though the
+ operand were truncated to a single digit while maintaining the
+ value of that digit and without limiting the resulting exponent).
+
+ >>> ExtendedContext.logb(Decimal('250'))
+ Decimal("2")
+ >>> ExtendedContext.logb(Decimal('2.50'))
+ Decimal("0")
+ >>> ExtendedContext.logb(Decimal('0.03'))
+ Decimal("-2")
+ >>> ExtendedContext.logb(Decimal('0'))
+ Decimal("-Infinity")
+ """
+ return a.logb(context=self)
+
+ def logical_and(self, a, b):
+ """Applies the logical operation 'and' between each operand's digits.
+
+ The operands must be both logical numbers.
+
+ >>> ExtendedContext.logical_and(Decimal('0'), Decimal('0'))
+ Decimal("0")
+ >>> ExtendedContext.logical_and(Decimal('0'), Decimal('1'))
+ Decimal("0")
+ >>> ExtendedContext.logical_and(Decimal('1'), Decimal('0'))
+ Decimal("0")
+ >>> ExtendedContext.logical_and(Decimal('1'), Decimal('1'))
+ Decimal("1")
+ >>> ExtendedContext.logical_and(Decimal('1100'), Decimal('1010'))
+ Decimal("1000")
+ >>> ExtendedContext.logical_and(Decimal('1111'), Decimal('10'))
+ Decimal("10")
+ """
+ return a.logical_and(b, context=self)
+
+ def logical_invert(self, a):
+ """Invert all the digits in the operand.
+
+ The operand must be a logical number.
+
+ >>> ExtendedContext.logical_invert(Decimal('0'))
+ Decimal("111111111")
+ >>> ExtendedContext.logical_invert(Decimal('1'))
+ Decimal("111111110")
+ >>> ExtendedContext.logical_invert(Decimal('111111111'))
+ Decimal("0")
+ >>> ExtendedContext.logical_invert(Decimal('101010101'))
+ Decimal("10101010")
+ """
+ return a.logical_invert(context=self)
+
+ def logical_or(self, a, b):
+ """Applies the logical operation 'or' between each operand's digits.
+
+ The operands must be both logical numbers.
+
+ >>> ExtendedContext.logical_or(Decimal('0'), Decimal('0'))
+ Decimal("0")
+ >>> ExtendedContext.logical_or(Decimal('0'), Decimal('1'))
+ Decimal("1")
+ >>> ExtendedContext.logical_or(Decimal('1'), Decimal('0'))
+ Decimal("1")
+ >>> ExtendedContext.logical_or(Decimal('1'), Decimal('1'))
+ Decimal("1")
+ >>> ExtendedContext.logical_or(Decimal('1100'), Decimal('1010'))
+ Decimal("1110")
+ >>> ExtendedContext.logical_or(Decimal('1110'), Decimal('10'))
+ Decimal("1110")
+ """
+ return a.logical_or(b, context=self)
+
+ def logical_xor(self, a, b):
+ """Applies the logical operation 'xor' between each operand's digits.
+
+ The operands must be both logical numbers.
+
+ >>> ExtendedContext.logical_xor(Decimal('0'), Decimal('0'))
+ Decimal("0")
+ >>> ExtendedContext.logical_xor(Decimal('0'), Decimal('1'))
+ Decimal("1")
+ >>> ExtendedContext.logical_xor(Decimal('1'), Decimal('0'))
+ Decimal("1")
+ >>> ExtendedContext.logical_xor(Decimal('1'), Decimal('1'))
+ Decimal("0")
+ >>> ExtendedContext.logical_xor(Decimal('1100'), Decimal('1010'))
+ Decimal("110")
+ >>> ExtendedContext.logical_xor(Decimal('1111'), Decimal('10'))
+ Decimal("1101")
+ """
+ return a.logical_xor(b, context=self)
+
def max(self, a,b):
"""max compares two values numerically and returns the maximum.
@@ -2550,6 +4175,10 @@
"""
return a.max(b, context=self)
+ def max_mag(self, a, b):
+ """Compares the values numerically with their sign ignored."""
+ return a.max_mag(b, context=self)
+
def min(self, a,b):
"""min compares two values numerically and returns the minimum.
@@ -2570,6 +4199,10 @@
"""
return a.min(b, context=self)
+ def min_mag(self, a, b):
+ """Compares the values numerically with their sign ignored."""
+ return a.min_mag(b, context=self)
+
def minus(self, a):
"""Minus corresponds to unary prefix minus in Python.
@@ -2605,6 +4238,68 @@
"""
return a.__mul__(b, context=self)
+ def next_minus(self, a):
+ """Returns the largest representable number smaller than a.
+
+ >>> c = ExtendedContext.copy()
+ >>> c.Emin = -999
+ >>> c.Emax = 999
+ >>> ExtendedContext.next_minus(Decimal('1'))
+ Decimal("0.999999999")
+ >>> c.next_minus(Decimal('1E-1007'))
+ Decimal("0E-1007")
+ >>> ExtendedContext.next_minus(Decimal('-1.00000003'))
+ Decimal("-1.00000004")
+ >>> c.next_minus(Decimal('Infinity'))
+ Decimal("9.99999999E+999")
+ """
+ return a.next_minus(context=self)
+
+ def next_plus(self, a):
+ """Returns the smallest representable number larger than a.
+
+ >>> c = ExtendedContext.copy()
+ >>> c.Emin = -999
+ >>> c.Emax = 999
+ >>> ExtendedContext.next_plus(Decimal('1'))
+ Decimal("1.00000001")
+ >>> c.next_plus(Decimal('-1E-1007'))
+ Decimal("-0E-1007")
+ >>> ExtendedContext.next_plus(Decimal('-1.00000003'))
+ Decimal("-1.00000002")
+ >>> c.next_plus(Decimal('-Infinity'))
+ Decimal("-9.99999999E+999")
+ """
+ return a.next_plus(context=self)
+
+ def next_toward(self, a, b):
+ """Returns the number closest to a, in direction towards b.
+
+ The result is the closest representable number from the first
+ operand (but not the first operand) that is in the direction
+ towards the second operand, unless the operands have the same
+ value.
+
+ >>> c = ExtendedContext.copy()
+ >>> c.Emin = -999
+ >>> c.Emax = 999
+ >>> c.next_toward(Decimal('1'), Decimal('2'))
+ Decimal("1.00000001")
+ >>> c.next_toward(Decimal('-1E-1007'), Decimal('1'))
+ Decimal("-0E-1007")
+ >>> c.next_toward(Decimal('-1.00000003'), Decimal('0'))
+ Decimal("-1.00000002")
+ >>> c.next_toward(Decimal('1'), Decimal('0'))
+ Decimal("0.999999999")
+ >>> c.next_toward(Decimal('1E-1007'), Decimal('-100'))
+ Decimal("0E-1007")
+ >>> c.next_toward(Decimal('-1.00000003'), Decimal('-10'))
+ Decimal("-1.00000004")
+ >>> c.next_toward(Decimal('0.00'), Decimal('-0.0000'))
+ Decimal("-0.00")
+ """
+ return a.next_toward(b, context=self)
+
def normalize(self, a):
"""normalize reduces an operand to its simplest form.
@@ -2626,6 +4321,53 @@
"""
return a.normalize(context=self)
+ def number_class(self, a):
+ """Returns an indication of the class of the operand.
+
+ The class is one of the following strings:
+ -sNaN
+ -NaN
+ -Infinity
+ -Normal
+ -Subnormal
+ -Zero
+ +Zero
+ +Subnormal
+ +Normal
+ +Infinity
+
+ >>> c = Context(ExtendedContext)
+ >>> c.Emin = -999
+ >>> c.Emax = 999
+ >>> c.number_class(Decimal('Infinity'))
+ '+Infinity'
+ >>> c.number_class(Decimal('1E-10'))
+ '+Normal'
+ >>> c.number_class(Decimal('2.50'))
+ '+Normal'
+ >>> c.number_class(Decimal('0.1E-999'))
+ '+Subnormal'
+ >>> c.number_class(Decimal('0'))
+ '+Zero'
+ >>> c.number_class(Decimal('-0'))
+ '-Zero'
+ >>> c.number_class(Decimal('-0.1E-999'))
+ '-Subnormal'
+ >>> c.number_class(Decimal('-1E-10'))
+ '-Normal'
+ >>> c.number_class(Decimal('-2.50'))
+ '-Normal'
+ >>> c.number_class(Decimal('-Infinity'))
+ '-Infinity'
+ >>> c.number_class(Decimal('NaN'))
+ 'NaN'
+ >>> c.number_class(Decimal('-NaN'))
+ 'NaN'
+ >>> c.number_class(Decimal('sNaN'))
+ 'sNaN'
+ """
+ return a.number_class(context=self)
+
def plus(self, a):
"""Plus corresponds to unary prefix plus in Python.
@@ -2643,49 +4385,69 @@
def power(self, a, b, modulo=None):
"""Raises a to the power of b, to modulo if given.
- The right-hand operand must be a whole number whose integer part (after
- any exponent has been applied) has no more than 9 digits and whose
- fractional part (if any) is all zeros before any rounding. The operand
- may be positive, negative, or zero; if negative, the absolute value of
- the power is used, and the left-hand operand is inverted (divided into
- 1) before use.
-
- If the increased precision needed for the intermediate calculations
- exceeds the capabilities of the implementation then an Invalid
- operation condition is raised.
-
- If, when raising to a negative power, an underflow occurs during the
- division into 1, the operation is not halted at that point but
- continues.
-
- >>> ExtendedContext.power(Decimal('2'), Decimal('3'))
+ With two arguments, compute a**b. If a is negative then b
+ must be integral. The result will be inexact unless b is
+ integral and the result is finite and can be expressed exactly
+ in 'precision' digits.
+
+ With three arguments, compute (a**b) % modulo. For the
+ three argument form, the following restrictions on the
+ arguments hold:
+
+ - all three arguments must be integral
+ - b must be nonnegative
+ - at least one of a or b must be nonzero
+ - modulo must be nonzero and have at most 'precision' digits
+
+ The result of pow(a, b, modulo) is identical to the result
+ that would be obtained by computing (a**b) % modulo with
+ unbounded precision, but is computed more efficiently. It is
+ always exact.
+
+ >>> c = ExtendedContext.copy()
+ >>> c.Emin = -999
+ >>> c.Emax = 999
+ >>> c.power(Decimal('2'), Decimal('3'))
Decimal("8")
- >>> ExtendedContext.power(Decimal('2'), Decimal('-3'))
+ >>> c.power(Decimal('-2'), Decimal('3'))
+ Decimal("-8")
+ >>> c.power(Decimal('2'), Decimal('-3'))
Decimal("0.125")
- >>> ExtendedContext.power(Decimal('1.7'), Decimal('8'))
+ >>> c.power(Decimal('1.7'), Decimal('8'))
Decimal("69.7575744")
- >>> ExtendedContext.power(Decimal('Infinity'), Decimal('-2'))
+ >>> c.power(Decimal('10'), Decimal('0.301029996'))
+ Decimal("2.00000000")
+ >>> c.power(Decimal('Infinity'), Decimal('-1'))
Decimal("0")
- >>> ExtendedContext.power(Decimal('Infinity'), Decimal('-1'))
- Decimal("0")
- >>> ExtendedContext.power(Decimal('Infinity'), Decimal('0'))
+ >>> c.power(Decimal('Infinity'), Decimal('0'))
Decimal("1")
- >>> ExtendedContext.power(Decimal('Infinity'), Decimal('1'))
- Decimal("Infinity")
- >>> ExtendedContext.power(Decimal('Infinity'), Decimal('2'))
+ >>> c.power(Decimal('Infinity'), Decimal('1'))
Decimal("Infinity")
- >>> ExtendedContext.power(Decimal('-Infinity'), Decimal('-2'))
- Decimal("0")
- >>> ExtendedContext.power(Decimal('-Infinity'), Decimal('-1'))
+ >>> c.power(Decimal('-Infinity'), Decimal('-1'))
Decimal("-0")
- >>> ExtendedContext.power(Decimal('-Infinity'), Decimal('0'))
+ >>> c.power(Decimal('-Infinity'), Decimal('0'))
Decimal("1")
- >>> ExtendedContext.power(Decimal('-Infinity'), Decimal('1'))
+ >>> c.power(Decimal('-Infinity'), Decimal('1'))
Decimal("-Infinity")
- >>> ExtendedContext.power(Decimal('-Infinity'), Decimal('2'))
+ >>> c.power(Decimal('-Infinity'), Decimal('2'))
Decimal("Infinity")
- >>> ExtendedContext.power(Decimal('0'), Decimal('0'))
+ >>> c.power(Decimal('0'), Decimal('0'))
Decimal("NaN")
+
+ >>> c.power(Decimal('3'), Decimal('7'), Decimal('16'))
+ Decimal("11")
+ >>> c.power(Decimal('-3'), Decimal('7'), Decimal('16'))
+ Decimal("-11")
+ >>> c.power(Decimal('-3'), Decimal('8'), Decimal('16'))
+ Decimal("1")
+ >>> c.power(Decimal('3'), Decimal('7'), Decimal('-16'))
+ Decimal("11")
+ >>> c.power(Decimal('23E12345'), Decimal('67E189'), Decimal('123456789'))
+ Decimal("11729830")
+ >>> c.power(Decimal('-0'), Decimal('17'), Decimal('1729'))
+ Decimal("-0")
+ >>> c.power(Decimal('-23'), Decimal('0'), Decimal('65537'))
+ Decimal("1")
"""
return a.__pow__(b, modulo, context=self)
@@ -2740,6 +4502,14 @@
"""
return a.quantize(b, context=self)
+ def radix(self):
+ """Just returns 10, as this is Decimal, :)
+
+ >>> ExtendedContext.radix()
+ Decimal("10")
+ """
+ return Decimal(10)
+
def remainder(self, a, b):
"""Returns the remainder from integer division.
@@ -2794,6 +4564,28 @@
"""
return a.remainder_near(b, context=self)
+ def rotate(self, a, b):
+ """Returns a rotated copy of a, b times.
+
+ The coefficient of the result is a rotated copy of the digits in
+ the coefficient of the first operand. The number of places of
+ rotation is taken from the absolute value of the second operand,
+ with the rotation being to the left if the second operand is
+ positive or to the right otherwise.
+
+ >>> ExtendedContext.rotate(Decimal('34'), Decimal('8'))
+ Decimal("400000003")
+ >>> ExtendedContext.rotate(Decimal('12'), Decimal('9'))
+ Decimal("12")
+ >>> ExtendedContext.rotate(Decimal('123456789'), Decimal('-2'))
+ Decimal("891234567")
+ >>> ExtendedContext.rotate(Decimal('123456789'), Decimal('0'))
+ Decimal("123456789")
+ >>> ExtendedContext.rotate(Decimal('123456789'), Decimal('+2'))
+ Decimal("345678912")
+ """
+ return a.rotate(b, context=self)
+
def same_quantum(self, a, b):
"""Returns True if the two operands have the same exponent.
@@ -2811,6 +4603,41 @@
"""
return a.same_quantum(b)
+ def scaleb (self, a, b):
+ """Returns the first operand after adding the second value its exp.
+
+ >>> ExtendedContext.scaleb(Decimal('7.50'), Decimal('-2'))
+ Decimal("0.0750")
+ >>> ExtendedContext.scaleb(Decimal('7.50'), Decimal('0'))
+ Decimal("7.50")
+ >>> ExtendedContext.scaleb(Decimal('7.50'), Decimal('3'))
+ Decimal("7.50E+3")
+ """
+ return a.scaleb (b, context=self)
+
+ def shift(self, a, b):
+ """Returns a shifted copy of a, b times.
+
+ The coefficient of the result is a shifted copy of the digits
+ in the coefficient of the first operand. The number of places
+ to shift is taken from the absolute value of the second operand,
+ with the shift being to the left if the second operand is
+ positive or to the right otherwise. Digits shifted into the
+ coefficient are zeros.
+
+ >>> ExtendedContext.shift(Decimal('34'), Decimal('8'))
+ Decimal("400000000")
+ >>> ExtendedContext.shift(Decimal('12'), Decimal('9'))
+ Decimal("0")
+ >>> ExtendedContext.shift(Decimal('123456789'), Decimal('-2'))
+ Decimal("1234567")
+ >>> ExtendedContext.shift(Decimal('123456789'), Decimal('0'))
+ Decimal("123456789")
+ >>> ExtendedContext.shift(Decimal('123456789'), Decimal('+2'))
+ Decimal("345678900")
+ """
+ return a.shift(b, context=self)
+
def sqrt(self, a):
"""Square root of a non-negative number to context precision.
@@ -2866,7 +4693,36 @@
"""
return a.__str__(context=self)
- def to_integral(self, a):
+ def to_integral_exact(self, a):
+ """Rounds to an integer.
+
+ When the operand has a negative exponent, the result is the same
+ as using the quantize() operation using the given operand as the
+ left-hand-operand, 1E+0 as the right-hand-operand, and the precision
+ of the operand as the precision setting; Inexact and Rounded flags
+ are allowed in this operation. The rounding mode is taken from the
+ context.
+
+ >>> ExtendedContext.to_integral_exact(Decimal('2.1'))
+ Decimal("2")
+ >>> ExtendedContext.to_integral_exact(Decimal('100'))
+ Decimal("100")
+ >>> ExtendedContext.to_integral_exact(Decimal('100.0'))
+ Decimal("100")
+ >>> ExtendedContext.to_integral_exact(Decimal('101.5'))
+ Decimal("102")
+ >>> ExtendedContext.to_integral_exact(Decimal('-101.5'))
+ Decimal("-102")
+ >>> ExtendedContext.to_integral_exact(Decimal('10E+5'))
+ Decimal("1.0E+6")
+ >>> ExtendedContext.to_integral_exact(Decimal('7.89E+77'))
+ Decimal("7.89E+77")
+ >>> ExtendedContext.to_integral_exact(Decimal('-Inf'))
+ Decimal("-Infinity")
+ """
+ return a.to_integral_exact(context=self)
+
+ def to_integral_value(self, a):
"""Rounds to an integer.
When the operand has a negative exponent, the result is the same
@@ -2875,29 +4731,32 @@
of the operand as the precision setting, except that no flags will
be set. The rounding mode is taken from the context.
- >>> ExtendedContext.to_integral(Decimal('2.1'))
+ >>> ExtendedContext.to_integral_value(Decimal('2.1'))
Decimal("2")
- >>> ExtendedContext.to_integral(Decimal('100'))
+ >>> ExtendedContext.to_integral_value(Decimal('100'))
Decimal("100")
- >>> ExtendedContext.to_integral(Decimal('100.0'))
+ >>> ExtendedContext.to_integral_value(Decimal('100.0'))
Decimal("100")
- >>> ExtendedContext.to_integral(Decimal('101.5'))
+ >>> ExtendedContext.to_integral_value(Decimal('101.5'))
Decimal("102")
- >>> ExtendedContext.to_integral(Decimal('-101.5'))
+ >>> ExtendedContext.to_integral_value(Decimal('-101.5'))
Decimal("-102")
- >>> ExtendedContext.to_integral(Decimal('10E+5'))
+ >>> ExtendedContext.to_integral_value(Decimal('10E+5'))
Decimal("1.0E+6")
- >>> ExtendedContext.to_integral(Decimal('7.89E+77'))
+ >>> ExtendedContext.to_integral_value(Decimal('7.89E+77'))
Decimal("7.89E+77")
- >>> ExtendedContext.to_integral(Decimal('-Inf'))
+ >>> ExtendedContext.to_integral_value(Decimal('-Inf'))
Decimal("-Infinity")
"""
- return a.to_integral(context=self)
+ return a.to_integral_value(context=self)
+
+ # the method name changed, but we provide also the old one, for compatibility
+ to_integral = to_integral_value
class _WorkRep(object):
__slots__ = ('sign','int','exp')
# sign: 0 or 1
- # int: int or long
+ # int: int
# exp: None, int, or string
def __init__(self, value=None):
@@ -2930,66 +4789,338 @@
Done during addition.
"""
- # Yes, the exponent is a long, but the difference between exponents
- # must be an int-- otherwise you'd get a big memory problem.
- numdigits = int(op1.exp - op2.exp)
- if numdigits < 0:
- numdigits = -numdigits
+ if op1.exp < op2.exp:
tmp = op2
other = op1
else:
tmp = op1
other = op2
-
- if shouldround and numdigits > prec + 1:
- # Big difference in exponents - check the adjusted exponents
+ # Let exp = min(tmp.exp - 1, tmp.adjusted() - precision - 1).
+ # Then adding 10**exp to tmp has the same effect (after rounding)
+ # as adding any positive quantity smaller than 10**exp; similarly
+ # for subtraction. So if other is smaller than 10**exp we replace
+ # it with 10**exp. This avoids tmp.exp - other.exp getting too large.
+ if shouldround:
tmp_len = len(str(tmp.int))
other_len = len(str(other.int))
- if numdigits > (other_len + prec + 1 - tmp_len):
- # If the difference in adjusted exps is > prec+1, we know
- # other is insignificant, so might as well put a 1 after the
- # precision (since this is only for addition). Also stops
- # use of massive longs.
-
- extend = prec + 2 - tmp_len
- if extend <= 0:
- extend = 1
- tmp.int *= 10 ** extend
- tmp.exp -= extend
+ exp = tmp.exp + min(-1, tmp_len - prec - 2)
+ if other_len + other.exp - 1 < exp:
other.int = 1
- other.exp = tmp.exp
- return op1, op2
+ other.exp = exp
- tmp.int *= 10 ** numdigits
- tmp.exp -= numdigits
+ tmp.int *= 10 ** (tmp.exp - other.exp)
+ tmp.exp = other.exp
return op1, op2
-def _adjust_coefficients(op1, op2):
- """Adjust op1, op2 so that op2.int * 10 > op1.int >= op2.int.
+##### Integer arithmetic functions used by ln, log10, exp and __pow__ #####
+
+# This function from Tim Peters was taken from here:
+# http://mail.python.org/pipermail/python-list/1999-July/007758.html
+# The correction being in the function definition is for speed, and
+# the whole function is not resolved with math.log because of avoiding
+# the use of floats.
+def _nbits(n, correction = {
+ '0': 4, '1': 3, '2': 2, '3': 2,
+ '4': 1, '5': 1, '6': 1, '7': 1,
+ '8': 0, '9': 0, 'a': 0, 'b': 0,
+ 'c': 0, 'd': 0, 'e': 0, 'f': 0}):
+ """Number of bits in binary representation of the positive integer n,
+ or 0 if n == 0.
+ """
+ if n < 0:
+ raise ValueError("The argument to _nbits should be nonnegative.")
+ hex_n = "%x" % n
+ return 4*len(hex_n) - correction[hex_n[0]]
+
+def _sqrt_nearest(n, a):
+ """Closest integer to the square root of the positive integer n. a is
+ an initial approximation to the square root. Any positive integer
+ will do for a, but the closer a is to the square root of n the
+ faster convergence will be.
+
+ """
+ if n <= 0 or a <= 0:
+ raise ValueError("Both arguments to _sqrt_nearest should be positive.")
+
+ b=0
+ while a != b:
+ b, a = a, a--n//a>>1
+ return a
+
+def _rshift_nearest(x, shift):
+ """Given an integer x and a nonnegative integer shift, return closest
+ integer to x / 2**shift; use round-to-even in case of a tie.
+
+ """
+ b, q = 1 << shift, x >> shift
+ return q + (2*(x & (b-1)) + (q&1) > b)
+
+def _div_nearest(a, b):
+ """Closest integer to a/b, a and b positive integers; rounds to even
+ in the case of a tie.
- Returns the adjusted op1, op2 as well as the change in op1.exp-op2.exp.
+ """
+ q, r = divmod(a, b)
+ return q + (2*r + (q&1) > b)
+
+def _ilog(x, M, L = 8):
+ """Integer approximation to M*log(x/M), with absolute error boundable
+ in terms only of x/M.
+
+ Given positive integers x and M, return an integer approximation to
+ M * log(x/M). For L = 8 and 0.1 <= x/M <= 10 the difference
+ between the approximation and the exact result is at most 22. For
+ L = 8 and 1.0 <= x/M <= 10.0 the difference is at most 15. In
+ both cases these are upper bounds on the error; it will usually be
+ much smaller."""
+
+ # The basic algorithm is the following: let log1p be the function
+ # log1p(x) = log(1+x). Then log(x/M) = log1p((x-M)/M). We use
+ # the reduction
+ #
+ # log1p(y) = 2*log1p(y/(1+sqrt(1+y)))
+ #
+ # repeatedly until the argument to log1p is small (< 2**-L in
+ # absolute value). For small y we can use the Taylor series
+ # expansion
+ #
+ # log1p(y) ~ y - y**2/2 + y**3/3 - ... - (-y)**T/T
+ #
+ # truncating at T such that y**T is small enough. The whole
+ # computation is carried out in a form of fixed-point arithmetic,
+ # with a real number z being represented by an integer
+ # approximation to z*M. To avoid loss of precision, the y below
+ # is actually an integer approximation to 2**R*y*M, where R is the
+ # number of reductions performed so far.
+
+ y = x-M
+ # argument reduction; R = number of reductions performed
+ R = 0
+ while (R <= L and abs(y) << L-R >= M or
+ R > L and abs(y) >> R-L >= M):
+ y = _div_nearest((M*y) << 1,
+ M + _sqrt_nearest(M*(M+_rshift_nearest(y, R)), M))
+ R += 1
+
+ # Taylor series with T terms
+ T = -int(-10*len(str(M))//(3*L))
+ yshift = _rshift_nearest(y, R)
+ w = _div_nearest(M, T)
+ for k in range(T-1, 0, -1):
+ w = _div_nearest(M, k) - _div_nearest(yshift*w, M)
+
+ return _div_nearest(w*y, M)
+
+def _dlog10(c, e, p):
+ """Given integers c, e and p with c > 0, p >= 0, compute an integer
+ approximation to 10**p * log10(c*10**e), with an absolute error of
+ at most 1. Assumes that c*10**e is not exactly 1."""
+
+ # increase precision by 2; compensate for this by dividing
+ # final result by 100
+ p += 2
+
+ # write c*10**e as d*10**f with either:
+ # f >= 0 and 1 <= d <= 10, or
+ # f <= 0 and 0.1 <= d <= 1.
+ # Thus for c*10**e close to 1, f = 0
+ l = len(str(c))
+ f = e+l - (e+l >= 1)
+
+ if p > 0:
+ M = 10**p
+ k = e+p-f
+ if k >= 0:
+ c *= 10**k
+ else:
+ c = _div_nearest(c, 10**-k)
+
+ log_d = _ilog(c, M) # error < 5 + 22 = 27
+ log_10 = _ilog(10*M, M) # error < 15
+ log_d = _div_nearest(log_d*M, log_10)
+ log_tenpower = f*M # exact
+ else:
+ log_d = 0 # error < 2.31
+ log_tenpower = div_nearest(f, 10**-p) # error < 0.5
+
+ return _div_nearest(log_tenpower+log_d, 100)
+
+def _dlog(c, e, p):
+ """Given integers c, e and p with c > 0, compute an integer
+ approximation to 10**p * log(c*10**e), with an absolute error of
+ at most 1. Assumes that c*10**e is not exactly 1."""
+
+ # Increase precision by 2. The precision increase is compensated
+ # for at the end with a division by 100.
+ p += 2
+
+ # rewrite c*10**e as d*10**f with either f >= 0 and 1 <= d <= 10,
+ # or f <= 0 and 0.1 <= d <= 1. Then we can compute 10**p * log(c*10**e)
+ # as 10**p * log(d) + 10**p*f * log(10).
+ l = len(str(c))
+ f = e+l - (e+l >= 1)
+
+ # compute approximation to 10**p*log(d), with error < 27
+ if p > 0:
+ k = e+p-f
+ if k >= 0:
+ c *= 10**k
+ else:
+ c = _div_nearest(c, 10**-k) # error of <= 0.5 in c
+
+ # _ilog magnifies existing error in c by a factor of at most 10
+ log_d = _ilog(c, 10**p) # error < 5 + 22 = 27
+ else:
+ # p <= 0: just approximate the whole thing by 0; error < 2.31
+ log_d = 0
+
+ # compute approximation to 10**p*f*log(10), with error < 17
+ if f:
+ sign_f = [-1, 1][f > 0]
+ if p >= 0:
+ M = 10**p * abs(f)
+ else:
+ M = _div_nearest(abs(f), 10**-p) # M = 10**p*|f|, error <= 0.5
+
+ if M:
+ f_log_ten = sign_f*_ilog(10*M, M) # M*log(10), error <= 1.2 + 15 < 17
+ else:
+ f_log_ten = 0
+ else:
+ f_log_ten = 0
+
+ # error in sum < 17+27 = 44; error after division < 0.44 + 0.5 < 1
+ return _div_nearest(f_log_ten + log_d, 100)
- Used on _WorkRep instances during division.
+def _iexp(x, M, L=8):
+ """Given integers x and M, M > 0, such that x/M is small in absolute
+ value, compute an integer approximation to M*exp(x/M). For 0 <=
+ x/M <= 2.4, the absolute error in the result is bounded by 60 (and
+ is usually much smaller)."""
+
+ # Algorithm: to compute exp(z) for a real number z, first divide z
+ # by a suitable power R of 2 so that |z/2**R| < 2**-L. Then
+ # compute expm1(z/2**R) = exp(z/2**R) - 1 using the usual Taylor
+ # series
+ #
+ # expm1(x) = x + x**2/2! + x**3/3! + ...
+ #
+ # Now use the identity
+ #
+ # expm1(2x) = expm1(x)*(expm1(x)+2)
+ #
+ # R times to compute the sequence expm1(z/2**R),
+ # expm1(z/2**(R-1)), ... , exp(z/2), exp(z).
+
+ # Find R such that x/2**R/M <= 2**-L
+ R = _nbits((x<<L)//M)
+
+ # Taylor series. (2**L)**T > M
+ T = -int(-10*len(str(M))//(3*L))
+ y = _div_nearest(x, T)
+ Mshift = M<<R
+ for i in range(T-1, 0, -1):
+ y = _div_nearest(x*(Mshift + y), Mshift * i)
+
+ # Expansion
+ for k in range(R-1, -1, -1):
+ Mshift = M<<(k+2)
+ y = _div_nearest(y*(y+Mshift), Mshift)
+
+ return M+y
+
+def _dexp(c, e, p):
+ """Compute an approximation to exp(c*10**e), with p decimal places of
+ precision.
+
+ Returns d, f such that:
+
+ 10**(p-1) <= d <= 10**p, and
+ (d-1)*10**f < exp(c*10**e) < (d+1)*10**f
+
+ In other words, d*10**f is an approximation to exp(c*10**e) with p
+ digits of precision, and with an error in d of at most 1. This is
+ almost, but not quite, the same as the error being < 1ulp: when d
+ = 10**(p-1) the error could be up to 10 ulp."""
+
+ # we'll call iexp with M = 10**(p+2), giving p+3 digits of precision
+ p += 2
+
+ # compute log10 with extra precision = adjusted exponent of c*10**e
+ extra = max(0, e + len(str(c)) - 1)
+ q = p + extra
+ log10 = _dlog(10, 0, q) # error <= 1
+
+ # compute quotient c*10**e/(log10/10**q) = c*10**(e+q)/log10,
+ # rounding down
+ shift = e+q
+ if shift >= 0:
+ cshift = c*10**shift
+ else:
+ cshift = c//10**-shift
+ quot, rem = divmod(cshift, log10)
+
+ # reduce remainder back to original precision
+ rem = _div_nearest(rem, 10**extra)
+
+ # error in result of _iexp < 120; error after division < 0.62
+ return _div_nearest(_iexp(rem, 10**p), 1000), quot - p + 3
+
+def _dpower(xc, xe, yc, ye, p):
+ """Given integers xc, xe, yc and ye representing Decimals x = xc*10**xe and
+ y = yc*10**ye, compute x**y. Returns a pair of integers (c, e) such that:
+
+ 10**(p-1) <= c <= 10**p, and
+ (c-1)*10**e < x**y < (c+1)*10**e
+
+ in other words, c*10**e is an approximation to x**y with p digits
+ of precision, and with an error in c of at most 1. (This is
+ almost, but not quite, the same as the error being < 1ulp: when c
+ == 10**(p-1) we can only guarantee error < 10ulp.)
+
+ We assume that: x is positive and not equal to 1, and y is nonzero.
"""
- adjust = 0
- # If op1 is smaller, make it larger
- while op2.int > op1.int:
- op1.int *= 10
- op1.exp -= 1
- adjust += 1
-
- # If op2 is too small, make it larger
- while op1.int >= (10 * op2.int):
- op2.int *= 10
- op2.exp -= 1
- adjust -= 1
- return op1, op2, adjust
+ # Find b such that 10**(b-1) <= |y| <= 10**b
+ b = len(str(abs(yc))) + ye
+
+ # log(x) = lxc*10**(-p-b-1), to p+b+1 places after the decimal point
+ lxc = _dlog(xc, xe, p+b+1)
+
+ # compute product y*log(x) = yc*lxc*10**(-p-b-1+ye) = pc*10**(-p-1)
+ shift = ye-b
+ if shift >= 0:
+ pc = lxc*yc*10**shift
+ else:
+ pc = _div_nearest(lxc*yc, 10**-shift)
+
+ if pc == 0:
+ # we prefer a result that isn't exactly 1; this makes it
+ # easier to compute a correctly rounded result in __pow__
+ if ((len(str(xc)) + xe >= 1) == (yc > 0)): # if x**y > 1:
+ coeff, exp = 10**(p-1)+1, 1-p
+ else:
+ coeff, exp = 10**p-1, -p
+ else:
+ coeff, exp = _dexp(pc, -(p+1), p+1)
+ coeff = _div_nearest(coeff, 10)
+ exp += 1
+
+ return coeff, exp
+
+def _log10_lb(c, correction = {
+ '1': 100, '2': 70, '3': 53, '4': 40, '5': 31,
+ '6': 23, '7': 16, '8': 10, '9': 5}):
+ """Compute a lower bound for 100*log10(c) for a positive integer c."""
+ if c <= 0:
+ raise ValueError("The argument to _log10_lb should be nonnegative.")
+ str_c = str(c)
+ return 100*len(str_c) - correction[str_c[0]]
##### Helper Functions ####################################################
-def _convert_other(other):
+def _convert_other(other, raiseit=False):
"""Convert other to Decimal.
Verifies that it's ok to use in an implicit construction.
@@ -2998,6 +5129,8 @@
return other
if isinstance(other, int):
return Decimal(other)
+ if raiseit:
+ raise TypeError("Unable to convert %s to Decimal" % other)
return NotImplemented
_infinity_map = {
@@ -3085,12 +5218,16 @@
# Reusable defaults
Inf = Decimal('Inf')
negInf = Decimal('-Inf')
+NaN = Decimal('NaN')
+Dec_0 = Decimal(0)
+Dec_p1 = Decimal(1)
+Dec_n1 = Decimal(-1)
+Dec_p2 = Decimal(2)
+Dec_n2 = Decimal(-2)
# Infsign[sign] is infinity w/ that sign
Infsign = (Inf, negInf)
-NaN = Decimal('NaN')
-
##### crud for parsing strings #############################################
import re
Modified: python/branches/py3k-importlib/Lib/distutils/command/build_scripts.py
==============================================================================
--- python/branches/py3k-importlib/Lib/distutils/command/build_scripts.py (original)
+++ python/branches/py3k-importlib/Lib/distutils/command/build_scripts.py Fri Sep 21 03:17:09 2007
@@ -102,7 +102,8 @@
outf.write("#!%s%s\n" %
(os.path.join(
sysconfig.get_config_var("BINDIR"),
- "python" + sysconfig.get_config_var("EXE")),
+ "python" + sysconfig.get_config_var("VERSION")
+ + sysconfig.get_config_var("EXE")),
post_interp))
outf.writelines(f.readlines())
outf.close()
Modified: python/branches/py3k-importlib/Lib/httplib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/httplib.py (original)
+++ python/branches/py3k-importlib/Lib/httplib.py Fri Sep 21 03:17:09 2007
@@ -985,12 +985,12 @@
"Connect to a host on a given (SSL) port."
sock = socket.create_connection((self.host, self.port), self.timeout)
- self.sock = ssl.sslsocket(sock, self.key_file, self.cert_file)
+ self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file)
def FakeSocket (sock, sslobj):
warnings.warn("FakeSocket is deprecated, and won't be in 3.x. " +
- "Use the result of ssl.sslsocket directly instead.",
+ "Use the result of ssl.wrap_socket() directly instead.",
DeprecationWarning, stacklevel=2)
return sslobj
Modified: python/branches/py3k-importlib/Lib/imaplib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/imaplib.py (original)
+++ python/branches/py3k-importlib/Lib/imaplib.py Fri Sep 21 03:17:09 2007
@@ -1147,7 +1147,7 @@
self.port = port
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.connect((host, port))
- self.sslobj = ssl.sslsocket(self.sock, self.keyfile, self.certfile)
+ self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile)
def read(self, size):
@@ -1199,7 +1199,7 @@
def ssl(self):
"""Return SSLObject instance used to communicate with the IMAP4 server.
- ssl = ssl.sslsocket(<instance>.socket)
+ ssl = ssl.wrap_socket(<instance>.socket)
"""
return self.sslobj
Modified: python/branches/py3k-importlib/Lib/platform.py
==============================================================================
--- python/branches/py3k-importlib/Lib/platform.py (original)
+++ python/branches/py3k-importlib/Lib/platform.py Fri Sep 21 03:17:09 2007
@@ -1142,6 +1142,12 @@
machine = ''
if processor == 'unknown':
processor = ''
+
+ # normalize name
+ if system == 'Microsoft' and release == 'Windows':
+ system = 'Windows'
+ release = 'Vista'
+
_uname_cache = system,node,release,version,machine,processor
return _uname_cache
Modified: python/branches/py3k-importlib/Lib/poplib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/poplib.py (original)
+++ python/branches/py3k-importlib/Lib/poplib.py Fri Sep 21 03:17:09 2007
@@ -348,7 +348,7 @@
if not self.sock:
raise socket.error(msg)
self.file = self.sock.makefile('rb')
- self.sslobj = ssl.sslsocket(self.sock, self.keyfile, self.certfile)
+ self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile)
self._debugging = 0
self.welcome = self._getresp()
Modified: python/branches/py3k-importlib/Lib/repr.py
==============================================================================
--- python/branches/py3k-importlib/Lib/repr.py (original)
+++ python/branches/py3k-importlib/Lib/repr.py Fri Sep 21 03:17:09 2007
@@ -1,4 +1,4 @@
-"""Redo the `...` (representation) but with limits on most sizes."""
+"""Redo the builtin repr() (representation) but with limits on most sizes."""
__all__ = ["Repr","repr"]
@@ -57,11 +57,11 @@
return self._repr_iterable(x, level, header, '])', self.maxarray)
def repr_set(self, x, level):
- x = sorted(x)
+ x = _possibly_sorted(x)
return self._repr_iterable(x, level, 'set([', '])', self.maxset)
def repr_frozenset(self, x, level):
- x = sorted(x)
+ x = _possibly_sorted(x)
return self._repr_iterable(x, level, 'frozenset([', '])',
self.maxfrozenset)
@@ -75,7 +75,7 @@
newlevel = level - 1
repr1 = self.repr1
pieces = []
- for key in islice(sorted(x), self.maxdict):
+ for key in islice(_possibly_sorted(x), self.maxdict):
keyrepr = repr1(key, newlevel)
valrepr = repr1(x[key], newlevel)
pieces.append('%s: %s' % (keyrepr, valrepr))
@@ -105,7 +105,7 @@
s = __builtin__.repr(x)
# Bugs in x.__repr__() can cause arbitrary
# exceptions -- then make up something
- except:
+ except Exception:
return '<%s instance at %x>' % (x.__class__.__name__, id(x))
if len(s) > self.maxother:
i = max(0, (self.maxother-3)//2)
@@ -113,5 +113,15 @@
s = s[:i] + '...' + s[len(s)-j:]
return s
+
+def _possibly_sorted(x):
+ # Since not all sequences of items can be sorted and comparison
+ # functions may raise arbitrary exceptions, return an unsorted
+ # sequence in that case.
+ try:
+ return sorted(x)
+ except Exception:
+ return list(x)
+
aRepr = Repr()
repr = aRepr.repr
Modified: python/branches/py3k-importlib/Lib/smtplib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/smtplib.py (original)
+++ python/branches/py3k-importlib/Lib/smtplib.py Fri Sep 21 03:17:09 2007
@@ -588,7 +588,7 @@
if resp == 220:
if not _have_ssl:
raise RuntimeError("No SSL support included in this Python")
- self.sock = ssl.sslsocket(self.sock, keyfile, certfile)
+ self.sock = ssl.wrap_socket(self.sock, keyfile, certfile)
self.file = SSLFakeFile(self.sock)
return (resp, reply)
@@ -721,7 +721,7 @@
def _get_socket(self, host, port, timeout):
if self.debuglevel > 0: print('connect:', (host, port), file=stderr)
self.sock = socket.create_connection((host, port), timeout)
- self.sock = ssl.sslsocket(self.sock, self.keyfile, self.certfile)
+ self.sock = ssl.wrap_socket(self.sock, self.keyfile, self.certfile)
self.file = SSLFakeFile(self.sock)
__all__.append("SMTP_SSL")
Modified: python/branches/py3k-importlib/Lib/socket.py
==============================================================================
--- python/branches/py3k-importlib/Lib/socket.py (original)
+++ python/branches/py3k-importlib/Lib/socket.py Fri Sep 21 03:17:09 2007
@@ -56,13 +56,13 @@
def ssl(sock, keyfile=None, certfile=None):
# we do an internal import here because the ssl
# module imports the socket module
- warnings.warn("socket.ssl() is deprecated. Use ssl.sslsocket() instead.",
+ warnings.warn("socket.ssl() is deprecated. Use ssl.wrap_socket() instead.",
DeprecationWarning, stacklevel=2)
return _realssl.sslwrap_simple(sock, keyfile, certfile)
# we need to import the same constants we used to...
+ from _ssl import SSLError as sslerror
from _ssl import \
- sslerror, \
RAND_add, \
RAND_egd, \
RAND_status, \
Modified: python/branches/py3k-importlib/Lib/ssl.py
==============================================================================
--- python/branches/py3k-importlib/Lib/ssl.py (original)
+++ python/branches/py3k-importlib/Lib/ssl.py Fri Sep 21 03:17:09 2007
@@ -8,11 +8,11 @@
Object types:
- sslsocket -- subtype of socket.socket which does SSL over the socket
+ SSLSocket -- subtype of socket.socket which does SSL over the socket
Exceptions:
- sslerror -- exception raised for I/O errors
+ SSLError -- exception raised for I/O errors
Functions:
@@ -57,12 +57,14 @@
PROTOCOL_TLSv1
"""
-import os, sys
+import os, sys, textwrap
import _ssl # if we can't import it, let the error propagate
-from _ssl import sslerror
+
+from _ssl import SSLError
from _ssl import CERT_NONE, CERT_OPTIONAL, CERT_REQUIRED
from _ssl import PROTOCOL_SSLv2, PROTOCOL_SSLv3, PROTOCOL_SSLv23, PROTOCOL_TLSv1
+from _ssl import RAND_status, RAND_egd, RAND_add
from _ssl import \
SSL_ERROR_ZERO_RETURN, \
SSL_ERROR_WANT_READ, \
@@ -76,9 +78,9 @@
from socket import socket
from socket import getnameinfo as _getnameinfo
+import base64 # for DER-to-PEM translation
-
-class sslsocket (socket):
+class SSLSocket (socket):
"""This class implements a subtype of socket.socket that wraps
the underlying OS socket in an SSL context when necessary, and
@@ -121,14 +123,21 @@
return self._sslobj.write(data)
- def getpeercert(self):
+ def getpeercert(self, binary_form=False):
"""Returns a formatted version of the data in the
certificate provided by the other end of the SSL channel.
Return None if no certificate was provided, {} if a
certificate was provided, but not validated."""
- return self._sslobj.peer_certificate()
+ return self._sslobj.peer_certificate(binary_form)
+
+ def cipher (self):
+
+ if not self._sslobj:
+ return None
+ else:
+ return self._sslobj.cipher()
def send (self, data, flags=0):
if self._sslobj:
@@ -174,21 +183,12 @@
else:
return socket.recv_from(self, addr, buflen, flags)
- def ssl_shutdown(self):
-
- """Shuts down the SSL channel over this socket (if active),
- without closing the socket connection."""
-
- if self._sslobj:
- self._sslobj.shutdown()
- self._sslobj = None
-
def shutdown(self, how):
- self.ssl_shutdown()
+ self._sslobj = None
socket.shutdown(self, how)
def close(self):
- self.ssl_shutdown()
+ self._sslobj = None
socket.close(self)
def connect(self, addr):
@@ -199,7 +199,7 @@
# Here we assume that the socket is client-side, and not
# connected at the time of the call. We connect it, then wrap it.
if self._sslobj:
- raise ValueError("attempt to connect already-connected sslsocket!")
+ raise ValueError("attempt to connect already-connected SSLSocket!")
socket.connect(self, addr)
self._sslobj = _ssl.sslwrap(self._sock, False, self.keyfile, self.certfile,
self.cert_reqs, self.ssl_version,
@@ -212,11 +212,261 @@
SSL channel, and the address of the remote client."""
newsock, addr = socket.accept(self)
- return (sslsocket(newsock, True, self.keyfile, self.certfile,
- self.cert_reqs, self.ssl_version,
- self.ca_certs), addr)
+ return (SSLSocket(newsock, True, self.keyfile, self.certfile,
+ self.cert_reqs, self.ssl_version,
+ self.ca_certs), addr)
+ def makefile(self, mode='r', bufsize=-1):
+
+ """Ouch. Need to make and return a file-like object that
+ works with the SSL connection."""
+
+ if self._sslobj:
+ return SSLFileStream(self._sslobj, mode, bufsize)
+ else:
+ return socket.makefile(self, mode, bufsize)
+
+
+class SSLFileStream:
+
+ """A class to simulate a file stream on top of a socket.
+ Most of this is just lifted from the socket module, and
+ adjusted to work with an SSL stream instead of a socket."""
+
+
+ default_bufsize = 8192
+ name = "<SSL stream>"
+
+ __slots__ = ["mode", "bufsize", "softspace",
+ # "closed" is a property, see below
+ "_sslobj", "_rbufsize", "_wbufsize", "_rbuf", "_wbuf",
+ "_close", "_fileno"]
+
+ def __init__(self, sslobj, mode='rb', bufsize=-1, close=False):
+ self._sslobj = sslobj
+ self.mode = mode # Not actually used in this version
+ if bufsize < 0:
+ bufsize = self.default_bufsize
+ self.bufsize = bufsize
+ self.softspace = False
+ if bufsize == 0:
+ self._rbufsize = 1
+ elif bufsize == 1:
+ self._rbufsize = self.default_bufsize
+ else:
+ self._rbufsize = bufsize
+ self._wbufsize = bufsize
+ self._rbuf = "" # A string
+ self._wbuf = [] # A list of strings
+ self._close = close
+ self._fileno = -1
+
+ def _getclosed(self):
+ return self._sslobj is None
+ closed = property(_getclosed, doc="True if the file is closed")
+
+ def fileno(self):
+ return self._fileno
+
+ def close(self):
+ try:
+ if self._sslobj:
+ self.flush()
+ finally:
+ if self._close and self._sslobj:
+ self._sslobj.close()
+ self._sslobj = None
+
+ def __del__(self):
+ try:
+ self.close()
+ except:
+ # close() may fail if __init__ didn't complete
+ pass
+
+ def flush(self):
+ if self._wbuf:
+ buffer = "".join(self._wbuf)
+ self._wbuf = []
+ count = 0
+ while (count < len(buffer)):
+ written = self._sslobj.write(buffer)
+ count += written
+ buffer = buffer[written:]
+
+ def write(self, data):
+ data = str(data) # XXX Should really reject non-string non-buffers
+ if not data:
+ return
+ self._wbuf.append(data)
+ if (self._wbufsize == 0 or
+ self._wbufsize == 1 and '\n' in data or
+ self._get_wbuf_len() >= self._wbufsize):
+ self.flush()
+
+ def writelines(self, list):
+ # XXX We could do better here for very long lists
+ # XXX Should really reject non-string non-buffers
+ self._wbuf.extend(filter(None, map(str, list)))
+ if (self._wbufsize <= 1 or
+ self._get_wbuf_len() >= self._wbufsize):
+ self.flush()
+
+ def _get_wbuf_len(self):
+ buf_len = 0
+ for x in self._wbuf:
+ buf_len += len(x)
+ return buf_len
+
+ def read(self, size=-1):
+ data = self._rbuf
+ if size < 0:
+ # Read until EOF
+ buffers = []
+ if data:
+ buffers.append(data)
+ self._rbuf = ""
+ if self._rbufsize <= 1:
+ recv_size = self.default_bufsize
+ else:
+ recv_size = self._rbufsize
+ while True:
+ data = self._sslobj.read(recv_size)
+ if not data:
+ break
+ buffers.append(data)
+ return "".join(buffers)
+ else:
+ # Read until size bytes or EOF seen, whichever comes first
+ buf_len = len(data)
+ if buf_len >= size:
+ self._rbuf = data[size:]
+ return data[:size]
+ buffers = []
+ if data:
+ buffers.append(data)
+ self._rbuf = ""
+ while True:
+ left = size - buf_len
+ recv_size = max(self._rbufsize, left)
+ data = self._sslobj.read(recv_size)
+ if not data:
+ break
+ buffers.append(data)
+ n = len(data)
+ if n >= left:
+ self._rbuf = data[left:]
+ buffers[-1] = data[:left]
+ break
+ buf_len += n
+ return "".join(buffers)
+
+ def readline(self, size=-1):
+ data = self._rbuf
+ if size < 0:
+ # Read until \n or EOF, whichever comes first
+ if self._rbufsize <= 1:
+ # Speed up unbuffered case
+ assert data == ""
+ buffers = []
+ while data != "\n":
+ data = self._sslobj.read(1)
+ if not data:
+ break
+ buffers.append(data)
+ return "".join(buffers)
+ nl = data.find('\n')
+ if nl >= 0:
+ nl += 1
+ self._rbuf = data[nl:]
+ return data[:nl]
+ buffers = []
+ if data:
+ buffers.append(data)
+ self._rbuf = ""
+ while True:
+ data = self._sslobj.read(self._rbufsize)
+ if not data:
+ break
+ buffers.append(data)
+ nl = data.find('\n')
+ if nl >= 0:
+ nl += 1
+ self._rbuf = data[nl:]
+ buffers[-1] = data[:nl]
+ break
+ return "".join(buffers)
+ else:
+ # Read until size bytes or \n or EOF seen, whichever comes first
+ nl = data.find('\n', 0, size)
+ if nl >= 0:
+ nl += 1
+ self._rbuf = data[nl:]
+ return data[:nl]
+ buf_len = len(data)
+ if buf_len >= size:
+ self._rbuf = data[size:]
+ return data[:size]
+ buffers = []
+ if data:
+ buffers.append(data)
+ self._rbuf = ""
+ while True:
+ data = self._sslobj.read(self._rbufsize)
+ if not data:
+ break
+ buffers.append(data)
+ left = size - buf_len
+ nl = data.find('\n', 0, left)
+ if nl >= 0:
+ nl += 1
+ self._rbuf = data[nl:]
+ buffers[-1] = data[:nl]
+ break
+ n = len(data)
+ if n >= left:
+ self._rbuf = data[left:]
+ buffers[-1] = data[:left]
+ break
+ buf_len += n
+ return "".join(buffers)
+
+ def readlines(self, sizehint=0):
+ total = 0
+ list = []
+ while True:
+ line = self.readline()
+ if not line:
+ break
+ list.append(line)
+ total += len(line)
+ if sizehint and total >= sizehint:
+ break
+ return list
+
+ # Iterator protocols
+
+ def __iter__(self):
+ return self
+
+ def next(self):
+ line = self.readline()
+ if not line:
+ raise StopIteration
+ return line
+
+
+
+
+def wrap_socket(sock, keyfile=None, certfile=None,
+ server_side=False, cert_reqs=CERT_NONE,
+ ssl_version=PROTOCOL_SSLv23, ca_certs=None):
+
+ return SSLSocket(sock, keyfile=keyfile, certfile=certfile,
+ server_side=server_side, cert_reqs=cert_reqs,
+ ssl_version=ssl_version, ca_certs=ca_certs)
+
# some utility functions
def cert_time_to_seconds(cert_time):
@@ -228,6 +478,71 @@
import time
return time.mktime(time.strptime(cert_time, "%b %d %H:%M:%S %Y GMT"))
+PEM_HEADER = "-----BEGIN CERTIFICATE-----"
+PEM_FOOTER = "-----END CERTIFICATE-----"
+
+def DER_cert_to_PEM_cert(der_cert_bytes):
+
+ """Takes a certificate in binary DER format and returns the
+ PEM version of it as a string."""
+
+ if hasattr(base64, 'standard_b64encode'):
+ # preferred because older API gets line-length wrong
+ f = base64.standard_b64encode(der_cert_bytes)
+ return (PEM_HEADER + '\n' +
+ textwrap.fill(f, 64) +
+ PEM_FOOTER + '\n')
+ else:
+ return (PEM_HEADER + '\n' +
+ base64.encodestring(der_cert_bytes) +
+ PEM_FOOTER + '\n')
+
+def PEM_cert_to_DER_cert(pem_cert_string):
+
+ """Takes a certificate in ASCII PEM format and returns the
+ DER-encoded version of it as a byte sequence"""
+
+ if not pem_cert_string.startswith(PEM_HEADER):
+ raise ValueError("Invalid PEM encoding; must start with %s"
+ % PEM_HEADER)
+ if not pem_cert_string.strip().endswith(PEM_FOOTER):
+ raise ValueError("Invalid PEM encoding; must end with %s"
+ % PEM_FOOTER)
+ d = pem_cert_string.strip()[len(PEM_HEADER):-len(PEM_FOOTER)]
+ return base64.decodestring(d)
+
+def get_server_certificate (addr, ssl_version=PROTOCOL_SSLv3, ca_certs=None):
+
+ """Retrieve the certificate from the server at the specified address,
+ and return it as a PEM-encoded string.
+ If 'ca_certs' is specified, validate the server cert against it.
+ If 'ssl_version' is specified, use it in the connection attempt."""
+
+ host, port = addr
+ if (ca_certs is not None):
+ cert_reqs = CERT_REQUIRED
+ else:
+ cert_reqs = CERT_NONE
+ s = wrap_socket(socket(), ssl_version=ssl_version,
+ cert_reqs=cert_reqs, ca_certs=ca_certs)
+ s.connect(addr)
+ dercert = s.getpeercert(True)
+ s.close()
+ return DER_cert_to_PEM_cert(dercert)
+
+def get_protocol_name (protocol_code):
+ if protocol_code == PROTOCOL_TLSv1:
+ return "TLSv1"
+ elif protocol_code == PROTOCOL_SSLv23:
+ return "SSLv23"
+ elif protocol_code == PROTOCOL_SSLv2:
+ return "SSLv2"
+ elif protocol_code == PROTOCOL_SSLv3:
+ return "SSLv3"
+ else:
+ return "<unknown>"
+
+
# a replacement for the old socket.ssl function
def sslwrap_simple (sock, keyfile=None, certfile=None):
Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/abs.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/abs.decTest (original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/abs.decTest Fri Sep 21 03:17:09 2007
@@ -1,6 +1,6 @@
------------------------------------------------------------------------
-- abs.decTest -- decimal absolute value --
--- Copyright (c) IBM Corporation, 1981, 2004. All rights reserved. --
+-- Copyright (c) IBM Corporation, 1981, 2007. All rights reserved. --
------------------------------------------------------------------------
-- Please see the document "General Decimal Arithmetic Testcases" --
-- at http://www2.hursley.ibm.com/decimal for the description of --
@@ -17,7 +17,7 @@
-- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
-- mfc at uk.ibm.com --
------------------------------------------------------------------------
-version: 2.39
+version: 2.56
-- This set of tests primarily tests the existence of the operator.
-- Additon, subtraction, rounding, and more overflows are tested
@@ -106,9 +106,9 @@
absx215 abs 0.999E-999 -> 1.00E-999 Inexact Rounded Subnormal Underflow
absx216 abs 0.099E-999 -> 1.0E-1000 Inexact Rounded Subnormal Underflow
absx217 abs 0.009E-999 -> 1E-1001 Inexact Rounded Subnormal Underflow
-absx218 abs 0.001E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow
-absx219 abs 0.0009E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow
-absx220 abs 0.0001E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow
+absx218 abs 0.001E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow Clamped
+absx219 abs 0.0009E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow Clamped
+absx220 abs 0.0001E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow Clamped
absx230 abs -1.00E-999 -> 1.00E-999
absx231 abs -0.1E-999 -> 1E-1000 Subnormal
@@ -119,9 +119,9 @@
absx235 abs -0.999E-999 -> 1.00E-999 Inexact Rounded Subnormal Underflow
absx236 abs -0.099E-999 -> 1.0E-1000 Inexact Rounded Subnormal Underflow
absx237 abs -0.009E-999 -> 1E-1001 Inexact Rounded Subnormal Underflow
-absx238 abs -0.001E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow
-absx239 abs -0.0009E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow
-absx240 abs -0.0001E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow
+absx238 abs -0.001E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow Clamped
+absx239 abs -0.0009E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow Clamped
+absx240 abs -0.0001E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow Clamped
-- long operand tests
maxexponent: 999
Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/add.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/add.decTest (original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/add.decTest Fri Sep 21 03:17:09 2007
@@ -1,6 +1,6 @@
-------------------------------------------------------------------------
+------/cancell----------------------------------------------------------
-- add.decTest -- decimal addition --
--- Copyright (c) IBM Corporation, 1981, 2004. All rights reserved. --
+-- Copyright (c) IBM Corporation, 1981, 2007. All rights reserved. --
------------------------------------------------------------------------
-- Please see the document "General Decimal Arithmetic Testcases" --
-- at http://www2.hursley.ibm.com/decimal for the description of --
@@ -17,7 +17,7 @@
-- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
-- mfc at uk.ibm.com --
------------------------------------------------------------------------
-version: 2.39
+version: 2.56
precision: 9
rounding: half_up
@@ -86,6 +86,7 @@
addx049 add '10000e+9' '7000' -> '10000000007000'
addx050 add '10000e+9' '70000' -> '10000000070000'
addx051 add '10000e+9' '700000' -> '10000000700000'
+addx052 add '10000e+9' '7000000' -> '10000007000000'
-- examples from decarith
addx053 add '12' '7.00' -> '19.00'
@@ -216,7 +217,7 @@
addx167 add '1.11' '7E+12' -> '7000000000001.11'
addx168 add '-1' '7E+12' -> '6999999999999'
--- 123456789012345 123456789012345 1 23456789012345
+-- 123456789012345 123456789012345 1 23456789012345
addx170 add '0.444444444444444' '0.555555555555563' -> '1.00000000000001' Inexact Rounded
addx171 add '0.444444444444444' '0.555555555555562' -> '1.00000000000001' Inexact Rounded
addx172 add '0.444444444444444' '0.555555555555561' -> '1.00000000000001' Inexact Rounded
@@ -396,6 +397,7 @@
addx361 add 0E+50 10000E+1 -> 1.0000E+5
addx362 add 10000E+1 0E-50 -> 100000.0 Rounded
addx363 add 10000E+1 10000E-50 -> 100000.0 Rounded Inexact
+addx364 add 9.999999E+92 -9.999999E+92 -> 0E+86
-- a curiosity from JSR 13 testing
rounding: half_down
@@ -568,7 +570,7 @@
rounding: down
addx561 add 1e-398 9.000000000000000E+384 -> 9.000000000000000E+384 Inexact Rounded
addx562 add 0 9.000000000000000E+384 -> 9.000000000000000E+384 Rounded
--- and using decimal64 bounds...
+-- and using decimal64 bounds (see also ddadd.decTest)
precision: 16
maxExponent: +384
minExponent: -383
@@ -576,6 +578,7 @@
addx563 add 1e-388 9.000000000000000E+374 -> 9.000000000000000E+374 Inexact Rounded
addx564 add 0 9.000000000000000E+374 -> 9.000000000000000E+374 Rounded
+
-- some more residue effects with extreme rounding
precision: 9
rounding: half_up
@@ -955,26 +958,26 @@
addx912 add 0.10E-999 0 -> 1.0E-1000 Subnormal
addx913 add 0.100E-999 0 -> 1.0E-1000 Subnormal Rounded
addx914 add 0.01E-999 0 -> 1E-1001 Subnormal
--- next is rounded to Emin
+-- next is rounded to Nmin
addx915 add 0.999E-999 0 -> 1.00E-999 Inexact Rounded Subnormal Underflow
addx916 add 0.099E-999 0 -> 1.0E-1000 Inexact Rounded Subnormal Underflow
addx917 add 0.009E-999 0 -> 1E-1001 Inexact Rounded Subnormal Underflow
-addx918 add 0.001E-999 0 -> 0E-1001 Inexact Rounded Subnormal Underflow
-addx919 add 0.0009E-999 0 -> 0E-1001 Inexact Rounded Subnormal Underflow
-addx920 add 0.0001E-999 0 -> 0E-1001 Inexact Rounded Subnormal Underflow
+addx918 add 0.001E-999 0 -> 0E-1001 Inexact Rounded Subnormal Underflow Clamped
+addx919 add 0.0009E-999 0 -> 0E-1001 Inexact Rounded Subnormal Underflow Clamped
+addx920 add 0.0001E-999 0 -> 0E-1001 Inexact Rounded Subnormal Underflow Clamped
addx930 add -1.00E-999 0 -> -1.00E-999
addx931 add -0.1E-999 0 -> -1E-1000 Subnormal
addx932 add -0.10E-999 0 -> -1.0E-1000 Subnormal
addx933 add -0.100E-999 0 -> -1.0E-1000 Subnormal Rounded
addx934 add -0.01E-999 0 -> -1E-1001 Subnormal
--- next is rounded to Emin
+-- next is rounded to Nmin
addx935 add -0.999E-999 0 -> -1.00E-999 Inexact Rounded Subnormal Underflow
addx936 add -0.099E-999 0 -> -1.0E-1000 Inexact Rounded Subnormal Underflow
addx937 add -0.009E-999 0 -> -1E-1001 Inexact Rounded Subnormal Underflow
-addx938 add -0.001E-999 0 -> -0E-1001 Inexact Rounded Subnormal Underflow
-addx939 add -0.0009E-999 0 -> -0E-1001 Inexact Rounded Subnormal Underflow
-addx940 add -0.0001E-999 0 -> -0E-1001 Inexact Rounded Subnormal Underflow
+addx938 add -0.001E-999 0 -> -0E-1001 Inexact Rounded Subnormal Underflow Clamped
+addx939 add -0.0009E-999 0 -> -0E-1001 Inexact Rounded Subnormal Underflow Clamped
+addx940 add -0.0001E-999 0 -> -0E-1001 Inexact Rounded Subnormal Underflow Clamped
-- some non-zero subnormal adds
addx950 add 1.00E-999 0.1E-999 -> 1.10E-999
@@ -995,12 +998,43 @@
addx964 add 0.100E-999 -0.1E-999 -> 0E-1001 Clamped
addx965 add 0.01E-999 -0.1E-999 -> -9E-1001 Subnormal
addx966 add 0.999E-999 -0.1E-999 -> 9.0E-1000 Inexact Rounded Subnormal Underflow
-addx967 add 0.099E-999 -0.1E-999 -> -0E-1001 Inexact Rounded Subnormal Underflow
+addx967 add 0.099E-999 -0.1E-999 -> -0E-1001 Inexact Rounded Subnormal Underflow Clamped
addx968 add 0.009E-999 -0.1E-999 -> -9E-1001 Inexact Rounded Subnormal Underflow
addx969 add 0.001E-999 -0.1E-999 -> -1.0E-1000 Inexact Rounded Subnormal Underflow
addx970 add 0.0009E-999 -0.1E-999 -> -1.0E-1000 Inexact Rounded Subnormal Underflow
addx971 add 0.0001E-999 -0.1E-999 -> -1.0E-1000 Inexact Rounded Subnormal Underflow
+-- some 'real' numbers
+maxExponent: 384
+minExponent: -383
+precision: 8
+addx566 add 99999061735E-394 0E-394 -> 9.999906E-384 Inexact Rounded Underflow Subnormal
+precision: 7
+addx567 add 99999061735E-394 0E-394 -> 9.99991E-384 Inexact Rounded Underflow Subnormal
+precision: 6
+addx568 add 99999061735E-394 0E-394 -> 9.9999E-384 Inexact Rounded Underflow Subnormal
+
+-- now the case where we can get underflow but the result is normal
+-- [note this can't happen if the operands are also bounded, as we
+-- cannot represent 1E-399, for example]
+precision: 16
+rounding: half_up
+maxExponent: 384
+minExponent: -383
+
+addx571 add 1E-383 0 -> 1E-383
+addx572 add 1E-384 0 -> 1E-384 Subnormal
+addx573 add 1E-383 1E-384 -> 1.1E-383
+addx574 subtract 1E-383 1E-384 -> 9E-384 Subnormal
+
+-- Here we explore the boundary of rounding a subnormal to Nmin
+addx575 subtract 1E-383 1E-398 -> 9.99999999999999E-384 Subnormal
+addx576 subtract 1E-383 1E-398 -> 9.99999999999999E-384 Subnormal
+addx577 subtract 1E-383 1E-399 -> 1.000000000000000E-383 Underflow Inexact Subnormal Rounded
+addx578 subtract 1E-383 1E-400 -> 1.000000000000000E-383 Underflow Inexact Subnormal Rounded
+addx579 subtract 1E-383 1E-401 -> 1.000000000000000E-383 Underflow Inexact Subnormal Rounded
+addx580 subtract 1E-383 1E-402 -> 1.000000000000000E-383 Underflow Inexact Subnormal Rounded
+
-- check overflow edge case
precision: 7
rounding: half_up
@@ -1106,21 +1140,1565 @@
addx1139 add 1000E-101 -1e-200 -> 9.99E-99 Subnormal Inexact Rounded Underflow
addx1140 add 100E-101 -1e-200 -> 9.9E-100 Subnormal Inexact Rounded Underflow
addx1141 add 10E-101 -1e-200 -> 9E-101 Subnormal Inexact Rounded Underflow
-addx1142 add 1E-101 -1e-200 -> 0E-101 Subnormal Inexact Rounded Underflow
-addx1143 add 0E-101 -1e-200 -> -0E-101 Subnormal Inexact Rounded Underflow
-addx1144 add 1E-102 -1e-200 -> 0E-101 Subnormal Inexact Rounded Underflow
+addx1142 add 1E-101 -1e-200 -> 0E-101 Subnormal Inexact Rounded Underflow Clamped
+addx1143 add 0E-101 -1e-200 -> -0E-101 Subnormal Inexact Rounded Underflow Clamped
+addx1144 add 1E-102 -1e-200 -> 0E-101 Subnormal Inexact Rounded Underflow Clamped
addx1151 add 10000E-102 -1e-200 -> 9.99E-99 Subnormal Inexact Rounded Underflow
addx1152 add 1000E-102 -1e-200 -> 9.9E-100 Subnormal Inexact Rounded Underflow
addx1153 add 100E-102 -1e-200 -> 9E-101 Subnormal Inexact Rounded Underflow
-addx1154 add 10E-102 -1e-200 -> 0E-101 Subnormal Inexact Rounded Underflow
-addx1155 add 1E-102 -1e-200 -> 0E-101 Subnormal Inexact Rounded Underflow
-addx1156 add 0E-102 -1e-200 -> -0E-101 Subnormal Inexact Rounded Underflow
-addx1157 add 1E-103 -1e-200 -> 0E-101 Subnormal Inexact Rounded Underflow
+addx1154 add 10E-102 -1e-200 -> 0E-101 Subnormal Inexact Rounded Underflow Clamped
+addx1155 add 1E-102 -1e-200 -> 0E-101 Subnormal Inexact Rounded Underflow Clamped
+addx1156 add 0E-102 -1e-200 -> -0E-101 Subnormal Inexact Rounded Underflow Clamped
+addx1157 add 1E-103 -1e-200 -> 0E-101 Subnormal Inexact Rounded Underflow Clamped
+
+addx1160 add 100E-105 -1e-101 -> -0E-101 Subnormal Inexact Rounded Underflow Clamped
+addx1161 add 100E-105 -1e-201 -> 0E-101 Subnormal Inexact Rounded Underflow Clamped
+
+-- tests based on Gunnar Degnbol's edge case
+precision: 15
+rounding: half_up
+maxExponent: 384
+minexponent: -383
+
+addx1200 add 1E15 -0.5 -> 1.00000000000000E+15 Inexact Rounded
+addx1201 add 1E15 -0.50 -> 1.00000000000000E+15 Inexact Rounded
+addx1210 add 1E15 -0.51 -> 999999999999999 Inexact Rounded
+addx1211 add 1E15 -0.501 -> 999999999999999 Inexact Rounded
+addx1212 add 1E15 -0.5001 -> 999999999999999 Inexact Rounded
+addx1213 add 1E15 -0.50001 -> 999999999999999 Inexact Rounded
+addx1214 add 1E15 -0.500001 -> 999999999999999 Inexact Rounded
+addx1215 add 1E15 -0.5000001 -> 999999999999999 Inexact Rounded
+addx1216 add 1E15 -0.50000001 -> 999999999999999 Inexact Rounded
+addx1217 add 1E15 -0.500000001 -> 999999999999999 Inexact Rounded
+addx1218 add 1E15 -0.5000000001 -> 999999999999999 Inexact Rounded
+addx1219 add 1E15 -0.50000000001 -> 999999999999999 Inexact Rounded
+addx1220 add 1E15 -0.500000000001 -> 999999999999999 Inexact Rounded
+addx1221 add 1E15 -0.5000000000001 -> 999999999999999 Inexact Rounded
+addx1222 add 1E15 -0.50000000000001 -> 999999999999999 Inexact Rounded
+addx1223 add 1E15 -0.500000000000001 -> 999999999999999 Inexact Rounded
+addx1224 add 1E15 -0.5000000000000001 -> 999999999999999 Inexact Rounded
+addx1225 add 1E15 -0.5000000000000000 -> 1.00000000000000E+15 Inexact Rounded
+addx1230 add 1E15 -5000000.000000001 -> 999999995000000 Inexact Rounded
+
+precision: 16
+
+addx1300 add 1E16 -0.5 -> 1.000000000000000E+16 Inexact Rounded
+addx1310 add 1E16 -0.51 -> 9999999999999999 Inexact Rounded
+addx1311 add 1E16 -0.501 -> 9999999999999999 Inexact Rounded
+addx1312 add 1E16 -0.5001 -> 9999999999999999 Inexact Rounded
+addx1313 add 1E16 -0.50001 -> 9999999999999999 Inexact Rounded
+addx1314 add 1E16 -0.500001 -> 9999999999999999 Inexact Rounded
+addx1315 add 1E16 -0.5000001 -> 9999999999999999 Inexact Rounded
+addx1316 add 1E16 -0.50000001 -> 9999999999999999 Inexact Rounded
+addx1317 add 1E16 -0.500000001 -> 9999999999999999 Inexact Rounded
+addx1318 add 1E16 -0.5000000001 -> 9999999999999999 Inexact Rounded
+addx1319 add 1E16 -0.50000000001 -> 9999999999999999 Inexact Rounded
+addx1320 add 1E16 -0.500000000001 -> 9999999999999999 Inexact Rounded
+addx1321 add 1E16 -0.5000000000001 -> 9999999999999999 Inexact Rounded
+addx1322 add 1E16 -0.50000000000001 -> 9999999999999999 Inexact Rounded
+addx1323 add 1E16 -0.500000000000001 -> 9999999999999999 Inexact Rounded
+addx1324 add 1E16 -0.5000000000000001 -> 9999999999999999 Inexact Rounded
+addx1325 add 1E16 -0.5000000000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx1326 add 1E16 -0.500000000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx1327 add 1E16 -0.50000000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx1328 add 1E16 -0.5000000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx1329 add 1E16 -0.500000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx1330 add 1E16 -0.50000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx1331 add 1E16 -0.5000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx1332 add 1E16 -0.500000000 -> 1.000000000000000E+16 Inexact Rounded
+addx1333 add 1E16 -0.50000000 -> 1.000000000000000E+16 Inexact Rounded
+addx1334 add 1E16 -0.5000000 -> 1.000000000000000E+16 Inexact Rounded
+addx1335 add 1E16 -0.500000 -> 1.000000000000000E+16 Inexact Rounded
+addx1336 add 1E16 -0.50000 -> 1.000000000000000E+16 Inexact Rounded
+addx1337 add 1E16 -0.5000 -> 1.000000000000000E+16 Inexact Rounded
+addx1338 add 1E16 -0.500 -> 1.000000000000000E+16 Inexact Rounded
+addx1339 add 1E16 -0.50 -> 1.000000000000000E+16 Inexact Rounded
+
+addx1340 add 1E16 -5000000.000010001 -> 9999999995000000 Inexact Rounded
+addx1341 add 1E16 -5000000.000000001 -> 9999999995000000 Inexact Rounded
+
+addx1349 add 9999999999999999 0.4 -> 9999999999999999 Inexact Rounded
+addx1350 add 9999999999999999 0.49 -> 9999999999999999 Inexact Rounded
+addx1351 add 9999999999999999 0.499 -> 9999999999999999 Inexact Rounded
+addx1352 add 9999999999999999 0.4999 -> 9999999999999999 Inexact Rounded
+addx1353 add 9999999999999999 0.49999 -> 9999999999999999 Inexact Rounded
+addx1354 add 9999999999999999 0.499999 -> 9999999999999999 Inexact Rounded
+addx1355 add 9999999999999999 0.4999999 -> 9999999999999999 Inexact Rounded
+addx1356 add 9999999999999999 0.49999999 -> 9999999999999999 Inexact Rounded
+addx1357 add 9999999999999999 0.499999999 -> 9999999999999999 Inexact Rounded
+addx1358 add 9999999999999999 0.4999999999 -> 9999999999999999 Inexact Rounded
+addx1359 add 9999999999999999 0.49999999999 -> 9999999999999999 Inexact Rounded
+addx1360 add 9999999999999999 0.499999999999 -> 9999999999999999 Inexact Rounded
+addx1361 add 9999999999999999 0.4999999999999 -> 9999999999999999 Inexact Rounded
+addx1362 add 9999999999999999 0.49999999999999 -> 9999999999999999 Inexact Rounded
+addx1363 add 9999999999999999 0.499999999999999 -> 9999999999999999 Inexact Rounded
+addx1364 add 9999999999999999 0.4999999999999999 -> 9999999999999999 Inexact Rounded
+addx1365 add 9999999999999999 0.5000000000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx1367 add 9999999999999999 0.500000000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx1368 add 9999999999999999 0.50000000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx1369 add 9999999999999999 0.5000000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx1370 add 9999999999999999 0.500000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx1371 add 9999999999999999 0.50000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx1372 add 9999999999999999 0.5000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx1373 add 9999999999999999 0.500000000 -> 1.000000000000000E+16 Inexact Rounded
+addx1374 add 9999999999999999 0.50000000 -> 1.000000000000000E+16 Inexact Rounded
+addx1375 add 9999999999999999 0.5000000 -> 1.000000000000000E+16 Inexact Rounded
+addx1376 add 9999999999999999 0.500000 -> 1.000000000000000E+16 Inexact Rounded
+addx1377 add 9999999999999999 0.50000 -> 1.000000000000000E+16 Inexact Rounded
+addx1378 add 9999999999999999 0.5000 -> 1.000000000000000E+16 Inexact Rounded
+addx1379 add 9999999999999999 0.500 -> 1.000000000000000E+16 Inexact Rounded
+addx1380 add 9999999999999999 0.50 -> 1.000000000000000E+16 Inexact Rounded
+addx1381 add 9999999999999999 0.5 -> 1.000000000000000E+16 Inexact Rounded
+addx1382 add 9999999999999999 0.5000000000000001 -> 1.000000000000000E+16 Inexact Rounded
+addx1383 add 9999999999999999 0.500000000000001 -> 1.000000000000000E+16 Inexact Rounded
+addx1384 add 9999999999999999 0.50000000000001 -> 1.000000000000000E+16 Inexact Rounded
+addx1385 add 9999999999999999 0.5000000000001 -> 1.000000000000000E+16 Inexact Rounded
+addx1386 add 9999999999999999 0.500000000001 -> 1.000000000000000E+16 Inexact Rounded
+addx1387 add 9999999999999999 0.50000000001 -> 1.000000000000000E+16 Inexact Rounded
+addx1388 add 9999999999999999 0.5000000001 -> 1.000000000000000E+16 Inexact Rounded
+addx1389 add 9999999999999999 0.500000001 -> 1.000000000000000E+16 Inexact Rounded
+addx1390 add 9999999999999999 0.50000001 -> 1.000000000000000E+16 Inexact Rounded
+addx1391 add 9999999999999999 0.5000001 -> 1.000000000000000E+16 Inexact Rounded
+addx1392 add 9999999999999999 0.500001 -> 1.000000000000000E+16 Inexact Rounded
+addx1393 add 9999999999999999 0.50001 -> 1.000000000000000E+16 Inexact Rounded
+addx1394 add 9999999999999999 0.5001 -> 1.000000000000000E+16 Inexact Rounded
+addx1395 add 9999999999999999 0.501 -> 1.000000000000000E+16 Inexact Rounded
+addx1396 add 9999999999999999 0.51 -> 1.000000000000000E+16 Inexact Rounded
+
+-- More GD edge cases, where difference between the unadjusted
+-- exponents is larger than the maximum precision and one side is 0
+precision: 15
+rounding: half_up
+maxExponent: 384
+minexponent: -383
+
+addx1400 add 0 1.23456789012345 -> 1.23456789012345
+addx1401 add 0 1.23456789012345E-1 -> 0.123456789012345
+addx1402 add 0 1.23456789012345E-2 -> 0.0123456789012345
+addx1403 add 0 1.23456789012345E-3 -> 0.00123456789012345
+addx1404 add 0 1.23456789012345E-4 -> 0.000123456789012345
+addx1405 add 0 1.23456789012345E-5 -> 0.0000123456789012345
+addx1406 add 0 1.23456789012345E-6 -> 0.00000123456789012345
+addx1407 add 0 1.23456789012345E-7 -> 1.23456789012345E-7
+addx1408 add 0 1.23456789012345E-8 -> 1.23456789012345E-8
+addx1409 add 0 1.23456789012345E-9 -> 1.23456789012345E-9
+addx1410 add 0 1.23456789012345E-10 -> 1.23456789012345E-10
+addx1411 add 0 1.23456789012345E-11 -> 1.23456789012345E-11
+addx1412 add 0 1.23456789012345E-12 -> 1.23456789012345E-12
+addx1413 add 0 1.23456789012345E-13 -> 1.23456789012345E-13
+addx1414 add 0 1.23456789012345E-14 -> 1.23456789012345E-14
+addx1415 add 0 1.23456789012345E-15 -> 1.23456789012345E-15
+addx1416 add 0 1.23456789012345E-16 -> 1.23456789012345E-16
+addx1417 add 0 1.23456789012345E-17 -> 1.23456789012345E-17
+addx1418 add 0 1.23456789012345E-18 -> 1.23456789012345E-18
+addx1419 add 0 1.23456789012345E-19 -> 1.23456789012345E-19
+
+-- same, precision 16..
+precision: 16
+addx1420 add 0 1.123456789012345 -> 1.123456789012345
+addx1421 add 0 1.123456789012345E-1 -> 0.1123456789012345
+addx1422 add 0 1.123456789012345E-2 -> 0.01123456789012345
+addx1423 add 0 1.123456789012345E-3 -> 0.001123456789012345
+addx1424 add 0 1.123456789012345E-4 -> 0.0001123456789012345
+addx1425 add 0 1.123456789012345E-5 -> 0.00001123456789012345
+addx1426 add 0 1.123456789012345E-6 -> 0.000001123456789012345
+addx1427 add 0 1.123456789012345E-7 -> 1.123456789012345E-7
+addx1428 add 0 1.123456789012345E-8 -> 1.123456789012345E-8
+addx1429 add 0 1.123456789012345E-9 -> 1.123456789012345E-9
+addx1430 add 0 1.123456789012345E-10 -> 1.123456789012345E-10
+addx1431 add 0 1.123456789012345E-11 -> 1.123456789012345E-11
+addx1432 add 0 1.123456789012345E-12 -> 1.123456789012345E-12
+addx1433 add 0 1.123456789012345E-13 -> 1.123456789012345E-13
+addx1434 add 0 1.123456789012345E-14 -> 1.123456789012345E-14
+addx1435 add 0 1.123456789012345E-15 -> 1.123456789012345E-15
+addx1436 add 0 1.123456789012345E-16 -> 1.123456789012345E-16
+addx1437 add 0 1.123456789012345E-17 -> 1.123456789012345E-17
+addx1438 add 0 1.123456789012345E-18 -> 1.123456789012345E-18
+addx1439 add 0 1.123456789012345E-19 -> 1.123456789012345E-19
+
+-- same, reversed 0
+addx1440 add 1.123456789012345 0 -> 1.123456789012345
+addx1441 add 1.123456789012345E-1 0 -> 0.1123456789012345
+addx1442 add 1.123456789012345E-2 0 -> 0.01123456789012345
+addx1443 add 1.123456789012345E-3 0 -> 0.001123456789012345
+addx1444 add 1.123456789012345E-4 0 -> 0.0001123456789012345
+addx1445 add 1.123456789012345E-5 0 -> 0.00001123456789012345
+addx1446 add 1.123456789012345E-6 0 -> 0.000001123456789012345
+addx1447 add 1.123456789012345E-7 0 -> 1.123456789012345E-7
+addx1448 add 1.123456789012345E-8 0 -> 1.123456789012345E-8
+addx1449 add 1.123456789012345E-9 0 -> 1.123456789012345E-9
+addx1450 add 1.123456789012345E-10 0 -> 1.123456789012345E-10
+addx1451 add 1.123456789012345E-11 0 -> 1.123456789012345E-11
+addx1452 add 1.123456789012345E-12 0 -> 1.123456789012345E-12
+addx1453 add 1.123456789012345E-13 0 -> 1.123456789012345E-13
+addx1454 add 1.123456789012345E-14 0 -> 1.123456789012345E-14
+addx1455 add 1.123456789012345E-15 0 -> 1.123456789012345E-15
+addx1456 add 1.123456789012345E-16 0 -> 1.123456789012345E-16
+addx1457 add 1.123456789012345E-17 0 -> 1.123456789012345E-17
+addx1458 add 1.123456789012345E-18 0 -> 1.123456789012345E-18
+addx1459 add 1.123456789012345E-19 0 -> 1.123456789012345E-19
+
+-- same, Es on the 0
+addx1460 add 1.123456789012345 0E-0 -> 1.123456789012345
+addx1461 add 1.123456789012345 0E-1 -> 1.123456789012345
+addx1462 add 1.123456789012345 0E-2 -> 1.123456789012345
+addx1463 add 1.123456789012345 0E-3 -> 1.123456789012345
+addx1464 add 1.123456789012345 0E-4 -> 1.123456789012345
+addx1465 add 1.123456789012345 0E-5 -> 1.123456789012345
+addx1466 add 1.123456789012345 0E-6 -> 1.123456789012345
+addx1467 add 1.123456789012345 0E-7 -> 1.123456789012345
+addx1468 add 1.123456789012345 0E-8 -> 1.123456789012345
+addx1469 add 1.123456789012345 0E-9 -> 1.123456789012345
+addx1470 add 1.123456789012345 0E-10 -> 1.123456789012345
+addx1471 add 1.123456789012345 0E-11 -> 1.123456789012345
+addx1472 add 1.123456789012345 0E-12 -> 1.123456789012345
+addx1473 add 1.123456789012345 0E-13 -> 1.123456789012345
+addx1474 add 1.123456789012345 0E-14 -> 1.123456789012345
+addx1475 add 1.123456789012345 0E-15 -> 1.123456789012345
+-- next four flag Rounded because the 0 extends the result
+addx1476 add 1.123456789012345 0E-16 -> 1.123456789012345 Rounded
+addx1477 add 1.123456789012345 0E-17 -> 1.123456789012345 Rounded
+addx1478 add 1.123456789012345 0E-18 -> 1.123456789012345 Rounded
+addx1479 add 1.123456789012345 0E-19 -> 1.123456789012345 Rounded
+
+-- sum of two opposite-sign operands is exactly 0 and floor => -0
+precision: 16
+maxExponent: 384
+minexponent: -383
+
+rounding: half_up
+-- exact zeros from zeros
+addx1500 add 0 0E-19 -> 0E-19
+addx1501 add -0 0E-19 -> 0E-19
+addx1502 add 0 -0E-19 -> 0E-19
+addx1503 add -0 -0E-19 -> -0E-19
+addx1504 add 0E-400 0E-19 -> 0E-398 Clamped
+addx1505 add -0E-400 0E-19 -> 0E-398 Clamped
+addx1506 add 0E-400 -0E-19 -> 0E-398 Clamped
+addx1507 add -0E-400 -0E-19 -> -0E-398 Clamped
+-- inexact zeros
+addx1511 add 1E-401 1E-400 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx1512 add -1E-401 1E-400 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx1513 add 1E-401 -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx1514 add -1E-401 -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+-- some exact zeros from non-zeros
+addx1515 add 1E-401 1E-401 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx1516 add -1E-401 1E-401 -> 0E-398 Clamped
+addx1517 add 1E-401 -1E-401 -> 0E-398 Clamped
+addx1518 add -1E-401 -1E-401 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+
+rounding: half_down
+-- exact zeros from zeros
+addx1520 add 0 0E-19 -> 0E-19
+addx1521 add -0 0E-19 -> 0E-19
+addx1522 add 0 -0E-19 -> 0E-19
+addx1523 add -0 -0E-19 -> -0E-19
+addx1524 add 0E-400 0E-19 -> 0E-398 Clamped
+addx1525 add -0E-400 0E-19 -> 0E-398 Clamped
+addx1526 add 0E-400 -0E-19 -> 0E-398 Clamped
+addx1527 add -0E-400 -0E-19 -> -0E-398 Clamped
+-- inexact zeros
+addx1531 add 1E-401 1E-400 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx1532 add -1E-401 1E-400 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx1533 add 1E-401 -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx1534 add -1E-401 -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+-- some exact zeros from non-zeros
+addx1535 add 1E-401 1E-401 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx1536 add -1E-401 1E-401 -> 0E-398 Clamped
+addx1537 add 1E-401 -1E-401 -> 0E-398 Clamped
+addx1538 add -1E-401 -1E-401 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+
+rounding: half_even
+-- exact zeros from zeros
+addx1540 add 0 0E-19 -> 0E-19
+addx1541 add -0 0E-19 -> 0E-19
+addx1542 add 0 -0E-19 -> 0E-19
+addx1543 add -0 -0E-19 -> -0E-19
+addx1544 add 0E-400 0E-19 -> 0E-398 Clamped
+addx1545 add -0E-400 0E-19 -> 0E-398 Clamped
+addx1546 add 0E-400 -0E-19 -> 0E-398 Clamped
+addx1547 add -0E-400 -0E-19 -> -0E-398 Clamped
+-- inexact zeros
+addx1551 add 1E-401 1E-400 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx1552 add -1E-401 1E-400 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx1553 add 1E-401 -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx1554 add -1E-401 -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+-- some exact zeros from non-zeros
+addx1555 add 1E-401 1E-401 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx1556 add -1E-401 1E-401 -> 0E-398 Clamped
+addx1557 add 1E-401 -1E-401 -> 0E-398 Clamped
+addx1558 add -1E-401 -1E-401 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+
+rounding: up
+-- exact zeros from zeros
+addx1560 add 0 0E-19 -> 0E-19
+addx1561 add -0 0E-19 -> 0E-19
+addx1562 add 0 -0E-19 -> 0E-19
+addx1563 add -0 -0E-19 -> -0E-19
+addx1564 add 0E-400 0E-19 -> 0E-398 Clamped
+addx1565 add -0E-400 0E-19 -> 0E-398 Clamped
+addx1566 add 0E-400 -0E-19 -> 0E-398 Clamped
+addx1567 add -0E-400 -0E-19 -> -0E-398 Clamped
+-- inexact zeros
+addx1571 add 1E-401 1E-400 -> 1E-398 Subnormal Inexact Rounded Underflow
+addx1572 add -1E-401 1E-400 -> 1E-398 Subnormal Inexact Rounded Underflow
+addx1573 add 1E-401 -1E-400 -> -1E-398 Subnormal Inexact Rounded Underflow
+addx1574 add -1E-401 -1E-400 -> -1E-398 Subnormal Inexact Rounded Underflow
+-- some exact zeros from non-zeros
+addx1575 add 1E-401 1E-401 -> 1E-398 Subnormal Inexact Rounded Underflow
+addx1576 add -1E-401 1E-401 -> 0E-398 Clamped
+addx1577 add 1E-401 -1E-401 -> 0E-398 Clamped
+addx1578 add -1E-401 -1E-401 -> -1E-398 Subnormal Inexact Rounded Underflow
+
+rounding: down
+-- exact zeros from zeros
+addx1580 add 0 0E-19 -> 0E-19
+addx1581 add -0 0E-19 -> 0E-19
+addx1582 add 0 -0E-19 -> 0E-19
+addx1583 add -0 -0E-19 -> -0E-19
+addx1584 add 0E-400 0E-19 -> 0E-398 Clamped
+addx1585 add -0E-400 0E-19 -> 0E-398 Clamped
+addx1586 add 0E-400 -0E-19 -> 0E-398 Clamped
+addx1587 add -0E-400 -0E-19 -> -0E-398 Clamped
+-- inexact zeros
+addx1591 add 1E-401 1E-400 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx1592 add -1E-401 1E-400 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx1593 add 1E-401 -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx1594 add -1E-401 -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+-- some exact zeros from non-zeros
+addx1595 add 1E-401 1E-401 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx1596 add -1E-401 1E-401 -> 0E-398 Clamped
+addx1597 add 1E-401 -1E-401 -> 0E-398 Clamped
+addx1598 add -1E-401 -1E-401 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+
+rounding: ceiling
+-- exact zeros from zeros
+addx1600 add 0 0E-19 -> 0E-19
+addx1601 add -0 0E-19 -> 0E-19
+addx1602 add 0 -0E-19 -> 0E-19
+addx1603 add -0 -0E-19 -> -0E-19
+addx1604 add 0E-400 0E-19 -> 0E-398 Clamped
+addx1605 add -0E-400 0E-19 -> 0E-398 Clamped
+addx1606 add 0E-400 -0E-19 -> 0E-398 Clamped
+addx1607 add -0E-400 -0E-19 -> -0E-398 Clamped
+-- inexact zeros
+addx1611 add 1E-401 1E-400 -> 1E-398 Subnormal Inexact Rounded Underflow
+addx1612 add -1E-401 1E-400 -> 1E-398 Subnormal Inexact Rounded Underflow
+addx1613 add 1E-401 -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx1614 add -1E-401 -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+-- some exact zeros from non-zeros
+addx1615 add 1E-401 1E-401 -> 1E-398 Subnormal Inexact Rounded Underflow
+addx1616 add -1E-401 1E-401 -> 0E-398 Clamped
+addx1617 add 1E-401 -1E-401 -> 0E-398 Clamped
+addx1618 add -1E-401 -1E-401 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+
+-- and the extra-special ugly case; unusual minuses marked by -- *
+rounding: floor
+-- exact zeros from zeros
+addx1620 add 0 0E-19 -> 0E-19
+addx1621 add -0 0E-19 -> -0E-19 -- *
+addx1622 add 0 -0E-19 -> -0E-19 -- *
+addx1623 add -0 -0E-19 -> -0E-19
+addx1624 add 0E-400 0E-19 -> 0E-398 Clamped
+addx1625 add -0E-400 0E-19 -> -0E-398 Clamped -- *
+addx1626 add 0E-400 -0E-19 -> -0E-398 Clamped -- *
+addx1627 add -0E-400 -0E-19 -> -0E-398 Clamped
+-- inexact zeros
+addx1631 add 1E-401 1E-400 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx1632 add -1E-401 1E-400 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx1633 add 1E-401 -1E-400 -> -1E-398 Subnormal Inexact Rounded Underflow
+addx1634 add -1E-401 -1E-400 -> -1E-398 Subnormal Inexact Rounded Underflow
+-- some exact zeros from non-zeros
+addx1635 add 1E-401 1E-401 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx1636 add -1E-401 1E-401 -> -0E-398 Clamped -- *
+addx1637 add 1E-401 -1E-401 -> -0E-398 Clamped -- *
+addx1638 add -1E-401 -1E-401 -> -1E-398 Subnormal Inexact Rounded Underflow
+
+-- BigDecimal problem testcases 2006.01.23
+precision: 16
+maxExponent: 384
+minexponent: -383
+
+rounding: down
+precision: 7
+addx1651 add 10001E+2 -2E+1 -> 1.00008E+6
+precision: 6
+addx1652 add 10001E+2 -2E+1 -> 1.00008E+6
+precision: 5
+addx1653 add 10001E+2 -2E+1 -> 1.0000E+6 Inexact Rounded
+precision: 4
+addx1654 add 10001E+2 -2E+1 -> 1.000E+6 Inexact Rounded
+precision: 3
+addx1655 add 10001E+2 -2E+1 -> 1.00E+6 Inexact Rounded
+precision: 2
+addx1656 add 10001E+2 -2E+1 -> 1.0E+6 Inexact Rounded
+precision: 1
+addx1657 add 10001E+2 -2E+1 -> 1E+6 Inexact Rounded
+
+rounding: half_even
+precision: 7
+addx1661 add 10001E+2 -2E+1 -> 1.00008E+6
+precision: 6
+addx1662 add 10001E+2 -2E+1 -> 1.00008E+6
+precision: 5
+addx1663 add 10001E+2 -2E+1 -> 1.0001E+6 Inexact Rounded
+precision: 4
+addx1664 add 10001E+2 -2E+1 -> 1.000E+6 Inexact Rounded
+precision: 3
+addx1665 add 10001E+2 -2E+1 -> 1.00E+6 Inexact Rounded
+precision: 2
+addx1666 add 10001E+2 -2E+1 -> 1.0E+6 Inexact Rounded
+precision: 1
+addx1667 add 10001E+2 -2E+1 -> 1E+6 Inexact Rounded
+
+rounding: up
+precision: 7
+addx1671 add 10001E+2 -2E+1 -> 1.00008E+6
+precision: 6
+addx1672 add 10001E+2 -2E+1 -> 1.00008E+6
+precision: 5
+addx1673 add 10001E+2 -2E+1 -> 1.0001E+6 Inexact Rounded
+precision: 4
+addx1674 add 10001E+2 -2E+1 -> 1.001E+6 Inexact Rounded
+precision: 3
+addx1675 add 10001E+2 -2E+1 -> 1.01E+6 Inexact Rounded
+precision: 2
+addx1676 add 10001E+2 -2E+1 -> 1.1E+6 Inexact Rounded
+precision: 1
+addx1677 add 10001E+2 -2E+1 -> 2E+6 Inexact Rounded
+
+precision: 34
+rounding: half_up
+maxExponent: 6144
+minExponent: -6143
+-- Examples from SQL proposal (Krishna Kulkarni)
+addx1701 add 130E-2 120E-2 -> 2.50
+addx1702 add 130E-2 12E-1 -> 2.50
+addx1703 add 130E-2 1E0 -> 2.30
+addx1704 add 1E2 1E4 -> 1.01E+4
+addx1705 subtract 130E-2 120E-2 -> 0.10
+addx1706 subtract 130E-2 12E-1 -> 0.10
+addx1707 subtract 130E-2 1E0 -> 0.30
+addx1708 subtract 1E2 1E4 -> -9.9E+3
+
+------------------------------------------------------------------------
+-- Same as above, using decimal64 default parameters --
+------------------------------------------------------------------------
+precision: 16
+rounding: half_even
+maxExponent: 384
+minexponent: -383
+
+-- [first group are 'quick confidence check']
+addx6001 add 1 1 -> 2
+addx6002 add 2 3 -> 5
+addx6003 add '5.75' '3.3' -> 9.05
+addx6004 add '5' '-3' -> 2
+addx6005 add '-5' '-3' -> -8
+addx6006 add '-7' '2.5' -> -4.5
+addx6007 add '0.7' '0.3' -> 1.0
+addx6008 add '1.25' '1.25' -> 2.50
+addx6009 add '1.23456789' '1.00000000' -> '2.23456789'
+addx6010 add '1.23456789' '1.00000011' -> '2.23456800'
+
+addx6011 add '0.44444444444444444' '0.55555555555555555' -> '1.000000000000000' Inexact Rounded
+addx6012 add '0.44444444444444440' '0.55555555555555555' -> '1.000000000000000' Inexact Rounded
+addx6013 add '0.44444444444444444' '0.55555555555555550' -> '0.9999999999999999' Inexact Rounded
+addx6014 add '0.444444444444444449' '0' -> '0.4444444444444444' Inexact Rounded
+addx6015 add '0.4444444444444444499' '0' -> '0.4444444444444444' Inexact Rounded
+addx6016 add '0.44444444444444444999' '0' -> '0.4444444444444444' Inexact Rounded
+addx6017 add '0.44444444444444445000' '0' -> '0.4444444444444444' Inexact Rounded
+addx6018 add '0.44444444444444445001' '0' -> '0.4444444444444445' Inexact Rounded
+addx6019 add '0.4444444444444444501' '0' -> '0.4444444444444445' Inexact Rounded
+addx6020 add '0.444444444444444451' '0' -> '0.4444444444444445' Inexact Rounded
+
+addx6021 add 0 1 -> 1
+addx6022 add 1 1 -> 2
+addx6023 add 2 1 -> 3
+addx6024 add 3 1 -> 4
+addx6025 add 4 1 -> 5
+addx6026 add 5 1 -> 6
+addx6027 add 6 1 -> 7
+addx6028 add 7 1 -> 8
+addx6029 add 8 1 -> 9
+addx6030 add 9 1 -> 10
+
+-- some carrying effects
+addx6031 add '0.9998' '0.0000' -> '0.9998'
+addx6032 add '0.9998' '0.0001' -> '0.9999'
+addx6033 add '0.9998' '0.0002' -> '1.0000'
+addx6034 add '0.9998' '0.0003' -> '1.0001'
+
+addx6035 add '70' '10000e+16' -> '1.000000000000000E+20' Inexact Rounded
+addx6036 add '700' '10000e+16' -> '1.000000000000000E+20' Inexact Rounded
+addx6037 add '7000' '10000e+16' -> '1.000000000000000E+20' Inexact Rounded
+addx6038 add '70000' '10000e+16' -> '1.000000000000001E+20' Inexact Rounded
+addx6039 add '700000' '10000e+16' -> '1.000000000000007E+20' Rounded
+
+-- symmetry:
+addx6040 add '10000e+16' '70' -> '1.000000000000000E+20' Inexact Rounded
+addx6041 add '10000e+16' '700' -> '1.000000000000000E+20' Inexact Rounded
+addx6042 add '10000e+16' '7000' -> '1.000000000000000E+20' Inexact Rounded
+addx6044 add '10000e+16' '70000' -> '1.000000000000001E+20' Inexact Rounded
+addx6045 add '10000e+16' '700000' -> '1.000000000000007E+20' Rounded
+
+addx6046 add '10000e+9' '7' -> '10000000000007'
+addx6047 add '10000e+9' '70' -> '10000000000070'
+addx6048 add '10000e+9' '700' -> '10000000000700'
+addx6049 add '10000e+9' '7000' -> '10000000007000'
+addx6050 add '10000e+9' '70000' -> '10000000070000'
+addx6051 add '10000e+9' '700000' -> '10000000700000'
+
+-- examples from decarith
+addx6053 add '12' '7.00' -> '19.00'
+addx6054 add '1.3' '-1.07' -> '0.23'
+addx6055 add '1.3' '-1.30' -> '0.00'
+addx6056 add '1.3' '-2.07' -> '-0.77'
+addx6057 add '1E+2' '1E+4' -> '1.01E+4'
+
+-- from above
+addx6061 add 1 '0.1' -> '1.1'
+addx6062 add 1 '0.01' -> '1.01'
+addx6063 add 1 '0.001' -> '1.001'
+addx6064 add 1 '0.0001' -> '1.0001'
+addx6065 add 1 '0.00001' -> '1.00001'
+addx6066 add 1 '0.000001' -> '1.000001'
+addx6067 add 1 '0.0000001' -> '1.0000001'
+addx6068 add 1 '0.00000001' -> '1.00000001'
+
+-- cancellation to integer
+addx6069 add 99999999999999123456789 -99999999999999E+9 -> 123456789
+
+-- some funny zeros [in case of bad signum]
+addx6070 add 1 0 -> 1
+addx6071 add 1 0. -> 1
+addx6072 add 1 .0 -> 1.0
+addx6073 add 1 0.0 -> 1.0
+addx6074 add 1 0.00 -> 1.00
+addx6075 add 0 1 -> 1
+addx6076 add 0. 1 -> 1
+addx6077 add .0 1 -> 1.0
+addx6078 add 0.0 1 -> 1.0
+addx6079 add 0.00 1 -> 1.00
-addx1160 add 100E-105 -1e-101 -> -0E-101 Subnormal Inexact Rounded Underflow
-addx1161 add 100E-105 -1e-201 -> 0E-101 Subnormal Inexact Rounded Underflow
+-- some carries
+addx6080 add 9999999999999998 1 -> 9999999999999999
+addx6081 add 9999999999999999 1 -> 1.000000000000000E+16 Rounded
+addx6082 add 999999999999999 1 -> 1000000000000000
+addx6083 add 9999999999999 1 -> 10000000000000
+addx6084 add 99999999999 1 -> 100000000000
+addx6085 add 999999999 1 -> 1000000000
+addx6086 add 9999999 1 -> 10000000
+addx6087 add 99999 1 -> 100000
+addx6088 add 999 1 -> 1000
+addx6089 add 9 1 -> 10
+
+
+-- more LHS swaps
+addx6090 add '-56267E-10' 0 -> '-0.0000056267'
+addx6091 add '-56267E-6' 0 -> '-0.056267'
+addx6092 add '-56267E-5' 0 -> '-0.56267'
+addx6093 add '-56267E-4' 0 -> '-5.6267'
+addx6094 add '-56267E-3' 0 -> '-56.267'
+addx6095 add '-56267E-2' 0 -> '-562.67'
+addx6096 add '-56267E-1' 0 -> '-5626.7'
+addx6097 add '-56267E-0' 0 -> '-56267'
+addx6098 add '-5E-10' 0 -> '-5E-10'
+addx6099 add '-5E-7' 0 -> '-5E-7'
+addx6100 add '-5E-6' 0 -> '-0.000005'
+addx6101 add '-5E-5' 0 -> '-0.00005'
+addx6102 add '-5E-4' 0 -> '-0.0005'
+addx6103 add '-5E-1' 0 -> '-0.5'
+addx6104 add '-5E0' 0 -> '-5'
+addx6105 add '-5E1' 0 -> '-50'
+addx6106 add '-5E5' 0 -> '-500000'
+addx6107 add '-5E15' 0 -> '-5000000000000000'
+addx6108 add '-5E16' 0 -> '-5.000000000000000E+16' Rounded
+addx6109 add '-5E17' 0 -> '-5.000000000000000E+17' Rounded
+addx6110 add '-5E18' 0 -> '-5.000000000000000E+18' Rounded
+addx6111 add '-5E100' 0 -> '-5.000000000000000E+100' Rounded
+-- more RHS swaps
+addx6113 add 0 '-56267E-10' -> '-0.0000056267'
+addx6114 add 0 '-56267E-6' -> '-0.056267'
+addx6116 add 0 '-56267E-5' -> '-0.56267'
+addx6117 add 0 '-56267E-4' -> '-5.6267'
+addx6119 add 0 '-56267E-3' -> '-56.267'
+addx6120 add 0 '-56267E-2' -> '-562.67'
+addx6121 add 0 '-56267E-1' -> '-5626.7'
+addx6122 add 0 '-56267E-0' -> '-56267'
+addx6123 add 0 '-5E-10' -> '-5E-10'
+addx6124 add 0 '-5E-7' -> '-5E-7'
+addx6125 add 0 '-5E-6' -> '-0.000005'
+addx6126 add 0 '-5E-5' -> '-0.00005'
+addx6127 add 0 '-5E-4' -> '-0.0005'
+addx6128 add 0 '-5E-1' -> '-0.5'
+addx6129 add 0 '-5E0' -> '-5'
+addx6130 add 0 '-5E1' -> '-50'
+addx6131 add 0 '-5E5' -> '-500000'
+addx6132 add 0 '-5E15' -> '-5000000000000000'
+addx6133 add 0 '-5E16' -> '-5.000000000000000E+16' Rounded
+addx6134 add 0 '-5E17' -> '-5.000000000000000E+17' Rounded
+addx6135 add 0 '-5E18' -> '-5.000000000000000E+18' Rounded
+addx6136 add 0 '-5E100' -> '-5.000000000000000E+100' Rounded
+
+-- related
+addx6137 add 1 '0E-19' -> '1.000000000000000' Rounded
+addx6138 add -1 '0E-19' -> '-1.000000000000000' Rounded
+addx6139 add '0E-19' 1 -> '1.000000000000000' Rounded
+addx6140 add '0E-19' -1 -> '-1.000000000000000' Rounded
+addx6141 add 1E+11 0.0000 -> '100000000000.0000'
+addx6142 add 1E+11 0.00000 -> '100000000000.0000' Rounded
+addx6143 add 0.000 1E+12 -> '1000000000000.000'
+addx6144 add 0.0000 1E+12 -> '1000000000000.000' Rounded
+
+-- [some of the next group are really constructor tests]
+addx6146 add '00.0' 0 -> '0.0'
+addx6147 add '0.00' 0 -> '0.00'
+addx6148 add 0 '0.00' -> '0.00'
+addx6149 add 0 '00.0' -> '0.0'
+addx6150 add '00.0' '0.00' -> '0.00'
+addx6151 add '0.00' '00.0' -> '0.00'
+addx6152 add '3' '.3' -> '3.3'
+addx6153 add '3.' '.3' -> '3.3'
+addx6154 add '3.0' '.3' -> '3.3'
+addx6155 add '3.00' '.3' -> '3.30'
+addx6156 add '3' '3' -> '6'
+addx6157 add '3' '+3' -> '6'
+addx6158 add '3' '-3' -> '0'
+addx6159 add '0.3' '-0.3' -> '0.0'
+addx6160 add '0.03' '-0.03' -> '0.00'
+
+-- try borderline precision, with carries, etc.
+addx6161 add '1E+13' '-1' -> '9999999999999'
+addx6162 add '1E+13' '1.11' -> '10000000000001.11'
+addx6163 add '1.11' '1E+13' -> '10000000000001.11'
+addx6164 add '-1' '1E+13' -> '9999999999999'
+addx6165 add '7E+13' '-1' -> '69999999999999'
+addx6166 add '7E+13' '1.11' -> '70000000000001.11'
+addx6167 add '1.11' '7E+13' -> '70000000000001.11'
+addx6168 add '-1' '7E+13' -> '69999999999999'
+
+-- 1234567890123456 1234567890123456 1 234567890123456
+addx6170 add '0.4444444444444444' '0.5555555555555563' -> '1.000000000000001' Inexact Rounded
+addx6171 add '0.4444444444444444' '0.5555555555555562' -> '1.000000000000001' Inexact Rounded
+addx6172 add '0.4444444444444444' '0.5555555555555561' -> '1.000000000000000' Inexact Rounded
+addx6173 add '0.4444444444444444' '0.5555555555555560' -> '1.000000000000000' Inexact Rounded
+addx6174 add '0.4444444444444444' '0.5555555555555559' -> '1.000000000000000' Inexact Rounded
+addx6175 add '0.4444444444444444' '0.5555555555555558' -> '1.000000000000000' Inexact Rounded
+addx6176 add '0.4444444444444444' '0.5555555555555557' -> '1.000000000000000' Inexact Rounded
+addx6177 add '0.4444444444444444' '0.5555555555555556' -> '1.000000000000000' Rounded
+addx6178 add '0.4444444444444444' '0.5555555555555555' -> '0.9999999999999999'
+addx6179 add '0.4444444444444444' '0.5555555555555554' -> '0.9999999999999998'
+addx6180 add '0.4444444444444444' '0.5555555555555553' -> '0.9999999999999997'
+addx6181 add '0.4444444444444444' '0.5555555555555552' -> '0.9999999999999996'
+addx6182 add '0.4444444444444444' '0.5555555555555551' -> '0.9999999999999995'
+addx6183 add '0.4444444444444444' '0.5555555555555550' -> '0.9999999999999994'
+
+-- and some more, including residue effects and different roundings
+rounding: half_up
+addx6200 add '6543210123456789' 0 -> '6543210123456789'
+addx6201 add '6543210123456789' 0.000000001 -> '6543210123456789' Inexact Rounded
+addx6202 add '6543210123456789' 0.000001 -> '6543210123456789' Inexact Rounded
+addx6203 add '6543210123456789' 0.1 -> '6543210123456789' Inexact Rounded
+addx6204 add '6543210123456789' 0.4 -> '6543210123456789' Inexact Rounded
+addx6205 add '6543210123456789' 0.49 -> '6543210123456789' Inexact Rounded
+addx6206 add '6543210123456789' 0.499999 -> '6543210123456789' Inexact Rounded
+addx6207 add '6543210123456789' 0.499999999 -> '6543210123456789' Inexact Rounded
+addx6208 add '6543210123456789' 0.5 -> '6543210123456790' Inexact Rounded
+addx6209 add '6543210123456789' 0.500000001 -> '6543210123456790' Inexact Rounded
+addx6210 add '6543210123456789' 0.500001 -> '6543210123456790' Inexact Rounded
+addx6211 add '6543210123456789' 0.51 -> '6543210123456790' Inexact Rounded
+addx6212 add '6543210123456789' 0.6 -> '6543210123456790' Inexact Rounded
+addx6213 add '6543210123456789' 0.9 -> '6543210123456790' Inexact Rounded
+addx6214 add '6543210123456789' 0.99999 -> '6543210123456790' Inexact Rounded
+addx6215 add '6543210123456789' 0.999999999 -> '6543210123456790' Inexact Rounded
+addx6216 add '6543210123456789' 1 -> '6543210123456790'
+addx6217 add '6543210123456789' 1.000000001 -> '6543210123456790' Inexact Rounded
+addx6218 add '6543210123456789' 1.00001 -> '6543210123456790' Inexact Rounded
+addx6219 add '6543210123456789' 1.1 -> '6543210123456790' Inexact Rounded
+
+rounding: half_even
+addx6220 add '6543210123456789' 0 -> '6543210123456789'
+addx6221 add '6543210123456789' 0.000000001 -> '6543210123456789' Inexact Rounded
+addx6222 add '6543210123456789' 0.000001 -> '6543210123456789' Inexact Rounded
+addx6223 add '6543210123456789' 0.1 -> '6543210123456789' Inexact Rounded
+addx6224 add '6543210123456789' 0.4 -> '6543210123456789' Inexact Rounded
+addx6225 add '6543210123456789' 0.49 -> '6543210123456789' Inexact Rounded
+addx6226 add '6543210123456789' 0.499999 -> '6543210123456789' Inexact Rounded
+addx6227 add '6543210123456789' 0.499999999 -> '6543210123456789' Inexact Rounded
+addx6228 add '6543210123456789' 0.5 -> '6543210123456790' Inexact Rounded
+addx6229 add '6543210123456789' 0.500000001 -> '6543210123456790' Inexact Rounded
+addx6230 add '6543210123456789' 0.500001 -> '6543210123456790' Inexact Rounded
+addx6231 add '6543210123456789' 0.51 -> '6543210123456790' Inexact Rounded
+addx6232 add '6543210123456789' 0.6 -> '6543210123456790' Inexact Rounded
+addx6233 add '6543210123456789' 0.9 -> '6543210123456790' Inexact Rounded
+addx6234 add '6543210123456789' 0.99999 -> '6543210123456790' Inexact Rounded
+addx6235 add '6543210123456789' 0.999999999 -> '6543210123456790' Inexact Rounded
+addx6236 add '6543210123456789' 1 -> '6543210123456790'
+addx6237 add '6543210123456789' 1.00000001 -> '6543210123456790' Inexact Rounded
+addx6238 add '6543210123456789' 1.00001 -> '6543210123456790' Inexact Rounded
+addx6239 add '6543210123456789' 1.1 -> '6543210123456790' Inexact Rounded
+-- critical few with even bottom digit...
+addx6240 add '6543210123456788' 0.499999999 -> '6543210123456788' Inexact Rounded
+addx6241 add '6543210123456788' 0.5 -> '6543210123456788' Inexact Rounded
+addx6242 add '6543210123456788' 0.500000001 -> '6543210123456789' Inexact Rounded
+
+rounding: down
+addx6250 add '6543210123456789' 0 -> '6543210123456789'
+addx6251 add '6543210123456789' 0.000000001 -> '6543210123456789' Inexact Rounded
+addx6252 add '6543210123456789' 0.000001 -> '6543210123456789' Inexact Rounded
+addx6253 add '6543210123456789' 0.1 -> '6543210123456789' Inexact Rounded
+addx6254 add '6543210123456789' 0.4 -> '6543210123456789' Inexact Rounded
+addx6255 add '6543210123456789' 0.49 -> '6543210123456789' Inexact Rounded
+addx6256 add '6543210123456789' 0.499999 -> '6543210123456789' Inexact Rounded
+addx6257 add '6543210123456789' 0.499999999 -> '6543210123456789' Inexact Rounded
+addx6258 add '6543210123456789' 0.5 -> '6543210123456789' Inexact Rounded
+addx6259 add '6543210123456789' 0.500000001 -> '6543210123456789' Inexact Rounded
+addx6260 add '6543210123456789' 0.500001 -> '6543210123456789' Inexact Rounded
+addx6261 add '6543210123456789' 0.51 -> '6543210123456789' Inexact Rounded
+addx6262 add '6543210123456789' 0.6 -> '6543210123456789' Inexact Rounded
+addx6263 add '6543210123456789' 0.9 -> '6543210123456789' Inexact Rounded
+addx6264 add '6543210123456789' 0.99999 -> '6543210123456789' Inexact Rounded
+addx6265 add '6543210123456789' 0.999999999 -> '6543210123456789' Inexact Rounded
+addx6266 add '6543210123456789' 1 -> '6543210123456790'
+addx6267 add '6543210123456789' 1.00000001 -> '6543210123456790' Inexact Rounded
+addx6268 add '6543210123456789' 1.00001 -> '6543210123456790' Inexact Rounded
+addx6269 add '6543210123456789' 1.1 -> '6543210123456790' Inexact Rounded
+
+-- 1 in last place tests
+rounding: half_even
+addx6301 add -1 1 -> 0
+addx6302 add 0 1 -> 1
+addx6303 add 1 1 -> 2
+addx6304 add 12 1 -> 13
+addx6305 add 98 1 -> 99
+addx6306 add 99 1 -> 100
+addx6307 add 100 1 -> 101
+addx6308 add 101 1 -> 102
+addx6309 add -1 -1 -> -2
+addx6310 add 0 -1 -> -1
+addx6311 add 1 -1 -> 0
+addx6312 add 12 -1 -> 11
+addx6313 add 98 -1 -> 97
+addx6314 add 99 -1 -> 98
+addx6315 add 100 -1 -> 99
+addx6316 add 101 -1 -> 100
+
+addx6321 add -0.01 0.01 -> 0.00
+addx6322 add 0.00 0.01 -> 0.01
+addx6323 add 0.01 0.01 -> 0.02
+addx6324 add 0.12 0.01 -> 0.13
+addx6325 add 0.98 0.01 -> 0.99
+addx6326 add 0.99 0.01 -> 1.00
+addx6327 add 1.00 0.01 -> 1.01
+addx6328 add 1.01 0.01 -> 1.02
+addx6329 add -0.01 -0.01 -> -0.02
+addx6330 add 0.00 -0.01 -> -0.01
+addx6331 add 0.01 -0.01 -> 0.00
+addx6332 add 0.12 -0.01 -> 0.11
+addx6333 add 0.98 -0.01 -> 0.97
+addx6334 add 0.99 -0.01 -> 0.98
+addx6335 add 1.00 -0.01 -> 0.99
+addx6336 add 1.01 -0.01 -> 1.00
+
+-- some more cases where adding 0 affects the coefficient
+addx6340 add 1E+3 0 -> 1000
+addx6341 add 1E+15 0 -> 1000000000000000
+addx6342 add 1E+16 0 -> 1.000000000000000E+16 Rounded
+addx6343 add 1E+17 0 -> 1.000000000000000E+17 Rounded
+-- which simply follow from these cases ...
+addx6344 add 1E+3 1 -> 1001
+addx6345 add 1E+15 1 -> 1000000000000001
+addx6346 add 1E+16 1 -> 1.000000000000000E+16 Inexact Rounded
+addx6347 add 1E+17 1 -> 1.000000000000000E+17 Inexact Rounded
+addx6348 add 1E+3 7 -> 1007
+addx6349 add 1E+15 7 -> 1000000000000007
+addx6350 add 1E+16 7 -> 1.000000000000001E+16 Inexact Rounded
+addx6351 add 1E+17 7 -> 1.000000000000000E+17 Inexact Rounded
+
+-- tryzeros cases
+addx6361 add 0E+50 10000E+1 -> 1.0000E+5
+addx6362 add 10000E+1 0E-50 -> 100000.0000000000 Rounded
+addx6363 add 10000E+1 10000E-50 -> 100000.0000000000 Rounded Inexact
+addx6364 add 12.34 0e-398 -> 12.34000000000000 Rounded
+
+-- ulp replacement tests
+addx6400 add 1 77e-14 -> 1.00000000000077
+addx6401 add 1 77e-15 -> 1.000000000000077
+addx6402 add 1 77e-16 -> 1.000000000000008 Inexact Rounded
+addx6403 add 1 77e-17 -> 1.000000000000001 Inexact Rounded
+addx6404 add 1 77e-18 -> 1.000000000000000 Inexact Rounded
+addx6405 add 1 77e-19 -> 1.000000000000000 Inexact Rounded
+addx6406 add 1 77e-99 -> 1.000000000000000 Inexact Rounded
+
+addx6410 add 10 77e-14 -> 10.00000000000077
+addx6411 add 10 77e-15 -> 10.00000000000008 Inexact Rounded
+addx6412 add 10 77e-16 -> 10.00000000000001 Inexact Rounded
+addx6413 add 10 77e-17 -> 10.00000000000000 Inexact Rounded
+addx6414 add 10 77e-18 -> 10.00000000000000 Inexact Rounded
+addx6415 add 10 77e-19 -> 10.00000000000000 Inexact Rounded
+addx6416 add 10 77e-99 -> 10.00000000000000 Inexact Rounded
+
+addx6420 add 77e-14 1 -> 1.00000000000077
+addx6421 add 77e-15 1 -> 1.000000000000077
+addx6422 add 77e-16 1 -> 1.000000000000008 Inexact Rounded
+addx6423 add 77e-17 1 -> 1.000000000000001 Inexact Rounded
+addx6424 add 77e-18 1 -> 1.000000000000000 Inexact Rounded
+addx6425 add 77e-19 1 -> 1.000000000000000 Inexact Rounded
+addx6426 add 77e-99 1 -> 1.000000000000000 Inexact Rounded
+
+addx6430 add 77e-14 10 -> 10.00000000000077
+addx6431 add 77e-15 10 -> 10.00000000000008 Inexact Rounded
+addx6432 add 77e-16 10 -> 10.00000000000001 Inexact Rounded
+addx6433 add 77e-17 10 -> 10.00000000000000 Inexact Rounded
+addx6434 add 77e-18 10 -> 10.00000000000000 Inexact Rounded
+addx6435 add 77e-19 10 -> 10.00000000000000 Inexact Rounded
+addx6436 add 77e-99 10 -> 10.00000000000000 Inexact Rounded
+
+-- negative ulps
+addx6440 add 1 -77e-14 -> 0.99999999999923
+addx6441 add 1 -77e-15 -> 0.999999999999923
+addx6442 add 1 -77e-16 -> 0.9999999999999923
+addx6443 add 1 -77e-17 -> 0.9999999999999992 Inexact Rounded
+addx6444 add 1 -77e-18 -> 0.9999999999999999 Inexact Rounded
+addx6445 add 1 -77e-19 -> 1.000000000000000 Inexact Rounded
+addx6446 add 1 -77e-99 -> 1.000000000000000 Inexact Rounded
+
+addx6450 add 10 -77e-14 -> 9.99999999999923
+addx6451 add 10 -77e-15 -> 9.999999999999923
+addx6452 add 10 -77e-16 -> 9.999999999999992 Inexact Rounded
+addx6453 add 10 -77e-17 -> 9.999999999999999 Inexact Rounded
+addx6454 add 10 -77e-18 -> 10.00000000000000 Inexact Rounded
+addx6455 add 10 -77e-19 -> 10.00000000000000 Inexact Rounded
+addx6456 add 10 -77e-99 -> 10.00000000000000 Inexact Rounded
+
+addx6460 add -77e-14 1 -> 0.99999999999923
+addx6461 add -77e-15 1 -> 0.999999999999923
+addx6462 add -77e-16 1 -> 0.9999999999999923
+addx6463 add -77e-17 1 -> 0.9999999999999992 Inexact Rounded
+addx6464 add -77e-18 1 -> 0.9999999999999999 Inexact Rounded
+addx6465 add -77e-19 1 -> 1.000000000000000 Inexact Rounded
+addx6466 add -77e-99 1 -> 1.000000000000000 Inexact Rounded
+
+addx6470 add -77e-14 10 -> 9.99999999999923
+addx6471 add -77e-15 10 -> 9.999999999999923
+addx6472 add -77e-16 10 -> 9.999999999999992 Inexact Rounded
+addx6473 add -77e-17 10 -> 9.999999999999999 Inexact Rounded
+addx6474 add -77e-18 10 -> 10.00000000000000 Inexact Rounded
+addx6475 add -77e-19 10 -> 10.00000000000000 Inexact Rounded
+addx6476 add -77e-99 10 -> 10.00000000000000 Inexact Rounded
+
+-- negative ulps
+addx6480 add -1 77e-14 -> -0.99999999999923
+addx6481 add -1 77e-15 -> -0.999999999999923
+addx6482 add -1 77e-16 -> -0.9999999999999923
+addx6483 add -1 77e-17 -> -0.9999999999999992 Inexact Rounded
+addx6484 add -1 77e-18 -> -0.9999999999999999 Inexact Rounded
+addx6485 add -1 77e-19 -> -1.000000000000000 Inexact Rounded
+addx6486 add -1 77e-99 -> -1.000000000000000 Inexact Rounded
+
+addx6490 add -10 77e-14 -> -9.99999999999923
+addx6491 add -10 77e-15 -> -9.999999999999923
+addx6492 add -10 77e-16 -> -9.999999999999992 Inexact Rounded
+addx6493 add -10 77e-17 -> -9.999999999999999 Inexact Rounded
+addx6494 add -10 77e-18 -> -10.00000000000000 Inexact Rounded
+addx6495 add -10 77e-19 -> -10.00000000000000 Inexact Rounded
+addx6496 add -10 77e-99 -> -10.00000000000000 Inexact Rounded
+
+addx6500 add 77e-14 -1 -> -0.99999999999923
+addx6501 add 77e-15 -1 -> -0.999999999999923
+addx6502 add 77e-16 -1 -> -0.9999999999999923
+addx6503 add 77e-17 -1 -> -0.9999999999999992 Inexact Rounded
+addx6504 add 77e-18 -1 -> -0.9999999999999999 Inexact Rounded
+addx6505 add 77e-19 -1 -> -1.000000000000000 Inexact Rounded
+addx6506 add 77e-99 -1 -> -1.000000000000000 Inexact Rounded
+
+addx6510 add 77e-14 -10 -> -9.99999999999923
+addx6511 add 77e-15 -10 -> -9.999999999999923
+addx6512 add 77e-16 -10 -> -9.999999999999992 Inexact Rounded
+addx6513 add 77e-17 -10 -> -9.999999999999999 Inexact Rounded
+addx6514 add 77e-18 -10 -> -10.00000000000000 Inexact Rounded
+addx6515 add 77e-19 -10 -> -10.00000000000000 Inexact Rounded
+addx6516 add 77e-99 -10 -> -10.00000000000000 Inexact Rounded
+
+
+-- long operands
+addx6521 add 101234562345678000 0 -> 1.012345623456780E+17 Rounded
+addx6522 add 0 101234562345678000 -> 1.012345623456780E+17 Rounded
+addx6523 add 10123456234567800 0 -> 1.012345623456780E+16 Rounded
+addx6524 add 0 10123456234567800 -> 1.012345623456780E+16 Rounded
+addx6525 add 10123456234567890 0 -> 1.012345623456789E+16 Rounded
+addx6526 add 0 10123456234567890 -> 1.012345623456789E+16 Rounded
+addx6527 add 10123456234567891 0 -> 1.012345623456789E+16 Inexact Rounded
+addx6528 add 0 10123456234567891 -> 1.012345623456789E+16 Inexact Rounded
+addx6529 add 101234562345678901 0 -> 1.012345623456789E+17 Inexact Rounded
+addx6530 add 0 101234562345678901 -> 1.012345623456789E+17 Inexact Rounded
+addx6531 add 10123456234567896 0 -> 1.012345623456790E+16 Inexact Rounded
+addx6532 add 0 10123456234567896 -> 1.012345623456790E+16 Inexact Rounded
+
+-- verify a query
+rounding: down
+addx6561 add 1e-398 9.000000000000000E+384 -> 9.000000000000000E+384 Inexact Rounded
+addx6562 add 0 9.000000000000000E+384 -> 9.000000000000000E+384 Rounded
+-- and using decimal64 bounds...
+rounding: down
+addx6563 add 1e-388 9.000000000000000E+374 -> 9.000000000000000E+374 Inexact Rounded
+addx6564 add 0 9.000000000000000E+374 -> 9.000000000000000E+374 Rounded
+
+-- more zeros, etc.
+rounding: half_even
+
+addx6701 add 5.00 1.00E-3 -> 5.00100
+addx6702 add 00.00 0.000 -> 0.000
+addx6703 add 00.00 0E-3 -> 0.000
+addx6704 add 0E-3 00.00 -> 0.000
+
+addx6710 add 0E+3 00.00 -> 0.00
+addx6711 add 0E+3 00.0 -> 0.0
+addx6712 add 0E+3 00. -> 0
+addx6713 add 0E+3 00.E+1 -> 0E+1
+addx6714 add 0E+3 00.E+2 -> 0E+2
+addx6715 add 0E+3 00.E+3 -> 0E+3
+addx6716 add 0E+3 00.E+4 -> 0E+3
+addx6717 add 0E+3 00.E+5 -> 0E+3
+addx6718 add 0E+3 -00.0 -> 0.0
+addx6719 add 0E+3 -00. -> 0
+addx6731 add 0E+3 -00.E+1 -> 0E+1
+
+addx6720 add 00.00 0E+3 -> 0.00
+addx6721 add 00.0 0E+3 -> 0.0
+addx6722 add 00. 0E+3 -> 0
+addx6723 add 00.E+1 0E+3 -> 0E+1
+addx6724 add 00.E+2 0E+3 -> 0E+2
+addx6725 add 00.E+3 0E+3 -> 0E+3
+addx6726 add 00.E+4 0E+3 -> 0E+3
+addx6727 add 00.E+5 0E+3 -> 0E+3
+addx6728 add -00.00 0E+3 -> 0.00
+addx6729 add -00.0 0E+3 -> 0.0
+addx6730 add -00. 0E+3 -> 0
+
+addx6732 add 0 0 -> 0
+addx6733 add 0 -0 -> 0
+addx6734 add -0 0 -> 0
+addx6735 add -0 -0 -> -0 -- IEEE 854 special case
+
+addx6736 add 1 -1 -> 0
+addx6737 add -1 -1 -> -2
+addx6738 add 1 1 -> 2
+addx6739 add -1 1 -> 0
+
+addx6741 add 0 -1 -> -1
+addx6742 add -0 -1 -> -1
+addx6743 add 0 1 -> 1
+addx6744 add -0 1 -> 1
+addx6745 add -1 0 -> -1
+addx6746 add -1 -0 -> -1
+addx6747 add 1 0 -> 1
+addx6748 add 1 -0 -> 1
+
+addx6751 add 0.0 -1 -> -1.0
+addx6752 add -0.0 -1 -> -1.0
+addx6753 add 0.0 1 -> 1.0
+addx6754 add -0.0 1 -> 1.0
+addx6755 add -1.0 0 -> -1.0
+addx6756 add -1.0 -0 -> -1.0
+addx6757 add 1.0 0 -> 1.0
+addx6758 add 1.0 -0 -> 1.0
+
+addx6761 add 0 -1.0 -> -1.0
+addx6762 add -0 -1.0 -> -1.0
+addx6763 add 0 1.0 -> 1.0
+addx6764 add -0 1.0 -> 1.0
+addx6765 add -1 0.0 -> -1.0
+addx6766 add -1 -0.0 -> -1.0
+addx6767 add 1 0.0 -> 1.0
+addx6768 add 1 -0.0 -> 1.0
+
+addx6771 add 0.0 -1.0 -> -1.0
+addx6772 add -0.0 -1.0 -> -1.0
+addx6773 add 0.0 1.0 -> 1.0
+addx6774 add -0.0 1.0 -> 1.0
+addx6775 add -1.0 0.0 -> -1.0
+addx6776 add -1.0 -0.0 -> -1.0
+addx6777 add 1.0 0.0 -> 1.0
+addx6778 add 1.0 -0.0 -> 1.0
+
+-- Specials
+addx6780 add -Inf -Inf -> -Infinity
+addx6781 add -Inf -1000 -> -Infinity
+addx6782 add -Inf -1 -> -Infinity
+addx6783 add -Inf -0 -> -Infinity
+addx6784 add -Inf 0 -> -Infinity
+addx6785 add -Inf 1 -> -Infinity
+addx6786 add -Inf 1000 -> -Infinity
+addx6787 add -1000 -Inf -> -Infinity
+addx6788 add -Inf -Inf -> -Infinity
+addx6789 add -1 -Inf -> -Infinity
+addx6790 add -0 -Inf -> -Infinity
+addx6791 add 0 -Inf -> -Infinity
+addx6792 add 1 -Inf -> -Infinity
+addx6793 add 1000 -Inf -> -Infinity
+addx6794 add Inf -Inf -> NaN Invalid_operation
+
+addx6800 add Inf -Inf -> NaN Invalid_operation
+addx6801 add Inf -1000 -> Infinity
+addx6802 add Inf -1 -> Infinity
+addx6803 add Inf -0 -> Infinity
+addx6804 add Inf 0 -> Infinity
+addx6805 add Inf 1 -> Infinity
+addx6806 add Inf 1000 -> Infinity
+addx6807 add Inf Inf -> Infinity
+addx6808 add -1000 Inf -> Infinity
+addx6809 add -Inf Inf -> NaN Invalid_operation
+addx6810 add -1 Inf -> Infinity
+addx6811 add -0 Inf -> Infinity
+addx6812 add 0 Inf -> Infinity
+addx6813 add 1 Inf -> Infinity
+addx6814 add 1000 Inf -> Infinity
+addx6815 add Inf Inf -> Infinity
+
+addx6821 add NaN -Inf -> NaN
+addx6822 add NaN -1000 -> NaN
+addx6823 add NaN -1 -> NaN
+addx6824 add NaN -0 -> NaN
+addx6825 add NaN 0 -> NaN
+addx6826 add NaN 1 -> NaN
+addx6827 add NaN 1000 -> NaN
+addx6828 add NaN Inf -> NaN
+addx6829 add NaN NaN -> NaN
+addx6830 add -Inf NaN -> NaN
+addx6831 add -1000 NaN -> NaN
+addx6832 add -1 NaN -> NaN
+addx6833 add -0 NaN -> NaN
+addx6834 add 0 NaN -> NaN
+addx6835 add 1 NaN -> NaN
+addx6836 add 1000 NaN -> NaN
+addx6837 add Inf NaN -> NaN
+
+addx6841 add sNaN -Inf -> NaN Invalid_operation
+addx6842 add sNaN -1000 -> NaN Invalid_operation
+addx6843 add sNaN -1 -> NaN Invalid_operation
+addx6844 add sNaN -0 -> NaN Invalid_operation
+addx6845 add sNaN 0 -> NaN Invalid_operation
+addx6846 add sNaN 1 -> NaN Invalid_operation
+addx6847 add sNaN 1000 -> NaN Invalid_operation
+addx6848 add sNaN NaN -> NaN Invalid_operation
+addx6849 add sNaN sNaN -> NaN Invalid_operation
+addx6850 add NaN sNaN -> NaN Invalid_operation
+addx6851 add -Inf sNaN -> NaN Invalid_operation
+addx6852 add -1000 sNaN -> NaN Invalid_operation
+addx6853 add -1 sNaN -> NaN Invalid_operation
+addx6854 add -0 sNaN -> NaN Invalid_operation
+addx6855 add 0 sNaN -> NaN Invalid_operation
+addx6856 add 1 sNaN -> NaN Invalid_operation
+addx6857 add 1000 sNaN -> NaN Invalid_operation
+addx6858 add Inf sNaN -> NaN Invalid_operation
+addx6859 add NaN sNaN -> NaN Invalid_operation
+
+-- propagating NaNs
+addx6861 add NaN1 -Inf -> NaN1
+addx6862 add +NaN2 -1000 -> NaN2
+addx6863 add NaN3 1000 -> NaN3
+addx6864 add NaN4 Inf -> NaN4
+addx6865 add NaN5 +NaN6 -> NaN5
+addx6866 add -Inf NaN7 -> NaN7
+addx6867 add -1000 NaN8 -> NaN8
+addx6868 add 1000 NaN9 -> NaN9
+addx6869 add Inf +NaN10 -> NaN10
+addx6871 add sNaN11 -Inf -> NaN11 Invalid_operation
+addx6872 add sNaN12 -1000 -> NaN12 Invalid_operation
+addx6873 add sNaN13 1000 -> NaN13 Invalid_operation
+addx6874 add sNaN14 NaN17 -> NaN14 Invalid_operation
+addx6875 add sNaN15 sNaN18 -> NaN15 Invalid_operation
+addx6876 add NaN16 sNaN19 -> NaN19 Invalid_operation
+addx6877 add -Inf +sNaN20 -> NaN20 Invalid_operation
+addx6878 add -1000 sNaN21 -> NaN21 Invalid_operation
+addx6879 add 1000 sNaN22 -> NaN22 Invalid_operation
+addx6880 add Inf sNaN23 -> NaN23 Invalid_operation
+addx6881 add +NaN25 +sNaN24 -> NaN24 Invalid_operation
+addx6882 add -NaN26 NaN28 -> -NaN26
+addx6883 add -sNaN27 sNaN29 -> -NaN27 Invalid_operation
+addx6884 add 1000 -NaN30 -> -NaN30
+addx6885 add 1000 -sNaN31 -> -NaN31 Invalid_operation
+
+-- now the case where we can get underflow but the result is normal
+-- [note this can't happen if the operands are also bounded, as we
+-- cannot represent 1E-399, for example]
+
+addx6571 add 1E-383 0 -> 1E-383
+addx6572 add 1E-384 0 -> 1E-384 Subnormal
+addx6573 add 1E-383 1E-384 -> 1.1E-383
+addx6574 subtract 1E-383 1E-384 -> 9E-384 Subnormal
+
+-- Here we explore the boundary of rounding a subnormal to Nmin
+addx6575 subtract 1E-383 1E-398 -> 9.99999999999999E-384 Subnormal
+addx6576 subtract 1E-383 1E-398 -> 9.99999999999999E-384 Subnormal
+addx6577 subtract 1E-383 1E-399 -> 1.000000000000000E-383 Underflow Inexact Subnormal Rounded
+addx6578 subtract 1E-383 1E-400 -> 1.000000000000000E-383 Underflow Inexact Subnormal Rounded
+addx6579 subtract 1E-383 1E-401 -> 1.000000000000000E-383 Underflow Inexact Subnormal Rounded
+addx6580 subtract 1E-383 1E-402 -> 1.000000000000000E-383 Underflow Inexact Subnormal Rounded
+
+-- check overflow edge case
+-- 1234567890123456
+addx6972 apply 9.999999999999999E+384 -> 9.999999999999999E+384
+addx6973 add 9.999999999999999E+384 1 -> 9.999999999999999E+384 Inexact Rounded
+addx6974 add 9999999999999999E+369 1 -> 9.999999999999999E+384 Inexact Rounded
+addx6975 add 9999999999999999E+369 1E+369 -> Infinity Overflow Inexact Rounded
+addx6976 add 9999999999999999E+369 9E+368 -> Infinity Overflow Inexact Rounded
+addx6977 add 9999999999999999E+369 8E+368 -> Infinity Overflow Inexact Rounded
+addx6978 add 9999999999999999E+369 7E+368 -> Infinity Overflow Inexact Rounded
+addx6979 add 9999999999999999E+369 6E+368 -> Infinity Overflow Inexact Rounded
+addx6980 add 9999999999999999E+369 5E+368 -> Infinity Overflow Inexact Rounded
+addx6981 add 9999999999999999E+369 4E+368 -> 9.999999999999999E+384 Inexact Rounded
+addx6982 add 9999999999999999E+369 3E+368 -> 9.999999999999999E+384 Inexact Rounded
+addx6983 add 9999999999999999E+369 2E+368 -> 9.999999999999999E+384 Inexact Rounded
+addx6984 add 9999999999999999E+369 1E+368 -> 9.999999999999999E+384 Inexact Rounded
+
+addx6985 apply -9.999999999999999E+384 -> -9.999999999999999E+384
+addx6986 add -9.999999999999999E+384 -1 -> -9.999999999999999E+384 Inexact Rounded
+addx6987 add -9999999999999999E+369 -1 -> -9.999999999999999E+384 Inexact Rounded
+addx6988 add -9999999999999999E+369 -1E+369 -> -Infinity Overflow Inexact Rounded
+addx6989 add -9999999999999999E+369 -9E+368 -> -Infinity Overflow Inexact Rounded
+addx6990 add -9999999999999999E+369 -8E+368 -> -Infinity Overflow Inexact Rounded
+addx6991 add -9999999999999999E+369 -7E+368 -> -Infinity Overflow Inexact Rounded
+addx6992 add -9999999999999999E+369 -6E+368 -> -Infinity Overflow Inexact Rounded
+addx6993 add -9999999999999999E+369 -5E+368 -> -Infinity Overflow Inexact Rounded
+addx6994 add -9999999999999999E+369 -4E+368 -> -9.999999999999999E+384 Inexact Rounded
+addx6995 add -9999999999999999E+369 -3E+368 -> -9.999999999999999E+384 Inexact Rounded
+addx6996 add -9999999999999999E+369 -2E+368 -> -9.999999999999999E+384 Inexact Rounded
+addx6997 add -9999999999999999E+369 -1E+368 -> -9.999999999999999E+384 Inexact Rounded
+
+-- And for round down full and subnormal results
+rounding: down
+addx61100 add 1e+2 -1e-383 -> 99.99999999999999 Rounded Inexact
+addx61101 add 1e+1 -1e-383 -> 9.999999999999999 Rounded Inexact
+addx61103 add +1 -1e-383 -> 0.9999999999999999 Rounded Inexact
+addx61104 add 1e-1 -1e-383 -> 0.09999999999999999 Rounded Inexact
+addx61105 add 1e-2 -1e-383 -> 0.009999999999999999 Rounded Inexact
+addx61106 add 1e-3 -1e-383 -> 0.0009999999999999999 Rounded Inexact
+addx61107 add 1e-4 -1e-383 -> 0.00009999999999999999 Rounded Inexact
+addx61108 add 1e-5 -1e-383 -> 0.000009999999999999999 Rounded Inexact
+addx61109 add 1e-6 -1e-383 -> 9.999999999999999E-7 Rounded Inexact
+
+rounding: ceiling
+addx61110 add -1e+2 +1e-383 -> -99.99999999999999 Rounded Inexact
+addx61111 add -1e+1 +1e-383 -> -9.999999999999999 Rounded Inexact
+addx61113 add -1 +1e-383 -> -0.9999999999999999 Rounded Inexact
+addx61114 add -1e-1 +1e-383 -> -0.09999999999999999 Rounded Inexact
+addx61115 add -1e-2 +1e-383 -> -0.009999999999999999 Rounded Inexact
+addx61116 add -1e-3 +1e-383 -> -0.0009999999999999999 Rounded Inexact
+addx61117 add -1e-4 +1e-383 -> -0.00009999999999999999 Rounded Inexact
+addx61118 add -1e-5 +1e-383 -> -0.000009999999999999999 Rounded Inexact
+addx61119 add -1e-6 +1e-383 -> -9.999999999999999E-7 Rounded Inexact
+
+-- tests based on Gunnar Degnbol's edge case
+rounding: half_even
+
+addx61300 add 1E16 -0.5 -> 1.000000000000000E+16 Inexact Rounded
+addx61310 add 1E16 -0.51 -> 9999999999999999 Inexact Rounded
+addx61311 add 1E16 -0.501 -> 9999999999999999 Inexact Rounded
+addx61312 add 1E16 -0.5001 -> 9999999999999999 Inexact Rounded
+addx61313 add 1E16 -0.50001 -> 9999999999999999 Inexact Rounded
+addx61314 add 1E16 -0.500001 -> 9999999999999999 Inexact Rounded
+addx61315 add 1E16 -0.5000001 -> 9999999999999999 Inexact Rounded
+addx61316 add 1E16 -0.50000001 -> 9999999999999999 Inexact Rounded
+addx61317 add 1E16 -0.500000001 -> 9999999999999999 Inexact Rounded
+addx61318 add 1E16 -0.5000000001 -> 9999999999999999 Inexact Rounded
+addx61319 add 1E16 -0.50000000001 -> 9999999999999999 Inexact Rounded
+addx61320 add 1E16 -0.500000000001 -> 9999999999999999 Inexact Rounded
+addx61321 add 1E16 -0.5000000000001 -> 9999999999999999 Inexact Rounded
+addx61322 add 1E16 -0.50000000000001 -> 9999999999999999 Inexact Rounded
+addx61323 add 1E16 -0.500000000000001 -> 9999999999999999 Inexact Rounded
+addx61324 add 1E16 -0.5000000000000001 -> 9999999999999999 Inexact Rounded
+addx61325 add 1E16 -0.5000000000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx61326 add 1E16 -0.500000000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx61327 add 1E16 -0.50000000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx61328 add 1E16 -0.5000000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx61329 add 1E16 -0.500000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx61330 add 1E16 -0.50000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx61331 add 1E16 -0.5000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx61332 add 1E16 -0.500000000 -> 1.000000000000000E+16 Inexact Rounded
+addx61333 add 1E16 -0.50000000 -> 1.000000000000000E+16 Inexact Rounded
+addx61334 add 1E16 -0.5000000 -> 1.000000000000000E+16 Inexact Rounded
+addx61335 add 1E16 -0.500000 -> 1.000000000000000E+16 Inexact Rounded
+addx61336 add 1E16 -0.50000 -> 1.000000000000000E+16 Inexact Rounded
+addx61337 add 1E16 -0.5000 -> 1.000000000000000E+16 Inexact Rounded
+addx61338 add 1E16 -0.500 -> 1.000000000000000E+16 Inexact Rounded
+addx61339 add 1E16 -0.50 -> 1.000000000000000E+16 Inexact Rounded
+
+addx61340 add 1E16 -5000000.000010001 -> 9999999995000000 Inexact Rounded
+addx61341 add 1E16 -5000000.000000001 -> 9999999995000000 Inexact Rounded
+
+addx61349 add 9999999999999999 0.4 -> 9999999999999999 Inexact Rounded
+addx61350 add 9999999999999999 0.49 -> 9999999999999999 Inexact Rounded
+addx61351 add 9999999999999999 0.499 -> 9999999999999999 Inexact Rounded
+addx61352 add 9999999999999999 0.4999 -> 9999999999999999 Inexact Rounded
+addx61353 add 9999999999999999 0.49999 -> 9999999999999999 Inexact Rounded
+addx61354 add 9999999999999999 0.499999 -> 9999999999999999 Inexact Rounded
+addx61355 add 9999999999999999 0.4999999 -> 9999999999999999 Inexact Rounded
+addx61356 add 9999999999999999 0.49999999 -> 9999999999999999 Inexact Rounded
+addx61357 add 9999999999999999 0.499999999 -> 9999999999999999 Inexact Rounded
+addx61358 add 9999999999999999 0.4999999999 -> 9999999999999999 Inexact Rounded
+addx61359 add 9999999999999999 0.49999999999 -> 9999999999999999 Inexact Rounded
+addx61360 add 9999999999999999 0.499999999999 -> 9999999999999999 Inexact Rounded
+addx61361 add 9999999999999999 0.4999999999999 -> 9999999999999999 Inexact Rounded
+addx61362 add 9999999999999999 0.49999999999999 -> 9999999999999999 Inexact Rounded
+addx61363 add 9999999999999999 0.499999999999999 -> 9999999999999999 Inexact Rounded
+addx61364 add 9999999999999999 0.4999999999999999 -> 9999999999999999 Inexact Rounded
+addx61365 add 9999999999999999 0.5000000000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx61367 add 9999999999999999 0.500000000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx61368 add 9999999999999999 0.50000000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx61369 add 9999999999999999 0.5000000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx61370 add 9999999999999999 0.500000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx61371 add 9999999999999999 0.50000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx61372 add 9999999999999999 0.5000000000 -> 1.000000000000000E+16 Inexact Rounded
+addx61373 add 9999999999999999 0.500000000 -> 1.000000000000000E+16 Inexact Rounded
+addx61374 add 9999999999999999 0.50000000 -> 1.000000000000000E+16 Inexact Rounded
+addx61375 add 9999999999999999 0.5000000 -> 1.000000000000000E+16 Inexact Rounded
+addx61376 add 9999999999999999 0.500000 -> 1.000000000000000E+16 Inexact Rounded
+addx61377 add 9999999999999999 0.50000 -> 1.000000000000000E+16 Inexact Rounded
+addx61378 add 9999999999999999 0.5000 -> 1.000000000000000E+16 Inexact Rounded
+addx61379 add 9999999999999999 0.500 -> 1.000000000000000E+16 Inexact Rounded
+addx61380 add 9999999999999999 0.50 -> 1.000000000000000E+16 Inexact Rounded
+addx61381 add 9999999999999999 0.5 -> 1.000000000000000E+16 Inexact Rounded
+addx61382 add 9999999999999999 0.5000000000000001 -> 1.000000000000000E+16 Inexact Rounded
+addx61383 add 9999999999999999 0.500000000000001 -> 1.000000000000000E+16 Inexact Rounded
+addx61384 add 9999999999999999 0.50000000000001 -> 1.000000000000000E+16 Inexact Rounded
+addx61385 add 9999999999999999 0.5000000000001 -> 1.000000000000000E+16 Inexact Rounded
+addx61386 add 9999999999999999 0.500000000001 -> 1.000000000000000E+16 Inexact Rounded
+addx61387 add 9999999999999999 0.50000000001 -> 1.000000000000000E+16 Inexact Rounded
+addx61388 add 9999999999999999 0.5000000001 -> 1.000000000000000E+16 Inexact Rounded
+addx61389 add 9999999999999999 0.500000001 -> 1.000000000000000E+16 Inexact Rounded
+addx61390 add 9999999999999999 0.50000001 -> 1.000000000000000E+16 Inexact Rounded
+addx61391 add 9999999999999999 0.5000001 -> 1.000000000000000E+16 Inexact Rounded
+addx61392 add 9999999999999999 0.500001 -> 1.000000000000000E+16 Inexact Rounded
+addx61393 add 9999999999999999 0.50001 -> 1.000000000000000E+16 Inexact Rounded
+addx61394 add 9999999999999999 0.5001 -> 1.000000000000000E+16 Inexact Rounded
+addx61395 add 9999999999999999 0.501 -> 1.000000000000000E+16 Inexact Rounded
+addx61396 add 9999999999999999 0.51 -> 1.000000000000000E+16 Inexact Rounded
+
+-- More GD edge cases, where difference between the unadjusted
+-- exponents is larger than the maximum precision and one side is 0
+addx61420 add 0 1.123456789012345 -> 1.123456789012345
+addx61421 add 0 1.123456789012345E-1 -> 0.1123456789012345
+addx61422 add 0 1.123456789012345E-2 -> 0.01123456789012345
+addx61423 add 0 1.123456789012345E-3 -> 0.001123456789012345
+addx61424 add 0 1.123456789012345E-4 -> 0.0001123456789012345
+addx61425 add 0 1.123456789012345E-5 -> 0.00001123456789012345
+addx61426 add 0 1.123456789012345E-6 -> 0.000001123456789012345
+addx61427 add 0 1.123456789012345E-7 -> 1.123456789012345E-7
+addx61428 add 0 1.123456789012345E-8 -> 1.123456789012345E-8
+addx61429 add 0 1.123456789012345E-9 -> 1.123456789012345E-9
+addx61430 add 0 1.123456789012345E-10 -> 1.123456789012345E-10
+addx61431 add 0 1.123456789012345E-11 -> 1.123456789012345E-11
+addx61432 add 0 1.123456789012345E-12 -> 1.123456789012345E-12
+addx61433 add 0 1.123456789012345E-13 -> 1.123456789012345E-13
+addx61434 add 0 1.123456789012345E-14 -> 1.123456789012345E-14
+addx61435 add 0 1.123456789012345E-15 -> 1.123456789012345E-15
+addx61436 add 0 1.123456789012345E-16 -> 1.123456789012345E-16
+addx61437 add 0 1.123456789012345E-17 -> 1.123456789012345E-17
+addx61438 add 0 1.123456789012345E-18 -> 1.123456789012345E-18
+addx61439 add 0 1.123456789012345E-19 -> 1.123456789012345E-19
+
+-- same, reversed 0
+addx61440 add 1.123456789012345 0 -> 1.123456789012345
+addx61441 add 1.123456789012345E-1 0 -> 0.1123456789012345
+addx61442 add 1.123456789012345E-2 0 -> 0.01123456789012345
+addx61443 add 1.123456789012345E-3 0 -> 0.001123456789012345
+addx61444 add 1.123456789012345E-4 0 -> 0.0001123456789012345
+addx61445 add 1.123456789012345E-5 0 -> 0.00001123456789012345
+addx61446 add 1.123456789012345E-6 0 -> 0.000001123456789012345
+addx61447 add 1.123456789012345E-7 0 -> 1.123456789012345E-7
+addx61448 add 1.123456789012345E-8 0 -> 1.123456789012345E-8
+addx61449 add 1.123456789012345E-9 0 -> 1.123456789012345E-9
+addx61450 add 1.123456789012345E-10 0 -> 1.123456789012345E-10
+addx61451 add 1.123456789012345E-11 0 -> 1.123456789012345E-11
+addx61452 add 1.123456789012345E-12 0 -> 1.123456789012345E-12
+addx61453 add 1.123456789012345E-13 0 -> 1.123456789012345E-13
+addx61454 add 1.123456789012345E-14 0 -> 1.123456789012345E-14
+addx61455 add 1.123456789012345E-15 0 -> 1.123456789012345E-15
+addx61456 add 1.123456789012345E-16 0 -> 1.123456789012345E-16
+addx61457 add 1.123456789012345E-17 0 -> 1.123456789012345E-17
+addx61458 add 1.123456789012345E-18 0 -> 1.123456789012345E-18
+addx61459 add 1.123456789012345E-19 0 -> 1.123456789012345E-19
+
+-- same, Es on the 0
+addx61460 add 1.123456789012345 0E-0 -> 1.123456789012345
+addx61461 add 1.123456789012345 0E-1 -> 1.123456789012345
+addx61462 add 1.123456789012345 0E-2 -> 1.123456789012345
+addx61463 add 1.123456789012345 0E-3 -> 1.123456789012345
+addx61464 add 1.123456789012345 0E-4 -> 1.123456789012345
+addx61465 add 1.123456789012345 0E-5 -> 1.123456789012345
+addx61466 add 1.123456789012345 0E-6 -> 1.123456789012345
+addx61467 add 1.123456789012345 0E-7 -> 1.123456789012345
+addx61468 add 1.123456789012345 0E-8 -> 1.123456789012345
+addx61469 add 1.123456789012345 0E-9 -> 1.123456789012345
+addx61470 add 1.123456789012345 0E-10 -> 1.123456789012345
+addx61471 add 1.123456789012345 0E-11 -> 1.123456789012345
+addx61472 add 1.123456789012345 0E-12 -> 1.123456789012345
+addx61473 add 1.123456789012345 0E-13 -> 1.123456789012345
+addx61474 add 1.123456789012345 0E-14 -> 1.123456789012345
+addx61475 add 1.123456789012345 0E-15 -> 1.123456789012345
+-- next four flag Rounded because the 0 extends the result
+addx61476 add 1.123456789012345 0E-16 -> 1.123456789012345 Rounded
+addx61477 add 1.123456789012345 0E-17 -> 1.123456789012345 Rounded
+addx61478 add 1.123456789012345 0E-18 -> 1.123456789012345 Rounded
+addx61479 add 1.123456789012345 0E-19 -> 1.123456789012345 Rounded
+
+-- sum of two opposite-sign operands is exactly 0 and floor => -0
+rounding: half_up
+-- exact zeros from zeros
+addx61500 add 0 0E-19 -> 0E-19
+addx61501 add -0 0E-19 -> 0E-19
+addx61502 add 0 -0E-19 -> 0E-19
+addx61503 add -0 -0E-19 -> -0E-19
+addx61504 add 0E-400 0E-19 -> 0E-398 Clamped
+addx61505 add -0E-400 0E-19 -> 0E-398 Clamped
+addx61506 add 0E-400 -0E-19 -> 0E-398 Clamped
+addx61507 add -0E-400 -0E-19 -> -0E-398 Clamped
+-- inexact zeros
+addx61511 add 1E-401 1E-400 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx61512 add -1E-401 1E-400 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx61513 add 1E-401 -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx61514 add -1E-401 -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+-- some exact zeros from non-zeros
+addx61515 add 1E-401 1E-401 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx61516 add -1E-401 1E-401 -> 0E-398 Clamped
+addx61517 add 1E-401 -1E-401 -> 0E-398 Clamped
+addx61518 add -1E-401 -1E-401 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+
+rounding: half_down
+-- exact zeros from zeros
+addx61520 add 0 0E-19 -> 0E-19
+addx61521 add -0 0E-19 -> 0E-19
+addx61522 add 0 -0E-19 -> 0E-19
+addx61523 add -0 -0E-19 -> -0E-19
+addx61524 add 0E-400 0E-19 -> 0E-398 Clamped
+addx61525 add -0E-400 0E-19 -> 0E-398 Clamped
+addx61526 add 0E-400 -0E-19 -> 0E-398 Clamped
+addx61527 add -0E-400 -0E-19 -> -0E-398 Clamped
+-- inexact zeros
+addx61531 add 1E-401 1E-400 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx61532 add -1E-401 1E-400 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx61533 add 1E-401 -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx61534 add -1E-401 -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+-- some exact zeros from non-zeros
+addx61535 add 1E-401 1E-401 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx61536 add -1E-401 1E-401 -> 0E-398 Clamped
+addx61537 add 1E-401 -1E-401 -> 0E-398 Clamped
+addx61538 add -1E-401 -1E-401 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+
+rounding: half_even
+-- exact zeros from zeros
+addx61540 add 0 0E-19 -> 0E-19
+addx61541 add -0 0E-19 -> 0E-19
+addx61542 add 0 -0E-19 -> 0E-19
+addx61543 add -0 -0E-19 -> -0E-19
+addx61544 add 0E-400 0E-19 -> 0E-398 Clamped
+addx61545 add -0E-400 0E-19 -> 0E-398 Clamped
+addx61546 add 0E-400 -0E-19 -> 0E-398 Clamped
+addx61547 add -0E-400 -0E-19 -> -0E-398 Clamped
+-- inexact zeros
+addx61551 add 1E-401 1E-400 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx61552 add -1E-401 1E-400 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx61553 add 1E-401 -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx61554 add -1E-401 -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+-- some exact zeros from non-zeros
+addx61555 add 1E-401 1E-401 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx61556 add -1E-401 1E-401 -> 0E-398 Clamped
+addx61557 add 1E-401 -1E-401 -> 0E-398 Clamped
+addx61558 add -1E-401 -1E-401 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+
+rounding: up
+-- exact zeros from zeros
+addx61560 add 0 0E-19 -> 0E-19
+addx61561 add -0 0E-19 -> 0E-19
+addx61562 add 0 -0E-19 -> 0E-19
+addx61563 add -0 -0E-19 -> -0E-19
+addx61564 add 0E-400 0E-19 -> 0E-398 Clamped
+addx61565 add -0E-400 0E-19 -> 0E-398 Clamped
+addx61566 add 0E-400 -0E-19 -> 0E-398 Clamped
+addx61567 add -0E-400 -0E-19 -> -0E-398 Clamped
+-- inexact zeros
+addx61571 add 1E-401 1E-400 -> 1E-398 Subnormal Inexact Rounded Underflow
+addx61572 add -1E-401 1E-400 -> 1E-398 Subnormal Inexact Rounded Underflow
+addx61573 add 1E-401 -1E-400 -> -1E-398 Subnormal Inexact Rounded Underflow
+addx61574 add -1E-401 -1E-400 -> -1E-398 Subnormal Inexact Rounded Underflow
+-- some exact zeros from non-zeros
+addx61575 add 1E-401 1E-401 -> 1E-398 Subnormal Inexact Rounded Underflow
+addx61576 add -1E-401 1E-401 -> 0E-398 Clamped
+addx61577 add 1E-401 -1E-401 -> 0E-398 Clamped
+addx61578 add -1E-401 -1E-401 -> -1E-398 Subnormal Inexact Rounded Underflow
+
+rounding: down
+-- exact zeros from zeros
+addx61580 add 0 0E-19 -> 0E-19
+addx61581 add -0 0E-19 -> 0E-19
+addx61582 add 0 -0E-19 -> 0E-19
+addx61583 add -0 -0E-19 -> -0E-19
+addx61584 add 0E-400 0E-19 -> 0E-398 Clamped
+addx61585 add -0E-400 0E-19 -> 0E-398 Clamped
+addx61586 add 0E-400 -0E-19 -> 0E-398 Clamped
+addx61587 add -0E-400 -0E-19 -> -0E-398 Clamped
+-- inexact zeros
+addx61591 add 1E-401 1E-400 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx61592 add -1E-401 1E-400 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx61593 add 1E-401 -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx61594 add -1E-401 -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+-- some exact zeros from non-zeros
+addx61595 add 1E-401 1E-401 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx61596 add -1E-401 1E-401 -> 0E-398 Clamped
+addx61597 add 1E-401 -1E-401 -> 0E-398 Clamped
+addx61598 add -1E-401 -1E-401 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+
+rounding: ceiling
+-- exact zeros from zeros
+addx61600 add 0 0E-19 -> 0E-19
+addx61601 add -0 0E-19 -> 0E-19
+addx61602 add 0 -0E-19 -> 0E-19
+addx61603 add -0 -0E-19 -> -0E-19
+addx61604 add 0E-400 0E-19 -> 0E-398 Clamped
+addx61605 add -0E-400 0E-19 -> 0E-398 Clamped
+addx61606 add 0E-400 -0E-19 -> 0E-398 Clamped
+addx61607 add -0E-400 -0E-19 -> -0E-398 Clamped
+-- inexact zeros
+addx61611 add 1E-401 1E-400 -> 1E-398 Subnormal Inexact Rounded Underflow
+addx61612 add -1E-401 1E-400 -> 1E-398 Subnormal Inexact Rounded Underflow
+addx61613 add 1E-401 -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx61614 add -1E-401 -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+-- some exact zeros from non-zeros
+addx61615 add 1E-401 1E-401 -> 1E-398 Subnormal Inexact Rounded Underflow
+addx61616 add -1E-401 1E-401 -> 0E-398 Clamped
+addx61617 add 1E-401 -1E-401 -> 0E-398 Clamped
+addx61618 add -1E-401 -1E-401 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
+
+-- and the extra-special ugly case; unusual minuses marked by -- *
+rounding: floor
+-- exact zeros from zeros
+addx61620 add 0 0E-19 -> 0E-19
+addx61621 add -0 0E-19 -> -0E-19 -- *
+addx61622 add 0 -0E-19 -> -0E-19 -- *
+addx61623 add -0 -0E-19 -> -0E-19
+addx61624 add 0E-400 0E-19 -> 0E-398 Clamped
+addx61625 add -0E-400 0E-19 -> -0E-398 Clamped -- *
+addx61626 add 0E-400 -0E-19 -> -0E-398 Clamped -- *
+addx61627 add -0E-400 -0E-19 -> -0E-398 Clamped
+-- inexact zeros
+addx61631 add 1E-401 1E-400 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx61632 add -1E-401 1E-400 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx61633 add 1E-401 -1E-400 -> -1E-398 Subnormal Inexact Rounded Underflow
+addx61634 add -1E-401 -1E-400 -> -1E-398 Subnormal Inexact Rounded Underflow
+-- some exact zeros from non-zeros
+addx61635 add 1E-401 1E-401 -> 0E-398 Subnormal Inexact Rounded Underflow Clamped
+addx61636 add -1E-401 1E-401 -> -0E-398 Clamped -- *
+addx61637 add 1E-401 -1E-401 -> -0E-398 Clamped -- *
+addx61638 add -1E-401 -1E-401 -> -1E-398 Subnormal Inexact Rounded Underflow
+
+-- Examples from SQL proposal (Krishna Kulkarni)
+addx61701 add 130E-2 120E-2 -> 2.50
+addx61702 add 130E-2 12E-1 -> 2.50
+addx61703 add 130E-2 1E0 -> 2.30
+addx61704 add 1E2 1E4 -> 1.01E+4
+addx61705 subtract 130E-2 120E-2 -> 0.10
+addx61706 subtract 130E-2 12E-1 -> 0.10
+addx61707 subtract 130E-2 1E0 -> 0.30
+addx61708 subtract 1E2 1E4 -> -9.9E+3
+
+-- Gappy coefficients; check residue handling even with full coefficient gap
+rounding: half_even
+
+addx62001 add 1234567890123456 1 -> 1234567890123457
+addx62002 add 1234567890123456 0.6 -> 1234567890123457 Inexact Rounded
+addx62003 add 1234567890123456 0.06 -> 1234567890123456 Inexact Rounded
+addx62004 add 1234567890123456 6E-3 -> 1234567890123456 Inexact Rounded
+addx62005 add 1234567890123456 6E-4 -> 1234567890123456 Inexact Rounded
+addx62006 add 1234567890123456 6E-5 -> 1234567890123456 Inexact Rounded
+addx62007 add 1234567890123456 6E-6 -> 1234567890123456 Inexact Rounded
+addx62008 add 1234567890123456 6E-7 -> 1234567890123456 Inexact Rounded
+addx62009 add 1234567890123456 6E-8 -> 1234567890123456 Inexact Rounded
+addx62010 add 1234567890123456 6E-9 -> 1234567890123456 Inexact Rounded
+addx62011 add 1234567890123456 6E-10 -> 1234567890123456 Inexact Rounded
+addx62012 add 1234567890123456 6E-11 -> 1234567890123456 Inexact Rounded
+addx62013 add 1234567890123456 6E-12 -> 1234567890123456 Inexact Rounded
+addx62014 add 1234567890123456 6E-13 -> 1234567890123456 Inexact Rounded
+addx62015 add 1234567890123456 6E-14 -> 1234567890123456 Inexact Rounded
+addx62016 add 1234567890123456 6E-15 -> 1234567890123456 Inexact Rounded
+addx62017 add 1234567890123456 6E-16 -> 1234567890123456 Inexact Rounded
+addx62018 add 1234567890123456 6E-17 -> 1234567890123456 Inexact Rounded
+addx62019 add 1234567890123456 6E-18 -> 1234567890123456 Inexact Rounded
+addx62020 add 1234567890123456 6E-19 -> 1234567890123456 Inexact Rounded
+addx62021 add 1234567890123456 6E-20 -> 1234567890123456 Inexact Rounded
+
+-- widening second argument at gap
+addx62030 add 12345678 1 -> 12345679
+addx62031 add 12345678 0.1 -> 12345678.1
+addx62032 add 12345678 0.12 -> 12345678.12
+addx62033 add 12345678 0.123 -> 12345678.123
+addx62034 add 12345678 0.1234 -> 12345678.1234
+addx62035 add 12345678 0.12345 -> 12345678.12345
+addx62036 add 12345678 0.123456 -> 12345678.123456
+addx62037 add 12345678 0.1234567 -> 12345678.1234567
+addx62038 add 12345678 0.12345678 -> 12345678.12345678
+addx62039 add 12345678 0.123456789 -> 12345678.12345679 Inexact Rounded
+addx62040 add 12345678 0.123456785 -> 12345678.12345678 Inexact Rounded
+addx62041 add 12345678 0.1234567850 -> 12345678.12345678 Inexact Rounded
+addx62042 add 12345678 0.1234567851 -> 12345678.12345679 Inexact Rounded
+addx62043 add 12345678 0.12345678501 -> 12345678.12345679 Inexact Rounded
+addx62044 add 12345678 0.123456785001 -> 12345678.12345679 Inexact Rounded
+addx62045 add 12345678 0.1234567850001 -> 12345678.12345679 Inexact Rounded
+addx62046 add 12345678 0.12345678500001 -> 12345678.12345679 Inexact Rounded
+addx62047 add 12345678 0.123456785000001 -> 12345678.12345679 Inexact Rounded
+addx62048 add 12345678 0.1234567850000001 -> 12345678.12345679 Inexact Rounded
+addx62049 add 12345678 0.1234567850000000 -> 12345678.12345678 Inexact Rounded
+-- 90123456
+rounding: half_even
+addx62050 add 12345678 0.0234567750000000 -> 12345678.02345678 Inexact Rounded
+addx62051 add 12345678 0.0034567750000000 -> 12345678.00345678 Inexact Rounded
+addx62052 add 12345678 0.0004567750000000 -> 12345678.00045678 Inexact Rounded
+addx62053 add 12345678 0.0000567750000000 -> 12345678.00005678 Inexact Rounded
+addx62054 add 12345678 0.0000067750000000 -> 12345678.00000678 Inexact Rounded
+addx62055 add 12345678 0.0000007750000000 -> 12345678.00000078 Inexact Rounded
+addx62056 add 12345678 0.0000000750000000 -> 12345678.00000008 Inexact Rounded
+addx62057 add 12345678 0.0000000050000000 -> 12345678.00000000 Inexact Rounded
+addx62060 add 12345678 0.0234567750000001 -> 12345678.02345678 Inexact Rounded
+addx62061 add 12345678 0.0034567750000001 -> 12345678.00345678 Inexact Rounded
+addx62062 add 12345678 0.0004567750000001 -> 12345678.00045678 Inexact Rounded
+addx62063 add 12345678 0.0000567750000001 -> 12345678.00005678 Inexact Rounded
+addx62064 add 12345678 0.0000067750000001 -> 12345678.00000678 Inexact Rounded
+addx62065 add 12345678 0.0000007750000001 -> 12345678.00000078 Inexact Rounded
+addx62066 add 12345678 0.0000000750000001 -> 12345678.00000008 Inexact Rounded
+addx62067 add 12345678 0.0000000050000001 -> 12345678.00000001 Inexact Rounded
+-- far-out residues (full coefficient gap is 16+15 digits)
+rounding: up
+addx62070 add 12345678 1E-8 -> 12345678.00000001
+addx62071 add 12345678 1E-9 -> 12345678.00000001 Inexact Rounded
+addx62072 add 12345678 1E-10 -> 12345678.00000001 Inexact Rounded
+addx62073 add 12345678 1E-11 -> 12345678.00000001 Inexact Rounded
+addx62074 add 12345678 1E-12 -> 12345678.00000001 Inexact Rounded
+addx62075 add 12345678 1E-13 -> 12345678.00000001 Inexact Rounded
+addx62076 add 12345678 1E-14 -> 12345678.00000001 Inexact Rounded
+addx62077 add 12345678 1E-15 -> 12345678.00000001 Inexact Rounded
+addx62078 add 12345678 1E-16 -> 12345678.00000001 Inexact Rounded
+addx62079 add 12345678 1E-17 -> 12345678.00000001 Inexact Rounded
+addx62080 add 12345678 1E-18 -> 12345678.00000001 Inexact Rounded
+addx62081 add 12345678 1E-19 -> 12345678.00000001 Inexact Rounded
+addx62082 add 12345678 1E-20 -> 12345678.00000001 Inexact Rounded
+addx62083 add 12345678 1E-25 -> 12345678.00000001 Inexact Rounded
+addx62084 add 12345678 1E-30 -> 12345678.00000001 Inexact Rounded
+addx62085 add 12345678 1E-31 -> 12345678.00000001 Inexact Rounded
+addx62086 add 12345678 1E-32 -> 12345678.00000001 Inexact Rounded
+addx62087 add 12345678 1E-33 -> 12345678.00000001 Inexact Rounded
+addx62088 add 12345678 1E-34 -> 12345678.00000001 Inexact Rounded
+addx62089 add 12345678 1E-35 -> 12345678.00000001 Inexact Rounded
+
+-- payload decapitate
+precision: 5
+addx62100 add 11 sNaN123456789 -> NaN56789 Invalid_operation
+addx62101 add -11 -sNaN123456789 -> -NaN56789 Invalid_operation
+addx62102 add 11 NaN123456789 -> NaN56789
+addx62103 add -11 -NaN123456789 -> -NaN56789
-- Null tests
addx9990 add 10 # -> NaN Invalid_operation
Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/base.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/base.decTest (original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/base.decTest Fri Sep 21 03:17:09 2007
@@ -1,6 +1,6 @@
------------------------------------------------------------------------
-- base.decTest -- base decimal <--> string conversions --
--- Copyright (c) IBM Corporation, 1981, 2003. All rights reserved. --
+-- Copyright (c) IBM Corporation, 1981, 2007. All rights reserved. --
------------------------------------------------------------------------
-- Please see the document "General Decimal Arithmetic Testcases" --
-- at http://www2.hursley.ibm.com/decimal for the description of --
@@ -17,7 +17,8 @@
-- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
-- mfc at uk.ibm.com --
------------------------------------------------------------------------
-version: 2.39
+version: 2.56
+extended: 1
-- This file tests base conversions from string to a decimal number
-- and back to a string (in either Scientific or Engineering form)
@@ -26,11 +27,10 @@
-- to conform to emax and precision settings (that is, numbers will
-- conform to rules and exponent will be in permitted range).
-precision: 15
+precision: 16
rounding: half_up
-maxExponent: 999999999
-minExponent: -999999999
-extended: 1
+maxExponent: 384
+minExponent: -383
basx001 toSci 0 -> 0
basx002 toSci 1 -> 1
@@ -73,41 +73,62 @@
-- String [many more examples are implicitly tested elsewhere]
-- strings without E cannot generate E in result
-basx100 toSci "12" -> '12'
-basx101 toSci "-76" -> '-76'
-basx102 toSci "12.76" -> '12.76'
-basx103 toSci "+12.76" -> '12.76'
-basx104 toSci "012.76" -> '12.76'
-basx105 toSci "+0.003" -> '0.003'
-basx106 toSci "17." -> '17'
-basx107 toSci ".5" -> '0.5'
-basx108 toSci "044" -> '44'
-basx109 toSci "0044" -> '44'
-basx110 toSci "0.0005" -> '0.0005'
-basx111 toSci "00.00005" -> '0.00005'
-basx112 toSci "0.000005" -> '0.000005'
-basx113 toSci "0.0000050" -> '0.0000050'
-basx114 toSci "0.0000005" -> '5E-7'
-basx115 toSci "0.00000005" -> '5E-8'
-basx116 toSci "12345678.543210" -> '12345678.543210'
-basx117 toSci "2345678.543210" -> '2345678.543210'
-basx118 toSci "345678.543210" -> '345678.543210'
-basx119 toSci "0345678.54321" -> '345678.54321'
-basx120 toSci "345678.5432" -> '345678.5432'
-basx121 toSci "+345678.5432" -> '345678.5432'
-basx122 toSci "+0345678.5432" -> '345678.5432'
-basx123 toSci "+00345678.5432" -> '345678.5432'
-basx124 toSci "-345678.5432" -> '-345678.5432'
-basx125 toSci "-0345678.5432" -> '-345678.5432'
-basx126 toSci "-00345678.5432" -> '-345678.5432'
+basx040 toSci "12" -> '12'
+basx041 toSci "-76" -> '-76'
+basx042 toSci "12.76" -> '12.76'
+basx043 toSci "+12.76" -> '12.76'
+basx044 toSci "012.76" -> '12.76'
+basx045 toSci "+0.003" -> '0.003'
+basx046 toSci "17." -> '17'
+basx047 toSci ".5" -> '0.5'
+basx048 toSci "044" -> '44'
+basx049 toSci "0044" -> '44'
+basx050 toSci "0.0005" -> '0.0005'
+basx051 toSci "00.00005" -> '0.00005'
+basx052 toSci "0.000005" -> '0.000005'
+basx053 toSci "0.0000050" -> '0.0000050'
+basx054 toSci "0.0000005" -> '5E-7'
+basx055 toSci "0.00000005" -> '5E-8'
+basx056 toSci "12345678.543210" -> '12345678.543210'
+basx057 toSci "2345678.543210" -> '2345678.543210'
+basx058 toSci "345678.543210" -> '345678.543210'
+basx059 toSci "0345678.54321" -> '345678.54321'
+basx060 toSci "345678.5432" -> '345678.5432'
+basx061 toSci "+345678.5432" -> '345678.5432'
+basx062 toSci "+0345678.5432" -> '345678.5432'
+basx063 toSci "+00345678.5432" -> '345678.5432'
+basx064 toSci "-345678.5432" -> '-345678.5432'
+basx065 toSci "-0345678.5432" -> '-345678.5432'
+basx066 toSci "-00345678.5432" -> '-345678.5432'
-- examples
-basx127 toSci "5E-6" -> '0.000005'
-basx128 toSci "50E-7" -> '0.0000050'
-basx129 toSci "5E-7" -> '5E-7'
-
+basx067 toSci "5E-6" -> '0.000005'
+basx068 toSci "50E-7" -> '0.0000050'
+basx069 toSci "5E-7" -> '5E-7'
-- [No exotics as no Unicode]
+-- rounded with dots in all (including edge) places
+basx071 toSci .1234567890123456123 -> 0.1234567890123456 Inexact Rounded
+basx072 toSci 1.234567890123456123 -> 1.234567890123456 Inexact Rounded
+basx073 toSci 12.34567890123456123 -> 12.34567890123456 Inexact Rounded
+basx074 toSci 123.4567890123456123 -> 123.4567890123456 Inexact Rounded
+basx075 toSci 1234.567890123456123 -> 1234.567890123456 Inexact Rounded
+basx076 toSci 12345.67890123456123 -> 12345.67890123456 Inexact Rounded
+basx077 toSci 123456.7890123456123 -> 123456.7890123456 Inexact Rounded
+basx078 toSci 1234567.890123456123 -> 1234567.890123456 Inexact Rounded
+basx079 toSci 12345678.90123456123 -> 12345678.90123456 Inexact Rounded
+basx080 toSci 123456789.0123456123 -> 123456789.0123456 Inexact Rounded
+basx081 toSci 1234567890.123456123 -> 1234567890.123456 Inexact Rounded
+basx082 toSci 12345678901.23456123 -> 12345678901.23456 Inexact Rounded
+basx083 toSci 123456789012.3456123 -> 123456789012.3456 Inexact Rounded
+basx084 toSci 1234567890123.456123 -> 1234567890123.456 Inexact Rounded
+basx085 toSci 12345678901234.56123 -> 12345678901234.56 Inexact Rounded
+basx086 toSci 123456789012345.6123 -> 123456789012345.6 Inexact Rounded
+basx087 toSci 1234567890123456.123 -> 1234567890123456 Inexact Rounded
+basx088 toSci 12345678901234561.23 -> 1.234567890123456E+16 Inexact Rounded
+basx089 toSci 123456789012345612.3 -> 1.234567890123456E+17 Inexact Rounded
+basx090 toSci 1234567890123456123. -> 1.234567890123456E+18 Inexact Rounded
+
-- Numbers with E
basx130 toSci "0.000E-1" -> '0.0000'
basx131 toSci "0.000E-2" -> '0.00000'
@@ -225,21 +246,6 @@
basx262 toSci "0.1265E+8" -> '1.265E+7'
basx263 toSci "0.1265E+20" -> '1.265E+19'
-basx270 toSci "0.09e999" -> '9E+997'
-basx271 toSci "0.9e999" -> '9E+998'
-basx272 toSci "9e999" -> '9E+999'
-basx273 toSci "9.9e999" -> '9.9E+999'
-basx274 toSci "9.99e999" -> '9.99E+999'
-basx275 toSci "9.99e-999" -> '9.99E-999'
-basx276 toSci "9.9e-999" -> '9.9E-999'
-basx277 toSci "9e-999" -> '9E-999'
-basx279 toSci "99e-999" -> '9.9E-998'
-basx280 toSci "999e-999" -> '9.99E-997'
-basx281 toSci '0.9e-998' -> '9E-999'
-basx282 toSci '0.09e-997' -> '9E-999'
-basx283 toSci '0.1e1000' -> '1E+999'
-basx284 toSci '10e-1000' -> '1.0E-999'
-
-- some more negative zeros [systematic tests below]
basx290 toSci "-0.000E-1" -> '-0.0000'
basx291 toSci "-0.000E-2" -> '-0.00000'
@@ -418,6 +424,22 @@
basx474 toSci 1000000009000 -> 1.00000001E+12 Rounded Inexact
basx475 toEng 1000000009000 -> 1.00000001E+12 Rounded Inexact
+-- all-nines rounding
+precision: 9
+rounding: half_up
+basx270 toSci 999999999 -> 999999999
+basx271 toSci 9999999990 -> 9.99999999E+9 Rounded
+basx272 toSci 9999999991 -> 9.99999999E+9 Rounded Inexact
+basx273 toSci 9999999992 -> 9.99999999E+9 Rounded Inexact
+basx274 toSci 9999999993 -> 9.99999999E+9 Rounded Inexact
+basx275 toSci 9999999994 -> 9.99999999E+9 Rounded Inexact
+basx276 toSci 9999999995 -> 1.00000000E+10 Rounded Inexact
+basx277 toSci 9999999996 -> 1.00000000E+10 Rounded Inexact
+basx278 toSci 9999999997 -> 1.00000000E+10 Rounded Inexact
+basx279 toSci 9999999998 -> 1.00000000E+10 Rounded Inexact
+basx280 toSci 9999999999 -> 1.00000000E+10 Rounded Inexact
+basx281 toSci 9999999999999999 -> 1.00000000E+16 Rounded Inexact
+
-- check rounding modes heeded
precision: 5
rounding: ceiling
@@ -425,11 +447,11 @@
bsrx402 toSci 1.234549 -> 1.2346 Rounded Inexact
bsrx403 toSci 1.234550 -> 1.2346 Rounded Inexact
bsrx404 toSci 1.234551 -> 1.2346 Rounded Inexact
-rounding: down
+rounding: up
bsrx405 toSci 1.23450 -> 1.2345 Rounded
-bsrx406 toSci 1.234549 -> 1.2345 Rounded Inexact
-bsrx407 toSci 1.234550 -> 1.2345 Rounded Inexact
-bsrx408 toSci 1.234551 -> 1.2345 Rounded Inexact
+bsrx406 toSci 1.234549 -> 1.2346 Rounded Inexact
+bsrx407 toSci 1.234550 -> 1.2346 Rounded Inexact
+bsrx408 toSci 1.234551 -> 1.2346 Rounded Inexact
rounding: floor
bsrx410 toSci 1.23450 -> 1.2345 Rounded
bsrx411 toSci 1.234549 -> 1.2345 Rounded Inexact
@@ -464,11 +486,11 @@
bsrx502 toSci -1.234549 -> -1.2345 Rounded Inexact
bsrx503 toSci -1.234550 -> -1.2345 Rounded Inexact
bsrx504 toSci -1.234551 -> -1.2345 Rounded Inexact
-rounding: down
+rounding: up
bsrx505 toSci -1.23450 -> -1.2345 Rounded
-bsrx506 toSci -1.234549 -> -1.2345 Rounded Inexact
-bsrx507 toSci -1.234550 -> -1.2345 Rounded Inexact
-bsrx508 toSci -1.234551 -> -1.2345 Rounded Inexact
+bsrx506 toSci -1.234549 -> -1.2346 Rounded Inexact
+bsrx507 toSci -1.234550 -> -1.2346 Rounded Inexact
+bsrx508 toSci -1.234551 -> -1.2346 Rounded Inexact
rounding: floor
bsrx510 toSci -1.23450 -> -1.2345 Rounded
bsrx511 toSci -1.234549 -> -1.2346 Rounded Inexact
@@ -498,6 +520,24 @@
bsrx534 toSci -1.234650 -> -1.2347 Rounded Inexact
bsrx535 toSci -1.234551 -> -1.2346 Rounded Inexact
+-- a few larger exponents
+maxExponent: 999999999
+minExponent: -999999999
+basx480 toSci "0.09e999" -> '9E+997'
+basx481 toSci "0.9e999" -> '9E+998'
+basx482 toSci "9e999" -> '9E+999'
+basx483 toSci "9.9e999" -> '9.9E+999'
+basx484 toSci "9.99e999" -> '9.99E+999'
+basx485 toSci "9.99e-999" -> '9.99E-999'
+basx486 toSci "9.9e-999" -> '9.9E-999'
+basx487 toSci "9e-999" -> '9E-999'
+basx489 toSci "99e-999" -> '9.9E-998'
+basx490 toSci "999e-999" -> '9.99E-997'
+basx491 toSci '0.9e-998' -> '9E-999'
+basx492 toSci '0.09e-997' -> '9E-999'
+basx493 toSci '0.1e1000' -> '1E+999'
+basx494 toSci '10e-1000' -> '1.0E-999'
+
rounding: half_up
precision: 9
@@ -580,32 +620,23 @@
basx574 toSci "xNaN" -> NaN Conversion_syntax
basx575 toSci "0sNaN" -> NaN Conversion_syntax
--- subnormals and overflows
-basx576 toSci '99e999999999' -> Infinity Overflow Inexact Rounded
-basx577 toSci '999e999999999' -> Infinity Overflow Inexact Rounded
-basx578 toSci '0.9e-999999999' -> 9E-1000000000 Subnormal
-basx579 toSci '0.09e-999999999' -> 9E-1000000001 Subnormal
-basx580 toSci '0.1e1000000000' -> 1E+999999999
-basx581 toSci '10e-1000000000' -> 1.0E-999999999
-basx582 toSci '0.9e9999999999' -> Infinity Overflow Inexact Rounded
-basx583 toSci '99e-9999999999' -> 0E-1000000007 Underflow Subnormal Inexact Rounded
-basx584 toSci '111e9999999999' -> Infinity Overflow Inexact Rounded
-basx585 toSci '1111e-9999999999' -> 0E-1000000007 Underflow Subnormal Inexact Rounded
-basx586 toSci '1111e-99999999999' -> 0E-1000000007 Underflow Subnormal Inexact Rounded
-basx587 toSci '7e1000000000' -> Infinity Overflow Inexact Rounded
--- negatives the same
-basx588 toSci '-99e999999999' -> -Infinity Overflow Inexact Rounded
-basx589 toSci '-999e999999999' -> -Infinity Overflow Inexact Rounded
-basx590 toSci '-0.9e-999999999' -> -9E-1000000000 Subnormal
-basx591 toSci '-0.09e-999999999' -> -9E-1000000001 Subnormal
-basx592 toSci '-0.1e1000000000' -> -1E+999999999
-basx593 toSci '-10e-1000000000' -> -1.0E-999999999
-basx594 toSci '-0.9e9999999999' -> -Infinity Overflow Inexact Rounded
-basx595 toSci '-99e-9999999999' -> -0E-1000000007 Underflow Subnormal Inexact Rounded
-basx596 toSci '-111e9999999999' -> -Infinity Overflow Inexact Rounded
-basx597 toSci '-1111e-9999999999' -> -0E-1000000007 Underflow Subnormal Inexact Rounded
-basx598 toSci '-1111e-99999999999' -> -0E-1000000007 Underflow Subnormal Inexact Rounded
-basx599 toSci '-7e1000000000' -> -Infinity Overflow Inexact Rounded
+-- some baddies with dots and Es and dots and specials
+basx576 toSci 'e+1' -> NaN Conversion_syntax
+basx577 toSci '.e+1' -> NaN Conversion_syntax
+basx578 toSci '+.e+1' -> NaN Conversion_syntax
+basx579 toSci '-.e+' -> NaN Conversion_syntax
+basx580 toSci '-.e' -> NaN Conversion_syntax
+basx581 toSci 'E+1' -> NaN Conversion_syntax
+basx582 toSci '.E+1' -> NaN Conversion_syntax
+basx583 toSci '+.E+1' -> NaN Conversion_syntax
+basx584 toSci '-.E+' -> NaN Conversion_syntax
+basx585 toSci '-.E' -> NaN Conversion_syntax
+
+basx586 toSci '.NaN' -> NaN Conversion_syntax
+basx587 toSci '-.NaN' -> NaN Conversion_syntax
+basx588 toSci '+.sNaN' -> NaN Conversion_syntax
+basx589 toSci '+.Inf' -> NaN Conversion_syntax
+basx590 toSci '.Infinity' -> NaN Conversion_syntax
-- Zeros
basx601 toSci 0.000000000 -> 0E-9
@@ -686,6 +717,17 @@
basx678 toSci 0.00E-8 -> 0E-10
basx679 toSci 0.00E-9 -> 0E-11
+basx680 toSci 000000. -> 0
+basx681 toSci 00000. -> 0
+basx682 toSci 0000. -> 0
+basx683 toSci 000. -> 0
+basx684 toSci 00. -> 0
+basx685 toSci 0. -> 0
+basx686 toSci +00000. -> 0
+basx687 toSci -00000. -> -0
+basx688 toSci +0. -> 0
+basx689 toSci -0. -> -0
+
-- Specials
precision: 4
basx700 toSci "NaN" -> NaN
@@ -868,6 +910,62 @@
basx878 toEng 0.00E-8 -> 0.0E-9
basx879 toEng 0.00E-9 -> 0.00E-9
+
+rounding: half_up
+precision: 9
+-- subnormals and overflows
+basx906 toSci '99e999999999' -> Infinity Overflow Inexact Rounded
+basx907 toSci '999e999999999' -> Infinity Overflow Inexact Rounded
+basx908 toSci '0.9e-999999999' -> 9E-1000000000 Subnormal
+basx909 toSci '0.09e-999999999' -> 9E-1000000001 Subnormal
+basx910 toSci '0.1e1000000000' -> 1E+999999999
+basx911 toSci '10e-1000000000' -> 1.0E-999999999
+basx912 toSci '0.9e9999999999' -> Infinity Overflow Inexact Rounded
+basx913 toSci '99e-9999999999' -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+basx914 toSci '111e9999999999' -> Infinity Overflow Inexact Rounded
+basx915 toSci '1111e-9999999999' -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+basx916 toSci '1111e-99999999999' -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+basx917 toSci '7e1000000000' -> Infinity Overflow Inexact Rounded
+-- negatives the same
+basx918 toSci '-99e999999999' -> -Infinity Overflow Inexact Rounded
+basx919 toSci '-999e999999999' -> -Infinity Overflow Inexact Rounded
+basx920 toSci '-0.9e-999999999' -> -9E-1000000000 Subnormal
+basx921 toSci '-0.09e-999999999' -> -9E-1000000001 Subnormal
+basx922 toSci '-0.1e1000000000' -> -1E+999999999
+basx923 toSci '-10e-1000000000' -> -1.0E-999999999
+basx924 toSci '-0.9e9999999999' -> -Infinity Overflow Inexact Rounded
+basx925 toSci '-99e-9999999999' -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+basx926 toSci '-111e9999999999' -> -Infinity Overflow Inexact Rounded
+basx927 toSci '-1111e-9999999999' -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+basx928 toSci '-1111e-99999999999' -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+basx929 toSci '-7e1000000000' -> -Infinity Overflow Inexact Rounded
+
+rounding: ceiling
+basx930 toSci '7e1000000000' -> Infinity Overflow Inexact Rounded
+basx931 toSci '-7e1000000000' -> -9.99999999E+999999999 Overflow Inexact Rounded
+rounding: up
+basx932 toSci '7e1000000000' -> Infinity Overflow Inexact Rounded
+basx933 toSci '-7e1000000000' -> -Infinity Overflow Inexact Rounded
+rounding: down
+basx934 toSci '7e1000000000' -> 9.99999999E+999999999 Overflow Inexact Rounded
+basx935 toSci '-7e1000000000' -> -9.99999999E+999999999 Overflow Inexact Rounded
+rounding: floor
+basx936 toSci '7e1000000000' -> 9.99999999E+999999999 Overflow Inexact Rounded
+basx937 toSci '-7e1000000000' -> -Infinity Overflow Inexact Rounded
+
+rounding: half_up
+basx938 toSci '7e1000000000' -> Infinity Overflow Inexact Rounded
+basx939 toSci '-7e1000000000' -> -Infinity Overflow Inexact Rounded
+rounding: half_even
+basx940 toSci '7e1000000000' -> Infinity Overflow Inexact Rounded
+basx941 toSci '-7e1000000000' -> -Infinity Overflow Inexact Rounded
+rounding: half_down
+basx942 toSci '7e1000000000' -> Infinity Overflow Inexact Rounded
+basx943 toSci '-7e1000000000' -> -Infinity Overflow Inexact Rounded
+
+rounding: half_even
+
+
-- Giga exponent initial tests
maxExponent: 999999999
minExponent: -999999999
@@ -987,8 +1085,8 @@
emax226 toSci 1E-8 -> 1E-8 Subnormal
emax227 toSci 1E-9 -> 1E-9 Subnormal
emax228 toSci 1E-10 -> 1E-10 Subnormal
-emax229 toSci 1E-11 -> 0E-10 Underflow Subnormal Inexact Rounded
-emax230 toSci 1E-12 -> 0E-10 Underflow Subnormal Inexact Rounded
+emax229 toSci 1E-11 -> 0E-10 Underflow Subnormal Inexact Rounded Clamped
+emax230 toSci 1E-12 -> 0E-10 Underflow Subnormal Inexact Rounded Clamped
maxexponent: 7
minexponent: -7
@@ -1003,7 +1101,7 @@
maxexponent: 9
minexponent: -9
-emax240 toSci 1E-21 -> 0E-17 Subnormal Underflow Inexact Rounded
+emax240 toSci 1E-21 -> 0E-17 Subnormal Underflow Inexact Rounded Clamped
emax241 toSci 1E-10 -> 1E-10 Subnormal
emax242 toSci 1E-9 -> 1E-9
emax243 toSci 1E-8 -> 1E-8
@@ -1015,7 +1113,7 @@
maxexponent: 10 -- boundary
minexponent: -10
-emax250 toSci 1E-21 -> 0E-18 Underflow Subnormal Inexact Rounded
+emax250 toSci 1E-21 -> 0E-18 Underflow Subnormal Inexact Rounded Clamped
emax251 toSci 1E-11 -> 1E-11 Subnormal
emax252 toSci 1E-10 -> 1E-10
emax253 toSci 1E-9 -> 1E-9
@@ -1025,7 +1123,7 @@
emax257 toSci 1E+10 -> 1E+10
emax258 toSci 1E+11 -> Infinity Overflow Inexact Rounded
-emax260 toSci 1.00E-21 -> 0E-18 Underflow Subnormal Inexact Rounded
+emax260 toSci 1.00E-21 -> 0E-18 Underflow Subnormal Inexact Rounded Clamped
emax261 toSci 1.00E-11 -> 1.00E-11 Subnormal
emax262 toSci 1.00E-10 -> 1.00E-10
emax263 toSci 1.00E-9 -> 1.00E-9
@@ -1034,7 +1132,7 @@
emax266 toSci 1.00E+9 -> 1.00E+9
emax267 toSci 1.00E+10 -> 1.00E+10
emax268 toSci 1.00E+11 -> Infinity Overflow Inexact Rounded
-emax270 toSci 9.99E-21 -> 0E-18 Underflow Subnormal Inexact Rounded
+emax270 toSci 9.99E-21 -> 0E-18 Underflow Subnormal Inexact Rounded Clamped
emax271 toSci 9.99E-11 -> 9.99E-11 Subnormal
emax272 toSci 9.99E-10 -> 9.99E-10
emax273 toSci 9.99E-9 -> 9.99E-9
@@ -1046,7 +1144,7 @@
maxexponent: 99
minexponent: -99
-emax280 toSci 1E-120 -> 0E-107 Underflow Subnormal Inexact Rounded
+emax280 toSci 1E-120 -> 0E-107 Underflow Subnormal Inexact Rounded Clamped
emax281 toSci 1E-100 -> 1E-100 Subnormal
emax282 toSci 1E-99 -> 1E-99
emax283 toSci 1E-98 -> 1E-98
@@ -1093,7 +1191,7 @@
maxexponent: 999999999
minexponent: -999999999
-emax347 toSci 1E-1000000008 -> 0E-1000000007 Underflow Subnormal Inexact Rounded
+emax347 toSci 1E-1000000008 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
emax348 toSci 1E-1000000007 -> 1E-1000000007 Subnormal
emax349 toSci 1E-1000000000 -> 1E-1000000000 Subnormal
emax350 toSci 1E-999999999 -> 1E-999999999
@@ -1103,7 +1201,7 @@
emax354 toSci 1.000E-999999999 -> 1.000E-999999999
emax355 toSci 1.000E+999999999 -> 1.000E+999999999
emax356 toSci 1.000E+1000000000 -> Infinity Overflow Inexact Rounded
-emax357 toSci 1.001E-1000000008 -> 0E-1000000007 Underflow Subnormal Inexact Rounded
+emax357 toSci 1.001E-1000000008 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
emax358 toSci 1.001E-1000000007 -> 1E-1000000007 Subnormal Inexact Rounded Underflow
emax359 toSci 1.001E-1000000000 -> 1.001E-1000000000 Subnormal
emax360 toSci 1.001E-999999999 -> 1.001E-999999999
@@ -1113,7 +1211,7 @@
emax364 toSci 9.000E-999999999 -> 9.000E-999999999
emax365 toSci 9.000E+999999999 -> 9.000E+999999999
emax366 toSci 9.000E+1000000000 -> Infinity Overflow Inexact Rounded
-emax367 toSci 9.999E-1000000009 -> 0E-1000000007 Underflow Subnormal Inexact Rounded
+emax367 toSci 9.999E-1000000009 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
emax368 toSci 9.999E-1000000008 -> 1E-1000000007 Underflow Subnormal Inexact Rounded
emax369 toSci 9.999E-1000000007 -> 1.0E-1000000006 Underflow Subnormal Inexact Rounded
emax370 toSci 9.999E-1000000000 -> 9.999E-1000000000 Subnormal
@@ -1129,11 +1227,11 @@
emax379 toSci -1.000E-999999999 -> -1.000E-999999999
emax380 toSci -1.000E+999999999 -> -1.000E+999999999
emax381 toSci -1.000E+1000000000 -> -Infinity Overflow Inexact Rounded
-emax382 toSci -1.001E-1000000008 -> -0E-1000000007 Underflow Subnormal Inexact Rounded
+emax382 toSci -1.001E-1000000008 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
emax383 toSci -1.001E-999999999 -> -1.001E-999999999
emax384 toSci -1.001E+999999999 -> -1.001E+999999999
emax385 toSci -1.001E+1000000000 -> -Infinity Overflow Inexact Rounded
-emax386 toSci -9.000E-1000000123 -> -0E-1000000007 Underflow Subnormal Inexact Rounded
+emax386 toSci -9.000E-1000000123 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
emax387 toSci -9.000E-999999999 -> -9.000E-999999999
emax388 toSci -9.000E+999999999 -> -9.000E+999999999
emax389 toSci -9.000E+1000000000 -> -Infinity Overflow Inexact Rounded
@@ -1168,11 +1266,11 @@
emax417 toSci 0.000250E-999 -> 2E-1003 Underflow Subnormal Inexact Rounded
emax418 toSci 0.000251E-999 -> 3E-1003 Underflow Subnormal Inexact Rounded
emax419 toSci 0.00009E-999 -> 1E-1003 Underflow Subnormal Inexact Rounded
-emax420 toSci 0.00005E-999 -> 0E-1003 Underflow Subnormal Inexact Rounded
-emax421 toSci 0.00003E-999 -> 0E-1003 Underflow Subnormal Inexact Rounded
-emax422 toSci 0.000009E-999 -> 0E-1003 Underflow Subnormal Inexact Rounded
-emax423 toSci 0.000005E-999 -> 0E-1003 Underflow Subnormal Inexact Rounded
-emax424 toSci 0.000003E-999 -> 0E-1003 Underflow Subnormal Inexact Rounded
+emax420 toSci 0.00005E-999 -> 0E-1003 Underflow Subnormal Inexact Rounded Clamped
+emax421 toSci 0.00003E-999 -> 0E-1003 Underflow Subnormal Inexact Rounded Clamped
+emax422 toSci 0.000009E-999 -> 0E-1003 Underflow Subnormal Inexact Rounded Clamped
+emax423 toSci 0.000005E-999 -> 0E-1003 Underflow Subnormal Inexact Rounded Clamped
+emax424 toSci 0.000003E-999 -> 0E-1003 Underflow Subnormal Inexact Rounded Clamped
emax425 toSci 0.001049E-999 -> 1.0E-1002 Underflow Subnormal Inexact Rounded
emax426 toSci 0.001050E-999 -> 1.0E-1002 Underflow Subnormal Inexact Rounded
@@ -1223,9 +1321,9 @@
emax473 toSci 0.0099999E-999 -> 1.00E-1001 Underflow Subnormal Inexact Rounded
emax474 toSci 0.00099999E-999 -> 1.0E-1002 Underflow Subnormal Inexact Rounded
emax475 toSci 0.000099999E-999 -> 1E-1003 Underflow Subnormal Inexact Rounded
-emax476 toSci 0.0000099999E-999 -> 0E-1003 Underflow Subnormal Inexact Rounded
-emax477 toSci 0.00000099999E-999 -> 0E-1003 Underflow Subnormal Inexact Rounded
-emax478 toSci 0.000000099999E-999 -> 0E-1003 Underflow Subnormal Inexact Rounded
+emax476 toSci 0.0000099999E-999 -> 0E-1003 Underflow Subnormal Inexact Rounded Clamped
+emax477 toSci 0.00000099999E-999 -> 0E-1003 Underflow Subnormal Inexact Rounded Clamped
+emax478 toSci 0.000000099999E-999 -> 0E-1003 Underflow Subnormal Inexact Rounded Clamped
-- Exponents with insignificant leading zeros
precision: 16
@@ -1248,9 +1346,9 @@
basx1021 tosci 1e+2147483649 -> Infinity Overflow Inexact Rounded
basx1022 tosci 1e+2147483648 -> Infinity Overflow Inexact Rounded
basx1023 tosci 1e+2147483647 -> Infinity Overflow Inexact Rounded
-basx1024 tosci 1e-2147483647 -> 0E-1000000014 Underflow Subnormal Inexact Rounded
-basx1025 tosci 1e-2147483648 -> 0E-1000000014 Underflow Subnormal Inexact Rounded
-basx1026 tosci 1e-2147483649 -> 0E-1000000014 Underflow Subnormal Inexact Rounded
+basx1024 tosci 1e-2147483647 -> 0E-1000000014 Underflow Subnormal Inexact Rounded Clamped
+basx1025 tosci 1e-2147483648 -> 0E-1000000014 Underflow Subnormal Inexact Rounded Clamped
+basx1026 tosci 1e-2147483649 -> 0E-1000000014 Underflow Subnormal Inexact Rounded Clamped
-- same unbalanced
precision: 7
maxExponent: 96
@@ -1258,9 +1356,9 @@
basx1031 tosci 1e+2147483649 -> Infinity Overflow Inexact Rounded
basx1032 tosci 1e+2147483648 -> Infinity Overflow Inexact Rounded
basx1033 tosci 1e+2147483647 -> Infinity Overflow Inexact Rounded
-basx1034 tosci 1e-2147483647 -> 0E-101 Underflow Subnormal Inexact Rounded
-basx1035 tosci 1e-2147483648 -> 0E-101 Underflow Subnormal Inexact Rounded
-basx1036 tosci 1e-2147483649 -> 0E-101 Underflow Subnormal Inexact Rounded
+basx1034 tosci 1e-2147483647 -> 0E-101 Underflow Subnormal Inexact Rounded Clamped
+basx1035 tosci 1e-2147483648 -> 0E-101 Underflow Subnormal Inexact Rounded Clamped
+basx1036 tosci 1e-2147483649 -> 0E-101 Underflow Subnormal Inexact Rounded Clamped
-- check for double-rounded subnormals
precision: 5
@@ -1270,3 +1368,44 @@
basx1042 toSci 1.52445E-80 -> 1.524E-80 Inexact Rounded Subnormal Underflow
basx1043 toSci 1.52446E-80 -> 1.524E-80 Inexact Rounded Subnormal Underflow
+-- clamped zeros [see also clamp.decTest]
+precision: 34
+maxExponent: 6144
+minExponent: -6143
+
+basx1061 apply 0e+10000 -> 0E+6144 Clamped
+basx1062 apply 0e-10000 -> 0E-6176 Clamped
+basx1063 apply -0e+10000 -> -0E+6144 Clamped
+basx1064 apply -0e-10000 -> -0E-6176 Clamped
+
+precision: 16
+maxExponent: 384
+minExponent: -383
+
+basx1065 apply 0e+10000 -> 0E+384 Clamped
+basx1066 apply 0e-10000 -> 0E-398 Clamped
+basx1067 apply -0e+10000 -> -0E+384 Clamped
+basx1068 apply -0e-10000 -> -0E-398 Clamped
+
+-- same with IEEE clamping
+clamp: 1
+
+precision: 34
+maxExponent: 6144
+minExponent: -6143
+
+basx1071 apply 0e+10000 -> 0E+6111 Clamped
+basx1072 apply 0e-10000 -> 0E-6176 Clamped
+basx1073 apply -0e+10000 -> -0E+6111 Clamped
+basx1074 apply -0e-10000 -> -0E-6176 Clamped
+
+precision: 16
+maxExponent: 384
+minExponent: -383
+
+basx1075 apply 0e+10000 -> 0E+369 Clamped
+basx1076 apply 0e-10000 -> 0E-398 Clamped
+basx1077 apply -0e+10000 -> -0E+369 Clamped
+basx1078 apply -0e-10000 -> -0E-398 Clamped
+
+
Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/clamp.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/clamp.decTest (original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/clamp.decTest Fri Sep 21 03:17:09 2007
@@ -1,6 +1,6 @@
------------------------------------------------------------------------
-- clamp.decTest -- clamped exponent tests (format-independent) --
--- Copyright (c) IBM Corporation, 2000, 2003. All rights reserved. --
+-- Copyright (c) IBM Corporation, 2000, 2007. All rights reserved. --
------------------------------------------------------------------------
-- Please see the document "General Decimal Arithmetic Testcases" --
-- at http://www2.hursley.ibm.com/decimal for the description of --
@@ -17,7 +17,7 @@
-- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
-- mfc at uk.ibm.com --
------------------------------------------------------------------------
-version: 2.39
+version: 2.56
-- This set of tests uses the same limits as the 8-byte concrete
-- representation, but applies clamping without using format-specific
@@ -73,10 +73,10 @@
clam093 apply 1.00000000001e-398 -> #0000000000000001 Subnormal Underflow Inexact Rounded
clam094 apply 1.00000000000001e-398 -> #0000000000000001 Subnormal Underflow Inexact Rounded
clam095 apply 1.000000000000001e-398 -> #0000000000000001 Subnormal Underflow Inexact Rounded
-clam096 apply 0.1e-398 -> #0000000000000000 Subnormal Underflow Inexact Rounded
-clam097 apply 0.00000000001e-398 -> #0000000000000000 Subnormal Underflow Inexact Rounded
-clam098 apply 0.00000000000001e-398 -> #0000000000000000 Subnormal Underflow Inexact Rounded
-clam099 apply 0.000000000000001e-398 -> #0000000000000000 Subnormal Underflow Inexact Rounded
+clam096 apply 0.1e-398 -> #0000000000000000 Subnormal Underflow Inexact Rounded Clamped
+clam097 apply 0.00000000001e-398 -> #0000000000000000 Subnormal Underflow Inexact Rounded Clamped
+clam098 apply 0.00000000000001e-398 -> #0000000000000000 Subnormal Underflow Inexact Rounded Clamped
+clam099 apply 0.000000000000001e-398 -> #0000000000000000 Subnormal Underflow Inexact Rounded Clamped
-- Same again, negatives
-- Nmax and similar
@@ -112,10 +112,10 @@
clam193 apply -1.00000000001e-398 -> #8000000000000001 Subnormal Underflow Inexact Rounded
clam194 apply -1.00000000000001e-398 -> #8000000000000001 Subnormal Underflow Inexact Rounded
clam195 apply -1.000000000000001e-398 -> #8000000000000001 Subnormal Underflow Inexact Rounded
-clam196 apply -0.1e-398 -> #8000000000000000 Subnormal Underflow Inexact Rounded
-clam197 apply -0.00000000001e-398 -> #8000000000000000 Subnormal Underflow Inexact Rounded
-clam198 apply -0.00000000000001e-398 -> #8000000000000000 Subnormal Underflow Inexact Rounded
-clam199 apply -0.000000000000001e-398 -> #8000000000000000 Subnormal Underflow Inexact Rounded
+clam196 apply -0.1e-398 -> #8000000000000000 Subnormal Underflow Inexact Rounded Clamped
+clam197 apply -0.00000000001e-398 -> #8000000000000000 Subnormal Underflow Inexact Rounded Clamped
+clam198 apply -0.00000000000001e-398 -> #8000000000000000 Subnormal Underflow Inexact Rounded Clamped
+clam199 apply -0.000000000000001e-398 -> #8000000000000000 Subnormal Underflow Inexact Rounded Clamped
-- zeros
clam401 apply 0E-500 -> 0E-398 Clamped
@@ -184,6 +184,20 @@
clam671 apply 9E+369 -> 9E+369
clam673 apply 9E+368 -> 9E+368
+-- subnormals clamped to 0-Etiny
+precision: 16
+maxExponent: 384
+minExponent: -383
+clam681 apply 7E-398 -> 7E-398 Subnormal
+clam682 apply 0E-398 -> 0E-398
+clam683 apply 7E-399 -> 1E-398 Subnormal Underflow Inexact Rounded
+clam684 apply 4E-399 -> 0E-398 Clamped Subnormal Underflow Inexact Rounded
+clam685 apply 7E-400 -> 0E-398 Clamped Subnormal Underflow Inexact Rounded
+clam686 apply 7E-401 -> 0E-398 Clamped Subnormal Underflow Inexact Rounded
+clam687 apply 0E-399 -> 0E-398 Clamped
+clam688 apply 0E-400 -> 0E-398 Clamped
+clam689 apply 0E-401 -> 0E-398 Clamped
+
-- example from documentation
precision: 7
rounding: half_even
Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/compare.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/compare.decTest (original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/compare.decTest Fri Sep 21 03:17:09 2007
@@ -1,6 +1,6 @@
------------------------------------------------------------------------
--- compare.decTest -- decimal comparison --
--- Copyright (c) IBM Corporation, 1981, 2003. All rights reserved. --
+-- compare.decTest -- decimal comparison that allows quiet NaNs --
+-- Copyright (c) IBM Corporation, 1981, 2007. All rights reserved. --
------------------------------------------------------------------------
-- Please see the document "General Decimal Arithmetic Testcases" --
-- at http://www2.hursley.ibm.com/decimal for the description of --
@@ -17,11 +17,11 @@
-- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
-- mfc at uk.ibm.com --
------------------------------------------------------------------------
-version: 2.39
+version: 2.56
-- Note that we cannot assume add/subtract tests cover paths adequately,
-- here, because the code might be quite different (comparison cannot
--- overflow or underflow, so actual subtractions are not necesary).
+-- overflow or underflow, so actual subtractions are not necessary).
extended: 1
@@ -112,10 +112,10 @@
-- now some cases which might overflow if subtract were used
maxexponent: 999999999
minexponent: -999999999
-comx090 compare 9.99999999E+999999999 9.99999999E+999999999 -> 0
-comx091 compare -9.99999999E+999999999 9.99999999E+999999999 -> -1
-comx092 compare 9.99999999E+999999999 -9.99999999E+999999999 -> 1
-comx093 compare -9.99999999E+999999999 -9.99999999E+999999999 -> 0
+comx095 compare 9.99999999E+999999999 9.99999999E+999999999 -> 0
+comx096 compare -9.99999999E+999999999 9.99999999E+999999999 -> -1
+comx097 compare 9.99999999E+999999999 -9.99999999E+999999999 -> 1
+comx098 compare -9.99999999E+999999999 -9.99999999E+999999999 -> 0
-- some differing length/exponent cases
comx100 compare 7.0 7.0 -> 0
@@ -265,6 +265,21 @@
comx449 compare -8 -.9E+1 -> 1
comx450 compare -8 -90E-1 -> 1
+-- misalignment traps for little-endian
+comx451 compare 1.0 0.1 -> 1
+comx452 compare 0.1 1.0 -> -1
+comx453 compare 10.0 0.1 -> 1
+comx454 compare 0.1 10.0 -> -1
+comx455 compare 100 1.0 -> 1
+comx456 compare 1.0 100 -> -1
+comx457 compare 1000 10.0 -> 1
+comx458 compare 10.0 1000 -> -1
+comx459 compare 10000 100.0 -> 1
+comx460 compare 100.0 10000 -> -1
+comx461 compare 100000 1000.0 -> 1
+comx462 compare 1000.0 100000 -> -1
+comx463 compare 1000000 10000.0 -> 1
+comx464 compare 10000.0 1000000 -> -1
-- testcases that subtract to lots of zeros at boundaries [pgr]
precision: 40
@@ -362,7 +377,7 @@
comx569 compare 1E+13 1 -> 1
comx570 compare 1E+14 1 -> 1
comx571 compare 1E+15 1 -> 1
--- similar with an useful coefficient, one side only
+-- similar with a useful coefficient, one side only
comx580 compare 0.000000987654321 1E-15 -> 1
comx581 compare 0.000000987654321 1E-14 -> 1
comx582 compare 0.000000987654321 1E-13 -> 1
@@ -712,6 +727,32 @@
comx907 compare -1e-777777777 1e-411111111 -> -1
comx908 compare -1e-777777777 -1e-411111111 -> 1
+-- spread zeros
+comx910 compare 0E-383 0 -> 0
+comx911 compare 0E-383 -0 -> 0
+comx912 compare -0E-383 0 -> 0
+comx913 compare -0E-383 -0 -> 0
+comx914 compare 0E-383 0E+384 -> 0
+comx915 compare 0E-383 -0E+384 -> 0
+comx916 compare -0E-383 0E+384 -> 0
+comx917 compare -0E-383 -0E+384 -> 0
+comx918 compare 0 0E+384 -> 0
+comx919 compare 0 -0E+384 -> 0
+comx920 compare -0 0E+384 -> 0
+comx921 compare -0 -0E+384 -> 0
+comx930 compare 0E+384 0 -> 0
+comx931 compare 0E+384 -0 -> 0
+comx932 compare -0E+384 0 -> 0
+comx933 compare -0E+384 -0 -> 0
+comx934 compare 0E+384 0E-383 -> 0
+comx935 compare 0E+384 -0E-383 -> 0
+comx936 compare -0E+384 0E-383 -> 0
+comx937 compare -0E+384 -0E-383 -> 0
+comx938 compare 0 0E-383 -> 0
+comx939 compare 0 -0E-383 -> 0
+comx940 compare -0 0E-383 -> 0
+comx941 compare -0 -0E-383 -> 0
+
-- Null tests
comx990 compare 10 # -> NaN Invalid_operation
comx991 compare # 10 -> NaN Invalid_operation
Deleted: /python/branches/py3k-importlib/Lib/test/decimaltestdata/decimal128.decTest
==============================================================================
--- /python/branches/py3k-importlib/Lib/test/decimaltestdata/decimal128.decTest Fri Sep 21 03:17:09 2007
+++ (empty file)
@@ -1,441 +0,0 @@
-------------------------------------------------------------------------
--- decimal128.decTest -- decimal sixteen-byte format testcases --
--- Copyright (c) IBM Corporation, 2000, 2003. All rights reserved. --
-------------------------------------------------------------------------
--- Please see the document "General Decimal Arithmetic Testcases" --
--- at http://www2.hursley.ibm.com/decimal for the description of --
--- these testcases. --
--- --
--- These testcases are experimental ('beta' versions), and they --
--- may contain errors. They are offered on an as-is basis. In --
--- particular, achieving the same results as the tests here is not --
--- a guarantee that an implementation complies with any Standard --
--- or specification. The tests are not exhaustive. --
--- --
--- Please send comments, suggestions, and corrections to the author: --
--- Mike Cowlishaw, IBM Fellow --
--- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
--- mfc at uk.ibm.com --
-------------------------------------------------------------------------
-version: 2.39
-
--- This set of tests is for the sixteen-byte concrete representation.
--- Its characteristics are:
---
--- 1 bit sign
--- 5 bits combination field
--- 12 bits exponent continuation
--- 110 bits coefficient continuation
---
--- Total exponent length 14 bits
--- Total coefficient length 114 bits (34 digits)
---
--- Elimit = 12287 (maximum encoded exponent)
--- Emax = 6144 (largest exponent value)
--- Emin = -6143 (smallest exponent value)
--- bias = 6176 (subtracted from encoded exponent) = -Etiny
-
-extended: 1
-precision: 34
-rounding: half_up
-maxExponent: 6144
-minExponent: -6143
-
--- General testcases
--- (mostly derived from the Strawman 4 document and examples)
-decg001 apply #A20780000000000000000000000003D0 -> -7.50
-decg002 apply -7.50 -> #A20780000000000000000000000003D0
-
--- Normality
-decf010 apply 1234567890123456789012345678901234 -> #2608134b9c1e28e56f3c127177823534
-decf011 apply 1234567890123456789012345678901234.0 -> #2608134b9c1e28e56f3c127177823534 Rounded
-decf012 apply 1234567890123456789012345678901234.1 -> #2608134b9c1e28e56f3c127177823534 Rounded Inexact
-decf013 apply -1234567890123456789012345678901234 -> #a608134b9c1e28e56f3c127177823534
-decf014 apply -1234567890123456789012345678901234.0 -> #a608134b9c1e28e56f3c127177823534 Rounded
-decf015 apply -1234567890123456789012345678901234.1 -> #a608134b9c1e28e56f3c127177823534 Rounded Inexact
-
-
--- Nmax and similar
-decf022 apply 9.999999999999999999999999999999999E+6144 -> #77ffcff3fcff3fcff3fcff3fcff3fcff
-decf023 apply #77ffcff3fcff3fcff3fcff3fcff3fcff -> 9.999999999999999999999999999999999E+6144
-decf024 apply 1.234567890123456789012345678901234E+6144 -> #47ffd34b9c1e28e56f3c127177823534
-decf025 apply #47ffd34b9c1e28e56f3c127177823534 -> 1.234567890123456789012345678901234E+6144
--- fold-downs (more below)
-decf030 apply 1.23E+6144 -> #47ffd300000000000000000000000000 Clamped
-decf031 apply #47ffd300000000000000000000000000 -> 1.230000000000000000000000000000000E+6144
-decf032 apply 1E+6144 -> #47ffc000000000000000000000000000 Clamped
-decf033 apply #47ffc000000000000000000000000000 -> 1.000000000000000000000000000000000E+6144
-
--- overflows
-maxExponent: 9999 -- set high so conversion causes the overflow
-minExponent: -9999
-decf040 apply 10E+6144 -> #78000000000000000000000000000000 Overflow Rounded Inexact
-decf041 apply 1.000000000000000E+6145 -> #78000000000000000000000000000000 Overflow Rounded Inexact
-maxExponent: 6144
-minExponent: -6143
-
-decf051 apply 12345 -> #220800000000000000000000000049c5
-decf052 apply #220800000000000000000000000049c5 -> 12345
-decf053 apply 1234 -> #22080000000000000000000000000534
-decf054 apply #22080000000000000000000000000534 -> 1234
-decf055 apply 123 -> #220800000000000000000000000000a3
-decf056 apply #220800000000000000000000000000a3 -> 123
-decf057 apply 12 -> #22080000000000000000000000000012
-decf058 apply #22080000000000000000000000000012 -> 12
-decf059 apply 1 -> #22080000000000000000000000000001
-decf060 apply #22080000000000000000000000000001 -> 1
-decf061 apply 1.23 -> #220780000000000000000000000000a3
-decf062 apply #220780000000000000000000000000a3 -> 1.23
-decf063 apply 123.45 -> #220780000000000000000000000049c5
-decf064 apply #220780000000000000000000000049c5 -> 123.45
-
--- Nmin and below
-decf071 apply 1E-6143 -> #00084000000000000000000000000001
-decf072 apply #00084000000000000000000000000001 -> 1E-6143
-decf073 apply 1.000000000000000000000000000000000E-6143 -> #04000000000000000000000000000000
-decf074 apply #04000000000000000000000000000000 -> 1.000000000000000000000000000000000E-6143
-decf075 apply 1.000000000000000000000000000000001E-6143 -> #04000000000000000000000000000001
-decf076 apply #04000000000000000000000000000001 -> 1.000000000000000000000000000000001E-6143
-
-decf077 apply 0.100000000000000000000000000000000E-6143 -> #00000800000000000000000000000000 Subnormal
-decf078 apply #00000800000000000000000000000000 -> 1.00000000000000000000000000000000E-6144 Subnormal
-decf079 apply 0.000000000000000000000000000000010E-6143 -> #00000000000000000000000000000010 Subnormal
-decf080 apply #00000000000000000000000000000010 -> 1.0E-6175 Subnormal
-decf081 apply 0.00000000000000000000000000000001E-6143 -> #00004000000000000000000000000001 Subnormal
-decf082 apply #00004000000000000000000000000001 -> 1E-6175 Subnormal
-decf083 apply 0.000000000000000000000000000000001E-6143 -> #00000000000000000000000000000001 Subnormal
-decf084 apply #00000000000000000000000000000001 -> 1E-6176 Subnormal
-
--- underflows
-decf090 apply 1e-6176 -> #00000000000000000000000000000001 Subnormal
-decf091 apply 1.9e-6176 -> #00000000000000000000000000000002 Subnormal Underflow Inexact Rounded
-decf092 apply 1.1e-6176 -> #00000000000000000000000000000001 Subnormal Underflow Inexact Rounded
-decf093 apply 1.00000000001e-6176 -> #00000000000000000000000000000001 Subnormal Underflow Inexact Rounded
-decf094 apply 1.00000000000001e-6176 -> #00000000000000000000000000000001 Subnormal Underflow Inexact Rounded
-decf095 apply 1.000000000000001e-6176 -> #00000000000000000000000000000001 Subnormal Underflow Inexact Rounded
-decf096 apply 0.1e-6176 -> #00000000000000000000000000000000 Subnormal Underflow Inexact Rounded
-decf097 apply 0.00000000001e-6176 -> #00000000000000000000000000000000 Subnormal Underflow Inexact Rounded
-decf098 apply 0.00000000000001e-6176 -> #00000000000000000000000000000000 Subnormal Underflow Inexact Rounded
-decf099 apply 0.000000000000001e-6176 -> #00000000000000000000000000000000 Subnormal Underflow Inexact Rounded
-decf100 apply 999999999999999999999999999999999e-6176 -> #00000ff3fcff3fcff3fcff3fcff3fcff Subnormal
-
--- same again, negatives
--- Nmax and similar
-decf122 apply -9.999999999999999999999999999999999E+6144 -> #f7ffcff3fcff3fcff3fcff3fcff3fcff
-decf123 apply #f7ffcff3fcff3fcff3fcff3fcff3fcff -> -9.999999999999999999999999999999999E+6144
-decf124 apply -1.234567890123456789012345678901234E+6144 -> #c7ffd34b9c1e28e56f3c127177823534
-decf125 apply #c7ffd34b9c1e28e56f3c127177823534 -> -1.234567890123456789012345678901234E+6144
--- fold-downs (more below)
-decf130 apply -1.23E+6144 -> #c7ffd300000000000000000000000000 Clamped
-decf131 apply #c7ffd300000000000000000000000000 -> -1.230000000000000000000000000000000E+6144
-decf132 apply -1E+6144 -> #c7ffc000000000000000000000000000 Clamped
-decf133 apply #c7ffc000000000000000000000000000 -> -1.000000000000000000000000000000000E+6144
-
--- overflows
-maxExponent: 9999 -- set high so conversion causes the overflow
-minExponent: -9999
-decf140 apply -10E+6144 -> #f8000000000000000000000000000000 Overflow Rounded Inexact
-decf141 apply -1.000000000000000E+6145 -> #f8000000000000000000000000000000 Overflow Rounded Inexact
-maxExponent: 6144
-minExponent: -6143
-
-decf151 apply -12345 -> #a20800000000000000000000000049c5
-decf152 apply #a20800000000000000000000000049c5 -> -12345
-decf153 apply -1234 -> #a2080000000000000000000000000534
-decf154 apply #a2080000000000000000000000000534 -> -1234
-decf155 apply -123 -> #a20800000000000000000000000000a3
-decf156 apply #a20800000000000000000000000000a3 -> -123
-decf157 apply -12 -> #a2080000000000000000000000000012
-decf158 apply #a2080000000000000000000000000012 -> -12
-decf159 apply -1 -> #a2080000000000000000000000000001
-decf160 apply #a2080000000000000000000000000001 -> -1
-decf161 apply -1.23 -> #a20780000000000000000000000000a3
-decf162 apply #a20780000000000000000000000000a3 -> -1.23
-decf163 apply -123.45 -> #a20780000000000000000000000049c5
-decf164 apply #a20780000000000000000000000049c5 -> -123.45
-
--- Nmin and below
-decf171 apply -1E-6143 -> #80084000000000000000000000000001
-decf172 apply #80084000000000000000000000000001 -> -1E-6143
-decf173 apply -1.000000000000000000000000000000000E-6143 -> #84000000000000000000000000000000
-decf174 apply #84000000000000000000000000000000 -> -1.000000000000000000000000000000000E-6143
-decf175 apply -1.000000000000000000000000000000001E-6143 -> #84000000000000000000000000000001
-decf176 apply #84000000000000000000000000000001 -> -1.000000000000000000000000000000001E-6143
-
-decf177 apply -0.100000000000000000000000000000000E-6143 -> #80000800000000000000000000000000 Subnormal
-decf178 apply #80000800000000000000000000000000 -> -1.00000000000000000000000000000000E-6144 Subnormal
-decf179 apply -0.000000000000000000000000000000010E-6143 -> #80000000000000000000000000000010 Subnormal
-decf180 apply #80000000000000000000000000000010 -> -1.0E-6175 Subnormal
-decf181 apply -0.00000000000000000000000000000001E-6143 -> #80004000000000000000000000000001 Subnormal
-decf182 apply #80004000000000000000000000000001 -> -1E-6175 Subnormal
-decf183 apply -0.000000000000000000000000000000001E-6143 -> #80000000000000000000000000000001 Subnormal
-decf184 apply #80000000000000000000000000000001 -> -1E-6176 Subnormal
-
--- underflows
-decf190 apply -1e-6176 -> #80000000000000000000000000000001 Subnormal
-decf191 apply -1.9e-6176 -> #80000000000000000000000000000002 Subnormal Underflow Inexact Rounded
-decf192 apply -1.1e-6176 -> #80000000000000000000000000000001 Subnormal Underflow Inexact Rounded
-decf193 apply -1.00000000001e-6176 -> #80000000000000000000000000000001 Subnormal Underflow Inexact Rounded
-decf194 apply -1.00000000000001e-6176 -> #80000000000000000000000000000001 Subnormal Underflow Inexact Rounded
-decf195 apply -1.000000000000001e-6176 -> #80000000000000000000000000000001 Subnormal Underflow Inexact Rounded
-decf196 apply -0.1e-6176 -> #80000000000000000000000000000000 Subnormal Underflow Inexact Rounded
-decf197 apply -0.00000000001e-6176 -> #80000000000000000000000000000000 Subnormal Underflow Inexact Rounded
-decf198 apply -0.00000000000001e-6176 -> #80000000000000000000000000000000 Subnormal Underflow Inexact Rounded
-decf199 apply -0.000000000000001e-6176 -> #80000000000000000000000000000000 Subnormal Underflow Inexact Rounded
-decf200 apply -999999999999999999999999999999999e-6176 -> #80000ff3fcff3fcff3fcff3fcff3fcff Subnormal
-
--- zeros
-decf400 apply 0E-8000 -> #00000000000000000000000000000000 Clamped
-decf401 apply 0E-6177 -> #00000000000000000000000000000000 Clamped
-decf402 apply 0E-6176 -> #00000000000000000000000000000000
-decf403 apply #00000000000000000000000000000000 -> 0E-6176
-decf404 apply 0.000000000000000000000000000000000E-6143 -> #00000000000000000000000000000000
-decf405 apply #00000000000000000000000000000000 -> 0E-6176
-decf406 apply 0E-2 -> #22078000000000000000000000000000
-decf407 apply #22078000000000000000000000000000 -> 0.00
-decf408 apply 0 -> #22080000000000000000000000000000
-decf409 apply #22080000000000000000000000000000 -> 0
-decf410 apply 0E+3 -> #2208c000000000000000000000000000
-decf411 apply #2208c000000000000000000000000000 -> 0E+3
-decf412 apply 0E+6111 -> #43ffc000000000000000000000000000
-decf413 apply #43ffc000000000000000000000000000 -> 0E+6111
--- clamped zeros...
-decf414 apply 0E+6112 -> #43ffc000000000000000000000000000 Clamped
-decf415 apply #43ffc000000000000000000000000000 -> 0E+6111
-decf416 apply 0E+6144 -> #43ffc000000000000000000000000000 Clamped
-decf417 apply #43ffc000000000000000000000000000 -> 0E+6111
-decf418 apply 0E+8000 -> #43ffc000000000000000000000000000 Clamped
-decf419 apply #43ffc000000000000000000000000000 -> 0E+6111
-
--- negative zeros
-decf420 apply -0E-8000 -> #80000000000000000000000000000000 Clamped
-decf421 apply -0E-6177 -> #80000000000000000000000000000000 Clamped
-decf422 apply -0E-6176 -> #80000000000000000000000000000000
-decf423 apply #80000000000000000000000000000000 -> -0E-6176
-decf424 apply -0.000000000000000000000000000000000E-6143 -> #80000000000000000000000000000000
-decf425 apply #80000000000000000000000000000000 -> -0E-6176
-decf426 apply -0E-2 -> #a2078000000000000000000000000000
-decf427 apply #a2078000000000000000000000000000 -> -0.00
-decf428 apply -0 -> #a2080000000000000000000000000000
-decf429 apply #a2080000000000000000000000000000 -> -0
-decf430 apply -0E+3 -> #a208c000000000000000000000000000
-decf431 apply #a208c000000000000000000000000000 -> -0E+3
-decf432 apply -0E+6111 -> #c3ffc000000000000000000000000000
-decf433 apply #c3ffc000000000000000000000000000 -> -0E+6111
--- clamped zeros...
-decf434 apply -0E+6112 -> #c3ffc000000000000000000000000000 Clamped
-decf435 apply #c3ffc000000000000000000000000000 -> -0E+6111
-decf436 apply -0E+6144 -> #c3ffc000000000000000000000000000 Clamped
-decf437 apply #c3ffc000000000000000000000000000 -> -0E+6111
-decf438 apply -0E+8000 -> #c3ffc000000000000000000000000000 Clamped
-decf439 apply #c3ffc000000000000000000000000000 -> -0E+6111
-
--- Specials
-decf500 apply Infinity -> #78000000000000000000000000000000
-decf501 apply #78787878787878787878787878787878 -> #78000000000000000000000000000000
-decf502 apply #78000000000000000000000000000000 -> Infinity
-decf503 apply #79797979797979797979797979797979 -> #78000000000000000000000000000000
-decf504 apply #79000000000000000000000000000000 -> Infinity
-decf505 apply #7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a -> #78000000000000000000000000000000
-decf506 apply #7a000000000000000000000000000000 -> Infinity
-decf507 apply #7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b -> #78000000000000000000000000000000
-decf508 apply #7b000000000000000000000000000000 -> Infinity
-
-decf509 apply NaN -> #7c000000000000000000000000000000
-decf510 apply #7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c -> #7c003c7c7c7c7c7c7c7c7c7c7c7c7c7c
-decf511 apply #7c000000000000000000000000000000 -> NaN
-decf512 apply #7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d -> #7c003d7d7d7d7d7d7d7d7d7d7d7d7d7d
-decf513 apply #7d000000000000000000000000000000 -> NaN
-decf514 apply #7e7e7e7e7e7e7e7e7e7e7e7e7e7e7e7e -> #7e003e7e7c7e7e7e7e7c7e7e7e7e7c7e
-decf515 apply #7e000000000000000000000000000000 -> sNaN
-decf516 apply #7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f -> #7e003f7f7c7f7f7f7f7c7f7f7f7f7c7f
-decf517 apply #7f000000000000000000000000000000 -> sNaN
-decf518 apply #7fffffffffffffffffffffffffffffff -> sNaN999999999999999999999999999999999
-decf519 apply #7fffffffffffffffffffffffffffffff -> #7e000ff3fcff3fcff3fcff3fcff3fcff
-
-decf520 apply -Infinity -> #f8000000000000000000000000000000
-decf521 apply #f8787878787878787878787878787878 -> #f8000000000000000000000000000000
-decf522 apply #f8000000000000000000000000000000 -> -Infinity
-decf523 apply #f9797979797979797979797979797979 -> #f8000000000000000000000000000000
-decf524 apply #f9000000000000000000000000000000 -> -Infinity
-decf525 apply #fa7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a -> #f8000000000000000000000000000000
-decf526 apply #fa000000000000000000000000000000 -> -Infinity
-decf527 apply #fb7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b -> #f8000000000000000000000000000000
-decf528 apply #fb000000000000000000000000000000 -> -Infinity
-
-decf529 apply -NaN -> #fc000000000000000000000000000000
-decf530 apply #fc7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c -> #fc003c7c7c7c7c7c7c7c7c7c7c7c7c7c
-decf531 apply #fc000000000000000000000000000000 -> -NaN
-decf532 apply #fd7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d -> #fc003d7d7d7d7d7d7d7d7d7d7d7d7d7d
-decf533 apply #fd000000000000000000000000000000 -> -NaN
-decf534 apply #fe7e7e7e7e7e7e7e7e7e7e7e7e7e7e7e -> #fe003e7e7c7e7e7e7e7c7e7e7e7e7c7e
-decf535 apply #fe000000000000000000000000000000 -> -sNaN
-decf536 apply #ff7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f -> #fe003f7f7c7f7f7f7f7c7f7f7f7f7c7f
-decf537 apply #ff000000000000000000000000000000 -> -sNaN
-decf538 apply #ffffffffffffffffffffffffffffffff -> -sNaN999999999999999999999999999999999
-decf539 apply #ffffffffffffffffffffffffffffffff -> #fe000ff3fcff3fcff3fcff3fcff3fcff
-
-decf540 apply NaN -> #7c000000000000000000000000000000
-decf541 apply NaN0 -> #7c000000000000000000000000000000
-decf542 apply NaN1 -> #7c000000000000000000000000000001
-decf543 apply NaN12 -> #7c000000000000000000000000000012
-decf544 apply NaN79 -> #7c000000000000000000000000000079
-decf545 apply NaN12345 -> #7c0000000000000000000000000049c5
-decf546 apply NaN123456 -> #7c000000000000000000000000028e56
-decf547 apply NaN799799 -> #7c0000000000000000000000000f7fdf
-decf548 apply NaN799799799799799799799799799799799 -> #7c003dff7fdff7fdff7fdff7fdff7fdf
-decf549 apply NaN999999999999999999999999999999999 -> #7c000ff3fcff3fcff3fcff3fcff3fcff
-decf550 apply NaN1234567890123456789012345678901234 -> #7c000000000000000000000000000000 -- too many digits
-
--- fold-down full sequence
-decf600 apply 1E+6145 -> #78000000000000000000000000000000 Overflow Inexact Rounded
-decf601 apply 1E+6144 -> #47ffc000000000000000000000000000 Clamped
-decf602 apply #47ffc000000000000000000000000000 -> 1.000000000000000000000000000000000E+6144
-decf603 apply 1E+6143 -> #43ffc800000000000000000000000000 Clamped
-decf604 apply #43ffc800000000000000000000000000 -> 1.00000000000000000000000000000000E+6143
-decf605 apply 1E+6142 -> #43ffc100000000000000000000000000 Clamped
-decf606 apply #43ffc100000000000000000000000000 -> 1.0000000000000000000000000000000E+6142
-decf607 apply 1E+6141 -> #43ffc010000000000000000000000000 Clamped
-decf608 apply #43ffc010000000000000000000000000 -> 1.000000000000000000000000000000E+6141
-decf609 apply 1E+6140 -> #43ffc002000000000000000000000000 Clamped
-decf610 apply #43ffc002000000000000000000000000 -> 1.00000000000000000000000000000E+6140
-decf611 apply 1E+6139 -> #43ffc000400000000000000000000000 Clamped
-decf612 apply #43ffc000400000000000000000000000 -> 1.0000000000000000000000000000E+6139
-decf613 apply 1E+6138 -> #43ffc000040000000000000000000000 Clamped
-decf614 apply #43ffc000040000000000000000000000 -> 1.000000000000000000000000000E+6138
-decf615 apply 1E+6137 -> #43ffc000008000000000000000000000 Clamped
-decf616 apply #43ffc000008000000000000000000000 -> 1.00000000000000000000000000E+6137
-decf617 apply 1E+6136 -> #43ffc000001000000000000000000000 Clamped
-decf618 apply #43ffc000001000000000000000000000 -> 1.0000000000000000000000000E+6136
-decf619 apply 1E+6135 -> #43ffc000000100000000000000000000 Clamped
-decf620 apply #43ffc000000100000000000000000000 -> 1.000000000000000000000000E+6135
-decf621 apply 1E+6134 -> #43ffc000000020000000000000000000 Clamped
-decf622 apply #43ffc000000020000000000000000000 -> 1.00000000000000000000000E+6134
-decf623 apply 1E+6133 -> #43ffc000000004000000000000000000 Clamped
-decf624 apply #43ffc000000004000000000000000000 -> 1.0000000000000000000000E+6133
-decf625 apply 1E+6132 -> #43ffc000000000400000000000000000 Clamped
-decf626 apply #43ffc000000000400000000000000000 -> 1.000000000000000000000E+6132
-decf627 apply 1E+6131 -> #43ffc000000000080000000000000000 Clamped
-decf628 apply #43ffc000000000080000000000000000 -> 1.00000000000000000000E+6131
-decf629 apply 1E+6130 -> #43ffc000000000010000000000000000 Clamped
-decf630 apply #43ffc000000000010000000000000000 -> 1.0000000000000000000E+6130
-decf631 apply 1E+6129 -> #43ffc000000000001000000000000000 Clamped
-decf632 apply #43ffc000000000001000000000000000 -> 1.000000000000000000E+6129
-decf633 apply 1E+6128 -> #43ffc000000000000200000000000000 Clamped
-decf634 apply #43ffc000000000000200000000000000 -> 1.00000000000000000E+6128
-decf635 apply 1E+6127 -> #43ffc000000000000040000000000000 Clamped
-decf636 apply #43ffc000000000000040000000000000 -> 1.0000000000000000E+6127
-decf637 apply 1E+6126 -> #43ffc000000000000004000000000000 Clamped
-decf638 apply #43ffc000000000000004000000000000 -> 1.000000000000000E+6126
-decf639 apply 1E+6125 -> #43ffc000000000000000800000000000 Clamped
-decf640 apply #43ffc000000000000000800000000000 -> 1.00000000000000E+6125
-decf641 apply 1E+6124 -> #43ffc000000000000000100000000000 Clamped
-decf642 apply #43ffc000000000000000100000000000 -> 1.0000000000000E+6124
-decf643 apply 1E+6123 -> #43ffc000000000000000010000000000 Clamped
-decf644 apply #43ffc000000000000000010000000000 -> 1.000000000000E+6123
-decf645 apply 1E+6122 -> #43ffc000000000000000002000000000 Clamped
-decf646 apply #43ffc000000000000000002000000000 -> 1.00000000000E+6122
-decf647 apply 1E+6121 -> #43ffc000000000000000000400000000 Clamped
-decf648 apply #43ffc000000000000000000400000000 -> 1.0000000000E+6121
-decf649 apply 1E+6120 -> #43ffc000000000000000000040000000 Clamped
-decf650 apply #43ffc000000000000000000040000000 -> 1.000000000E+6120
-decf651 apply 1E+6119 -> #43ffc000000000000000000008000000 Clamped
-decf652 apply #43ffc000000000000000000008000000 -> 1.00000000E+6119
-decf653 apply 1E+6118 -> #43ffc000000000000000000001000000 Clamped
-decf654 apply #43ffc000000000000000000001000000 -> 1.0000000E+6118
-decf655 apply 1E+6117 -> #43ffc000000000000000000000100000 Clamped
-decf656 apply #43ffc000000000000000000000100000 -> 1.000000E+6117
-decf657 apply 1E+6116 -> #43ffc000000000000000000000020000 Clamped
-decf658 apply #43ffc000000000000000000000020000 -> 1.00000E+6116
-decf659 apply 1E+6115 -> #43ffc000000000000000000000004000 Clamped
-decf660 apply #43ffc000000000000000000000004000 -> 1.0000E+6115
-decf661 apply 1E+6114 -> #43ffc000000000000000000000000400 Clamped
-decf662 apply #43ffc000000000000000000000000400 -> 1.000E+6114
-decf663 apply 1E+6113 -> #43ffc000000000000000000000000080 Clamped
-decf664 apply #43ffc000000000000000000000000080 -> 1.00E+6113
-decf665 apply 1E+6112 -> #43ffc000000000000000000000000010 Clamped
-decf666 apply #43ffc000000000000000000000000010 -> 1.0E+6112
-decf667 apply 1E+6111 -> #43ffc000000000000000000000000001
-decf668 apply #43ffc000000000000000000000000001 -> 1E+6111
-decf669 apply 1E+6110 -> #43ff8000000000000000000000000001
-decf670 apply #43ff8000000000000000000000000001 -> 1E+6110
-
--- Selected DPD codes
-decf700 apply #22080000000000000000000000000000 -> 0
-decf701 apply #22080000000000000000000000000009 -> 9
-decf702 apply #22080000000000000000000000000010 -> 10
-decf703 apply #22080000000000000000000000000019 -> 19
-decf704 apply #22080000000000000000000000000020 -> 20
-decf705 apply #22080000000000000000000000000029 -> 29
-decf706 apply #22080000000000000000000000000030 -> 30
-decf707 apply #22080000000000000000000000000039 -> 39
-decf708 apply #22080000000000000000000000000040 -> 40
-decf709 apply #22080000000000000000000000000049 -> 49
-decf710 apply #22080000000000000000000000000050 -> 50
-decf711 apply #22080000000000000000000000000059 -> 59
-decf712 apply #22080000000000000000000000000060 -> 60
-decf713 apply #22080000000000000000000000000069 -> 69
-decf714 apply #22080000000000000000000000000070 -> 70
-decf715 apply #22080000000000000000000000000071 -> 71
-decf716 apply #22080000000000000000000000000072 -> 72
-decf717 apply #22080000000000000000000000000073 -> 73
-decf718 apply #22080000000000000000000000000074 -> 74
-decf719 apply #22080000000000000000000000000075 -> 75
-decf720 apply #22080000000000000000000000000076 -> 76
-decf721 apply #22080000000000000000000000000077 -> 77
-decf722 apply #22080000000000000000000000000078 -> 78
-decf723 apply #22080000000000000000000000000079 -> 79
-
-decf730 apply #2208000000000000000000000000029e -> 994
-decf731 apply #2208000000000000000000000000029f -> 995
-decf732 apply #220800000000000000000000000002a0 -> 520
-decf733 apply #220800000000000000000000000002a1 -> 521
-
--- DPD: one of each of the huffman groups
-decf740 apply #220800000000000000000000000003f7 -> 777
-decf741 apply #220800000000000000000000000003f8 -> 778
-decf742 apply #220800000000000000000000000003eb -> 787
-decf743 apply #2208000000000000000000000000037d -> 877
-decf744 apply #2208000000000000000000000000039f -> 997
-decf745 apply #220800000000000000000000000003bf -> 979
-decf746 apply #220800000000000000000000000003df -> 799
-decf747 apply #2208000000000000000000000000006e -> 888
-
-
--- DPD all-highs cases (includes the 24 redundant codes)
-decf750 apply #2208000000000000000000000000006e -> 888
-decf751 apply #2208000000000000000000000000016e -> 888
-decf752 apply #2208000000000000000000000000026e -> 888
-decf753 apply #2208000000000000000000000000036e -> 888
-decf754 apply #2208000000000000000000000000006f -> 889
-decf755 apply #2208000000000000000000000000016f -> 889
-decf756 apply #2208000000000000000000000000026f -> 889
-decf757 apply #2208000000000000000000000000036f -> 889
-
-decf760 apply #2208000000000000000000000000007e -> 898
-decf761 apply #2208000000000000000000000000017e -> 898
-decf762 apply #2208000000000000000000000000027e -> 898
-decf763 apply #2208000000000000000000000000037e -> 898
-decf764 apply #2208000000000000000000000000007f -> 899
-decf765 apply #2208000000000000000000000000017f -> 899
-decf766 apply #2208000000000000000000000000027f -> 899
-decf767 apply #2208000000000000000000000000037f -> 899
-
-decf770 apply #220800000000000000000000000000ee -> 988
-decf771 apply #220800000000000000000000000001ee -> 988
-decf772 apply #220800000000000000000000000002ee -> 988
-decf773 apply #220800000000000000000000000003ee -> 988
-decf774 apply #220800000000000000000000000000ef -> 989
-decf775 apply #220800000000000000000000000001ef -> 989
-decf776 apply #220800000000000000000000000002ef -> 989
-decf777 apply #220800000000000000000000000003ef -> 989
-
-decf780 apply #220800000000000000000000000000fe -> 998
-decf781 apply #220800000000000000000000000001fe -> 998
-decf782 apply #220800000000000000000000000002fe -> 998
-decf783 apply #220800000000000000000000000003fe -> 998
-decf784 apply #220800000000000000000000000000ff -> 999
-decf785 apply #220800000000000000000000000001ff -> 999
-decf786 apply #220800000000000000000000000002ff -> 999
-decf787 apply #220800000000000000000000000003ff -> 999
-
Deleted: /python/branches/py3k-importlib/Lib/test/decimaltestdata/decimal32.decTest
==============================================================================
--- /python/branches/py3k-importlib/Lib/test/decimaltestdata/decimal32.decTest Fri Sep 21 03:17:09 2007
+++ (empty file)
@@ -1,385 +0,0 @@
-------------------------------------------------------------------------
--- decimal32.decTest -- decimal four-byte format testcases --
--- Copyright (c) IBM Corporation, 2000, 2003. All rights reserved. --
-------------------------------------------------------------------------
--- Please see the document "General Decimal Arithmetic Testcases" --
--- at http://www2.hursley.ibm.com/decimal for the description of --
--- these testcases. --
--- --
--- These testcases are experimental ('beta' versions), and they --
--- may contain errors. They are offered on an as-is basis. In --
--- particular, achieving the same results as the tests here is not --
--- a guarantee that an implementation complies with any Standard --
--- or specification. The tests are not exhaustive. --
--- --
--- Please send comments, suggestions, and corrections to the author: --
--- Mike Cowlishaw, IBM Fellow --
--- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
--- mfc at uk.ibm.com --
-------------------------------------------------------------------------
-version: 2.39
-
--- This set of tests is for the four-byte concrete representation.
--- Its characteristics are:
---
--- 1 bit sign
--- 5 bits combination field
--- 6 bits exponent continuation
--- 20 bits coefficient continuation
---
--- Total exponent length 8 bits
--- Total coefficient length 24 bits (7 digits)
---
--- Elimit = 191 (maximum encoded exponent)
--- Emax = 96 (largest exponent value)
--- Emin = -95 (smallest exponent value)
--- bias = 101 (subtracted from encoded exponent) = -Etiny
-
-extended: 1
-precision: 7
-rounding: half_up
-maxExponent: 96
-minExponent: -95
-
--- General testcases
--- (mostly derived from the Strawman 4 document and examples)
-decd001 apply #A23003D0 -> -7.50
-decd002 apply -7.50 -> #A23003D0
-
--- Normality
-decd010 apply 1234567 -> #2654d2e7
-decd011 apply 1234567.0 -> #2654d2e7 Rounded
-decd012 apply 1234567.1 -> #2654d2e7 Rounded Inexact
-decd013 apply -1234567 -> #a654d2e7
-decd014 apply -1234567.0 -> #a654d2e7 Rounded
-decd015 apply -1234567.1 -> #a654d2e7 Rounded Inexact
-
-
--- Nmax and similar
-decd022 apply 9.999999E+96 -> #77f3fcff
-decd023 apply #77f3fcff -> 9.999999E+96
-decd024 apply 1.234567E+96 -> #47f4d2e7
-decd025 apply #47f4d2e7 -> 1.234567E+96
--- fold-downs (more below)
-decd030 apply 1.23E+96 -> #47f4c000 Clamped
-decd031 apply #47f4c000 -> 1.230000E+96
-decd032 apply 1E+96 -> #47f00000 Clamped
-decd033 apply #47f00000 -> 1.000000E+96
-
--- overflows
-maxExponent: 999 -- set high so conversion causes the overflow
-minExponent: -999
-decd040 apply 10E+96 -> #78000000 Overflow Rounded Inexact
-decd041 apply 1.000000E+97 -> #78000000 Overflow Rounded Inexact
-maxExponent: 96
-minExponent: -95
-
-decd051 apply 12345 -> #225049c5
-decd052 apply #225049c5 -> 12345
-decd053 apply 1234 -> #22500534
-decd054 apply #22500534 -> 1234
-decd055 apply 123 -> #225000a3
-decd056 apply #225000a3 -> 123
-decd057 apply 12 -> #22500012
-decd058 apply #22500012 -> 12
-decd059 apply 1 -> #22500001
-decd060 apply #22500001 -> 1
-decd061 apply 1.23 -> #223000a3
-decd062 apply #223000a3 -> 1.23
-decd063 apply 123.45 -> #223049c5
-decd064 apply #223049c5 -> 123.45
-
--- Nmin and below
-decd071 apply 1E-95 -> #00600001
-decd072 apply #00600001 -> 1E-95
-decd073 apply 1.000000E-95 -> #04000000
-decd074 apply #04000000 -> 1.000000E-95
-decd075 apply 1.000001E-95 -> #04000001
-decd076 apply #04000001 -> 1.000001E-95
-
-decd077 apply 0.100000E-95 -> #00020000 Subnormal
-decd07x apply 1.00000E-96 -> 1.00000E-96 Subnormal
-decd078 apply #00020000 -> 1.00000E-96 Subnormal
-decd079 apply 0.000010E-95 -> #00000010 Subnormal
-decd080 apply #00000010 -> 1.0E-100 Subnormal
-decd081 apply 0.000001E-95 -> #00000001 Subnormal
-decd082 apply #00000001 -> 1E-101 Subnormal
-decd083 apply 1e-101 -> #00000001 Subnormal
-decd084 apply #00000001 -> 1E-101 Subnormal
-decd08x apply 1e-101 -> 1E-101 Subnormal
-
--- underflows
-decd090 apply 1e-101 -> #00000001 Subnormal
-decd091 apply 1.9e-101 -> #00000002 Subnormal Underflow Inexact Rounded
-decd092 apply 1.1e-101 -> #00000001 Subnormal Underflow Inexact Rounded
-decd093 apply 1.001e-101 -> #00000001 Subnormal Underflow Inexact Rounded
-decd094 apply 1.000001e-101 -> #00000001 Subnormal Underflow Inexact Rounded
-decd095 apply 1.0000001e-101 -> #00000001 Subnormal Underflow Inexact Rounded
-decd096 apply 0.1e-101 -> #00000000 Subnormal Underflow Inexact Rounded
-decd097 apply 0.001e-101 -> #00000000 Subnormal Underflow Inexact Rounded
-decd098 apply 0.000001e-101 -> #00000000 Subnormal Underflow Inexact Rounded
-decd099 apply 0.0000001e-101 -> #00000000 Subnormal Underflow Inexact Rounded
-
--- same again, negatives --
-
--- Nmax and similar
-decd122 apply -9.999999E+96 -> #f7f3fcff
-decd123 apply #f7f3fcff -> -9.999999E+96
-decd124 apply -1.234567E+96 -> #c7f4d2e7
-decd125 apply #c7f4d2e7 -> -1.234567E+96
--- fold-downs (more below)
-decd130 apply -1.23E+96 -> #c7f4c000 Clamped
-decd131 apply #c7f4c000 -> -1.230000E+96
-decd132 apply -1E+96 -> #c7f00000 Clamped
-decd133 apply #c7f00000 -> -1.000000E+96
-
--- overflows
-maxExponent: 999 -- set high so conversion causes the overflow
-minExponent: -999
-decd140 apply -10E+96 -> #f8000000 Overflow Rounded Inexact
-decd141 apply -1.000000E+97 -> #f8000000 Overflow Rounded Inexact
-maxExponent: 96
-minExponent: -95
-
-decd151 apply -12345 -> #a25049c5
-decd152 apply #a25049c5 -> -12345
-decd153 apply -1234 -> #a2500534
-decd154 apply #a2500534 -> -1234
-decd155 apply -123 -> #a25000a3
-decd156 apply #a25000a3 -> -123
-decd157 apply -12 -> #a2500012
-decd158 apply #a2500012 -> -12
-decd159 apply -1 -> #a2500001
-decd160 apply #a2500001 -> -1
-decd161 apply -1.23 -> #a23000a3
-decd162 apply #a23000a3 -> -1.23
-decd163 apply -123.45 -> #a23049c5
-decd164 apply #a23049c5 -> -123.45
-
--- Nmin and below
-decd171 apply -1E-95 -> #80600001
-decd172 apply #80600001 -> -1E-95
-decd173 apply -1.000000E-95 -> #84000000
-decd174 apply #84000000 -> -1.000000E-95
-decd175 apply -1.000001E-95 -> #84000001
-decd176 apply #84000001 -> -1.000001E-95
-
-decd177 apply -0.100000E-95 -> #80020000 Subnormal
-decd178 apply #80020000 -> -1.00000E-96 Subnormal
-decd179 apply -0.000010E-95 -> #80000010 Subnormal
-decd180 apply #80000010 -> -1.0E-100 Subnormal
-decd181 apply -0.000001E-95 -> #80000001 Subnormal
-decd182 apply #80000001 -> -1E-101 Subnormal
-decd183 apply -1e-101 -> #80000001 Subnormal
-decd184 apply #80000001 -> -1E-101 Subnormal
-
--- underflows
-decd190 apply -1e-101 -> #80000001 Subnormal
-decd191 apply -1.9e-101 -> #80000002 Subnormal Underflow Inexact Rounded
-decd192 apply -1.1e-101 -> #80000001 Subnormal Underflow Inexact Rounded
-decd193 apply -1.001e-101 -> #80000001 Subnormal Underflow Inexact Rounded
-decd194 apply -1.000001e-101 -> #80000001 Subnormal Underflow Inexact Rounded
-decd195 apply -1.0000001e-101 -> #80000001 Subnormal Underflow Inexact Rounded
-decd196 apply -0.1e-101 -> #80000000 Subnormal Underflow Inexact Rounded
-decd197 apply -0.001e-101 -> #80000000 Subnormal Underflow Inexact Rounded
-decd198 apply -0.000001e-101 -> #80000000 Subnormal Underflow Inexact Rounded
-decd199 apply -0.0000001e-101 -> #80000000 Subnormal Underflow Inexact Rounded
-
--- zeros
-decd400 apply 0E-400 -> #00000000 Clamped
-decd401 apply 0E-101 -> #00000000
-decd402 apply #00000000 -> 0E-101
-decd403 apply 0.000000E-95 -> #00000000
-decd404 apply #00000000 -> 0E-101
-decd405 apply 0E-2 -> #22300000
-decd406 apply #22300000 -> 0.00
-decd407 apply 0 -> #22500000
-decd408 apply #22500000 -> 0
-decd409 apply 0E+3 -> #22800000
-decd410 apply #22800000 -> 0E+3
-decd411 apply 0E+90 -> #43f00000
-decd412 apply #43f00000 -> 0E+90
--- clamped zeros...
-decd413 apply 0E+91 -> #43f00000 Clamped
-decd414 apply #43f00000 -> 0E+90
-decd415 apply 0E+96 -> #43f00000 Clamped
-decd416 apply #43f00000 -> 0E+90
-decd417 apply 0E+400 -> #43f00000 Clamped
-decd418 apply #43f00000 -> 0E+90
-
--- negative zeros
-decd420 apply -0E-400 -> #80000000 Clamped
-decd421 apply -0E-101 -> #80000000
-decd422 apply #80000000 -> -0E-101
-decd423 apply -0.000000E-95 -> #80000000
-decd424 apply #80000000 -> -0E-101
-decd425 apply -0E-2 -> #a2300000
-decd426 apply #a2300000 -> -0.00
-decd427 apply -0 -> #a2500000
-decd428 apply #a2500000 -> -0
-decd429 apply -0E+3 -> #a2800000
-decd430 apply #a2800000 -> -0E+3
-decd431 apply -0E+90 -> #c3f00000
-decd432 apply #c3f00000 -> -0E+90
--- clamped zeros...
-decd433 apply -0E+91 -> #c3f00000 Clamped
-decd434 apply #c3f00000 -> -0E+90
-decd435 apply -0E+96 -> #c3f00000 Clamped
-decd436 apply #c3f00000 -> -0E+90
-decd437 apply -0E+400 -> #c3f00000 Clamped
-decd438 apply #c3f00000 -> -0E+90
-
--- Specials
-decd500 apply Infinity -> #78000000
-decd501 apply #78787878 -> #78000000
-decd502 apply #78000000 -> Infinity
-decd503 apply #79797979 -> #78000000
-decd504 apply #79000000 -> Infinity
-decd505 apply #7a7a7a7a -> #78000000
-decd506 apply #7a000000 -> Infinity
-decd507 apply #7b7b7b7b -> #78000000
-decd508 apply #7b000000 -> Infinity
-decd509 apply #7c7c7c7c -> #7c0c7c7c
-
-decd510 apply NaN -> #7c000000
-decd511 apply #7c000000 -> NaN
-decd512 apply #7d7d7d7d -> #7c0d7d7d
-decd513 apply #7d000000 -> NaN
-decd514 apply #7e7e7e7e -> #7e0e7c7e
-decd515 apply #7e000000 -> sNaN
-decd516 apply #7f7f7f7f -> #7e0f7c7f
-decd517 apply #7f000000 -> sNaN
-decd518 apply #7fffffff -> sNaN999999
-decd519 apply #7fffffff -> #7e03fcff
-
-decd520 apply -Infinity -> #f8000000
-decd521 apply #f8787878 -> #f8000000
-decd522 apply #f8000000 -> -Infinity
-decd523 apply #f9797979 -> #f8000000
-decd524 apply #f9000000 -> -Infinity
-decd525 apply #fa7a7a7a -> #f8000000
-decd526 apply #fa000000 -> -Infinity
-decd527 apply #fb7b7b7b -> #f8000000
-decd528 apply #fb000000 -> -Infinity
-
-decd529 apply -NaN -> #fc000000
-decd530 apply #fc7c7c7c -> #fc0c7c7c
-decd531 apply #fc000000 -> -NaN
-decd532 apply #fd7d7d7d -> #fc0d7d7d
-decd533 apply #fd000000 -> -NaN
-decd534 apply #fe7e7e7e -> #fe0e7c7e
-decd535 apply #fe000000 -> -sNaN
-decd536 apply #ff7f7f7f -> #fe0f7c7f
-decd537 apply #ff000000 -> -sNaN
-decd538 apply #ffffffff -> -sNaN999999
-decd539 apply #ffffffff -> #fe03fcff
-
--- diagnostic NaNs
-decd540 apply NaN -> #7c000000
-decd541 apply NaN0 -> #7c000000
-decd542 apply NaN1 -> #7c000001
-decd543 apply NaN12 -> #7c000012
-decd544 apply NaN79 -> #7c000079
-decd545 apply NaN12345 -> #7c0049c5
-decd546 apply NaN123456 -> #7c028e56
-decd547 apply NaN799799 -> #7c0f7fdf
-decd548 apply NaN999999 -> #7c03fcff
-decd549 apply NaN1234567 -> #7c000000 -- too many digits
-
-
--- fold-down full sequence
-decd601 apply 1E+96 -> #47f00000 Clamped
-decd602 apply #47f00000 -> 1.000000E+96
-decd603 apply 1E+95 -> #43f20000 Clamped
-decd604 apply #43f20000 -> 1.00000E+95
-decd605 apply 1E+94 -> #43f04000 Clamped
-decd606 apply #43f04000 -> 1.0000E+94
-decd607 apply 1E+93 -> #43f00400 Clamped
-decd608 apply #43f00400 -> 1.000E+93
-decd609 apply 1E+92 -> #43f00080 Clamped
-decd610 apply #43f00080 -> 1.00E+92
-decd611 apply 1E+91 -> #43f00010 Clamped
-decd612 apply #43f00010 -> 1.0E+91
-decd613 apply 1E+90 -> #43f00001
-decd614 apply #43f00001 -> 1E+90
-
-
--- Selected DPD codes
-decd700 apply #22500000 -> 0
-decd701 apply #22500009 -> 9
-decd702 apply #22500010 -> 10
-decd703 apply #22500019 -> 19
-decd704 apply #22500020 -> 20
-decd705 apply #22500029 -> 29
-decd706 apply #22500030 -> 30
-decd707 apply #22500039 -> 39
-decd708 apply #22500040 -> 40
-decd709 apply #22500049 -> 49
-decd710 apply #22500050 -> 50
-decd711 apply #22500059 -> 59
-decd712 apply #22500060 -> 60
-decd713 apply #22500069 -> 69
-decd714 apply #22500070 -> 70
-decd715 apply #22500071 -> 71
-decd716 apply #22500072 -> 72
-decd717 apply #22500073 -> 73
-decd718 apply #22500074 -> 74
-decd719 apply #22500075 -> 75
-decd720 apply #22500076 -> 76
-decd721 apply #22500077 -> 77
-decd722 apply #22500078 -> 78
-decd723 apply #22500079 -> 79
-
-decd730 apply #2250029e -> 994
-decd731 apply #2250029f -> 995
-decd732 apply #225002a0 -> 520
-decd733 apply #225002a1 -> 521
-
--- DPD: one of each of the huffman groups
-decd740 apply #225003f7 -> 777
-decd741 apply #225003f8 -> 778
-decd742 apply #225003eb -> 787
-decd743 apply #2250037d -> 877
-decd744 apply #2250039f -> 997
-decd745 apply #225003bf -> 979
-decd746 apply #225003df -> 799
-decd747 apply #2250006e -> 888
-
-
--- DPD all-highs cases (includes the 24 redundant codes)
-decd750 apply #2250006e -> 888
-decd751 apply #2250016e -> 888
-decd752 apply #2250026e -> 888
-decd753 apply #2250036e -> 888
-decd754 apply #2250006f -> 889
-decd755 apply #2250016f -> 889
-decd756 apply #2250026f -> 889
-decd757 apply #2250036f -> 889
-
-decd760 apply #2250007e -> 898
-decd761 apply #2250017e -> 898
-decd762 apply #2250027e -> 898
-decd763 apply #2250037e -> 898
-decd764 apply #2250007f -> 899
-decd765 apply #2250017f -> 899
-decd766 apply #2250027f -> 899
-decd767 apply #2250037f -> 899
-
-decd770 apply #225000ee -> 988
-decd771 apply #225001ee -> 988
-decd772 apply #225002ee -> 988
-decd773 apply #225003ee -> 988
-decd774 apply #225000ef -> 989
-decd775 apply #225001ef -> 989
-decd776 apply #225002ef -> 989
-decd777 apply #225003ef -> 989
-
-decd780 apply #225000fe -> 998
-decd781 apply #225001fe -> 998
-decd782 apply #225002fe -> 998
-decd783 apply #225003fe -> 998
-decd784 apply #225000ff -> 999
-decd785 apply #225001ff -> 999
-decd786 apply #225002ff -> 999
-decd787 apply #225003ff -> 999
-
Deleted: /python/branches/py3k-importlib/Lib/test/decimaltestdata/decimal64.decTest
==============================================================================
--- /python/branches/py3k-importlib/Lib/test/decimaltestdata/decimal64.decTest Fri Sep 21 03:17:09 2007
+++ (empty file)
@@ -1,444 +0,0 @@
-------------------------------------------------------------------------
--- decimal64.decTest -- decimal eight-byte format testcases --
--- Copyright (c) IBM Corporation, 2000, 2003. All rights reserved. --
-------------------------------------------------------------------------
--- Please see the document "General Decimal Arithmetic Testcases" --
--- at http://www2.hursley.ibm.com/decimal for the description of --
--- these testcases. --
--- --
--- These testcases are experimental ('beta' versions), and they --
--- may contain errors. They are offered on an as-is basis. In --
--- particular, achieving the same results as the tests here is not --
--- a guarantee that an implementation complies with any Standard --
--- or specification. The tests are not exhaustive. --
--- --
--- Please send comments, suggestions, and corrections to the author: --
--- Mike Cowlishaw, IBM Fellow --
--- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
--- mfc at uk.ibm.com --
-------------------------------------------------------------------------
-version: 2.39
-
--- This set of tests is for the eight-byte concrete representation.
--- Its characteristics are:
---
--- 1 bit sign
--- 5 bits combination field
--- 8 bits exponent continuation
--- 50 bits coefficient continuation
---
--- Total exponent length 10 bits
--- Total coefficient length 54 bits (16 digits)
---
--- Elimit = 767 (maximum encoded exponent)
--- Emax = 384 (largest exponent value)
--- Emin = -383 (smallest exponent value)
--- bias = 398 (subtracted from encoded exponent) = -Etiny
-
-extended: 1
-precision: 16
-rounding: half_up
-maxExponent: 384
-minExponent: -383
-
--- General testcases
--- (mostly derived from the Strawman 4 document and examples)
-dece001 apply #A2300000000003D0 -> -7.50
-dece002 apply -7.50 -> #A2300000000003D0
-
--- Normality
-dece010 apply 1234567890123456 -> #263934b9c1e28e56
-dece011 apply 1234567890123456.0 -> #263934b9c1e28e56 Rounded
-dece012 apply 1234567890123456.1 -> #263934b9c1e28e56 Rounded Inexact
-dece013 apply -1234567890123456 -> #a63934b9c1e28e56
-dece014 apply -1234567890123456.0 -> #a63934b9c1e28e56 Rounded
-dece015 apply -1234567890123456.1 -> #a63934b9c1e28e56 Rounded Inexact
-
-
--- Nmax and similar
-dece022 apply 9.999999999999999E+384 -> #77fcff3fcff3fcff
-dece023 apply #77fcff3fcff3fcff -> 9.999999999999999E+384
-dece024 apply 1.234567890123456E+384 -> #47fd34b9c1e28e56
-dece025 apply #47fd34b9c1e28e56 -> 1.234567890123456E+384
--- fold-downs (more below)
-dece030 apply 1.23E+384 -> #47fd300000000000 Clamped
-dece031 apply #47fd300000000000 -> 1.230000000000000E+384
-dece032 apply 1E+384 -> #47fc000000000000 Clamped
-dece033 apply #47fc000000000000 -> 1.000000000000000E+384
-
--- overflows
-maxExponent: 999 -- set high so conversion causes the overflow
-minExponent: -999
-dece040 apply 10E+384 -> #7800000000000000 Overflow Rounded Inexact
-dece041 apply 1.000000000000000E+385 -> #7800000000000000 Overflow Rounded Inexact
-maxExponent: 384
-minExponent: -383
-
-dece051 apply 12345 -> #22380000000049c5
-dece052 apply #22380000000049c5 -> 12345
-dece053 apply 1234 -> #2238000000000534
-dece054 apply #2238000000000534 -> 1234
-dece055 apply 123 -> #22380000000000a3
-dece056 apply #22380000000000a3 -> 123
-dece057 apply 12 -> #2238000000000012
-dece058 apply #2238000000000012 -> 12
-dece059 apply 1 -> #2238000000000001
-dece060 apply #2238000000000001 -> 1
-dece061 apply 1.23 -> #22300000000000a3
-dece062 apply #22300000000000a3 -> 1.23
-dece063 apply 123.45 -> #22300000000049c5
-dece064 apply #22300000000049c5 -> 123.45
-
--- Nmin and below
-dece071 apply 1E-383 -> #003c000000000001
-dece072 apply #003c000000000001 -> 1E-383
-dece073 apply 1.000000000000000E-383 -> #0400000000000000
-dece074 apply #0400000000000000 -> 1.000000000000000E-383
-dece075 apply 1.000000000000001E-383 -> #0400000000000001
-dece076 apply #0400000000000001 -> 1.000000000000001E-383
-
-dece077 apply 0.100000000000000E-383 -> #0000800000000000 Subnormal
-dece078 apply #0000800000000000 -> 1.00000000000000E-384 Subnormal
-dece079 apply 0.000000000000010E-383 -> #0000000000000010 Subnormal
-dece080 apply #0000000000000010 -> 1.0E-397 Subnormal
-dece081 apply 0.00000000000001E-383 -> #0004000000000001 Subnormal
-dece082 apply #0004000000000001 -> 1E-397 Subnormal
-dece083 apply 0.000000000000001E-383 -> #0000000000000001 Subnormal
-dece084 apply #0000000000000001 -> 1E-398 Subnormal
-
--- underflows
-dece090 apply 1e-398 -> #0000000000000001 Subnormal
-dece091 apply 1.9e-398 -> #0000000000000002 Subnormal Underflow Inexact Rounded
-dece092 apply 1.1e-398 -> #0000000000000001 Subnormal Underflow Inexact Rounded
-dece093 apply 1.00000000001e-398 -> #0000000000000001 Subnormal Underflow Inexact Rounded
-dece094 apply 1.00000000000001e-398 -> #0000000000000001 Subnormal Underflow Inexact Rounded
-dece095 apply 1.000000000000001e-398 -> #0000000000000001 Subnormal Underflow Inexact Rounded
-dece096 apply 0.1e-398 -> #0000000000000000 Subnormal Underflow Inexact Rounded
-dece097 apply 0.00000000001e-398 -> #0000000000000000 Subnormal Underflow Inexact Rounded
-dece098 apply 0.00000000000001e-398 -> #0000000000000000 Subnormal Underflow Inexact Rounded
-dece099 apply 0.000000000000001e-398 -> #0000000000000000 Subnormal Underflow Inexact Rounded
-
--- Same again, negatives
--- Nmax and similar
-dece122 apply -9.999999999999999E+384 -> #f7fcff3fcff3fcff
-dece123 apply #f7fcff3fcff3fcff -> -9.999999999999999E+384
-dece124 apply -1.234567890123456E+384 -> #c7fd34b9c1e28e56
-dece125 apply #c7fd34b9c1e28e56 -> -1.234567890123456E+384
--- fold-downs (more below)
-dece130 apply -1.23E+384 -> #c7fd300000000000 Clamped
-dece131 apply #c7fd300000000000 -> -1.230000000000000E+384
-dece132 apply -1E+384 -> #c7fc000000000000 Clamped
-dece133 apply #c7fc000000000000 -> -1.000000000000000E+384
-
--- overflows
-maxExponent: 999 -- set high so conversion causes the overflow
-minExponent: -999
-dece140 apply -10E+384 -> #f800000000000000 Overflow Rounded Inexact
-dece141 apply -1.000000000000000E+385 -> #f800000000000000 Overflow Rounded Inexact
-maxExponent: 384
-minExponent: -383
-
-dece151 apply -12345 -> #a2380000000049c5
-dece152 apply #a2380000000049c5 -> -12345
-dece153 apply -1234 -> #a238000000000534
-dece154 apply #a238000000000534 -> -1234
-dece155 apply -123 -> #a2380000000000a3
-dece156 apply #a2380000000000a3 -> -123
-dece157 apply -12 -> #a238000000000012
-dece158 apply #a238000000000012 -> -12
-dece159 apply -1 -> #a238000000000001
-dece160 apply #a238000000000001 -> -1
-dece161 apply -1.23 -> #a2300000000000a3
-dece162 apply #a2300000000000a3 -> -1.23
-dece163 apply -123.45 -> #a2300000000049c5
-dece164 apply #a2300000000049c5 -> -123.45
-
--- Nmin and below
-dece171 apply -1E-383 -> #803c000000000001
-dece172 apply #803c000000000001 -> -1E-383
-dece173 apply -1.000000000000000E-383 -> #8400000000000000
-dece174 apply #8400000000000000 -> -1.000000000000000E-383
-dece175 apply -1.000000000000001E-383 -> #8400000000000001
-dece176 apply #8400000000000001 -> -1.000000000000001E-383
-
-dece177 apply -0.100000000000000E-383 -> #8000800000000000 Subnormal
-dece178 apply #8000800000000000 -> -1.00000000000000E-384 Subnormal
-dece179 apply -0.000000000000010E-383 -> #8000000000000010 Subnormal
-dece180 apply #8000000000000010 -> -1.0E-397 Subnormal
-dece181 apply -0.00000000000001E-383 -> #8004000000000001 Subnormal
-dece182 apply #8004000000000001 -> -1E-397 Subnormal
-dece183 apply -0.000000000000001E-383 -> #8000000000000001 Subnormal
-dece184 apply #8000000000000001 -> -1E-398 Subnormal
-
--- underflows
-dece189 apply -1e-398 -> #8000000000000001 Subnormal
-dece190 apply -1.0e-398 -> #8000000000000001 Subnormal Rounded
-dece191 apply -1.9e-398 -> #8000000000000002 Subnormal Underflow Inexact Rounded
-dece192 apply -1.1e-398 -> #8000000000000001 Subnormal Underflow Inexact Rounded
-dece193 apply -1.00000000001e-398 -> #8000000000000001 Subnormal Underflow Inexact Rounded
-dece194 apply -1.00000000000001e-398 -> #8000000000000001 Subnormal Underflow Inexact Rounded
-dece195 apply -1.000000000000001e-398 -> #8000000000000001 Subnormal Underflow Inexact Rounded
-dece196 apply -0.1e-398 -> #8000000000000000 Subnormal Underflow Inexact Rounded
-dece197 apply -0.00000000001e-398 -> #8000000000000000 Subnormal Underflow Inexact Rounded
-dece198 apply -0.00000000000001e-398 -> #8000000000000000 Subnormal Underflow Inexact Rounded
-dece199 apply -0.000000000000001e-398 -> #8000000000000000 Subnormal Underflow Inexact Rounded
-
--- zeros
-dece401 apply 0E-500 -> #0000000000000000 Clamped
-dece402 apply 0E-400 -> #0000000000000000 Clamped
-dece403 apply 0E-398 -> #0000000000000000
-dece404 apply #0000000000000000 -> 0E-398
-dece405 apply 0.000000000000000E-383 -> #0000000000000000
-dece406 apply #0000000000000000 -> 0E-398
-dece407 apply 0E-2 -> #2230000000000000
-dece408 apply #2230000000000000 -> 0.00
-dece409 apply 0 -> #2238000000000000
-dece410 apply #2238000000000000 -> 0
-dece411 apply 0E+3 -> #2244000000000000
-dece412 apply #2244000000000000 -> 0E+3
-dece413 apply 0E+369 -> #43fc000000000000
-dece414 apply #43fc000000000000 -> 0E+369
--- clamped zeros...
-dece415 apply 0E+370 -> #43fc000000000000 Clamped
-dece416 apply #43fc000000000000 -> 0E+369
-dece417 apply 0E+384 -> #43fc000000000000 Clamped
-dece418 apply #43fc000000000000 -> 0E+369
-dece419 apply 0E+400 -> #43fc000000000000 Clamped
-dece420 apply #43fc000000000000 -> 0E+369
-dece421 apply 0E+500 -> #43fc000000000000 Clamped
-dece422 apply #43fc000000000000 -> 0E+369
-
--- negative zeros
-dece431 apply -0E-400 -> #8000000000000000 Clamped
-dece432 apply -0E-400 -> #8000000000000000 Clamped
-dece433 apply -0E-398 -> #8000000000000000
-dece434 apply #8000000000000000 -> -0E-398
-dece435 apply -0.000000000000000E-383 -> #8000000000000000
-dece436 apply #8000000000000000 -> -0E-398
-dece437 apply -0E-2 -> #a230000000000000
-dece438 apply #a230000000000000 -> -0.00
-dece439 apply -0 -> #a238000000000000
-dece440 apply #a238000000000000 -> -0
-dece441 apply -0E+3 -> #a244000000000000
-dece442 apply #a244000000000000 -> -0E+3
-dece443 apply -0E+369 -> #c3fc000000000000
-dece444 apply #c3fc000000000000 -> -0E+369
--- clamped zeros...
-dece445 apply -0E+370 -> #c3fc000000000000 Clamped
-dece446 apply #c3fc000000000000 -> -0E+369
-dece447 apply -0E+384 -> #c3fc000000000000 Clamped
-dece448 apply #c3fc000000000000 -> -0E+369
-dece449 apply -0E+400 -> #c3fc000000000000 Clamped
-dece450 apply #c3fc000000000000 -> -0E+369
-dece451 apply -0E+500 -> #c3fc000000000000 Clamped
-dece452 apply #c3fc000000000000 -> -0E+369
-
--- Specials
-dece500 apply Infinity -> #7800000000000000
-dece501 apply #7878787878787878 -> #7800000000000000
-dece502 apply #7800000000000000 -> Infinity
-dece503 apply #7979797979797979 -> #7800000000000000
-dece504 apply #7900000000000000 -> Infinity
-dece505 apply #7a7a7a7a7a7a7a7a -> #7800000000000000
-dece506 apply #7a00000000000000 -> Infinity
-dece507 apply #7b7b7b7b7b7b7b7b -> #7800000000000000
-dece508 apply #7b00000000000000 -> Infinity
-
-dece509 apply NaN -> #7c00000000000000
-dece510 apply #7c7c7c7c7c7c7c7c -> #7c007c7c7c7c7c7c
-dece511 apply #7c00000000000000 -> NaN
-dece512 apply #7d7d7d7d7d7d7d7d -> #7c017d7d7d7d7d7d
-dece513 apply #7d00000000000000 -> NaN
-dece514 apply #7e7e7e7e7e7e7e7e -> #7e007e7e7e7e7c7e
-dece515 apply #7e00000000000000 -> sNaN
-dece516 apply #7f7f7f7f7f7f7f7f -> #7e007f7f7f7f7c7f
-dece517 apply #7f00000000000000 -> sNaN
-dece518 apply #7fffffffffffffff -> sNaN999999999999999
-dece519 apply #7fffffffffffffff -> #7e00ff3fcff3fcff
-
-dece520 apply -Infinity -> #f800000000000000
-dece521 apply #f878787878787878 -> #f800000000000000
-dece522 apply #f800000000000000 -> -Infinity
-dece523 apply #f979797979797979 -> #f800000000000000
-dece524 apply #f900000000000000 -> -Infinity
-dece525 apply #fa7a7a7a7a7a7a7a -> #f800000000000000
-dece526 apply #fa00000000000000 -> -Infinity
-dece527 apply #fb7b7b7b7b7b7b7b -> #f800000000000000
-dece528 apply #fb00000000000000 -> -Infinity
-
-dece529 apply -NaN -> #fc00000000000000
-dece530 apply #fc7c7c7c7c7c7c7c -> #fc007c7c7c7c7c7c
-dece531 apply #fc00000000000000 -> -NaN
-dece532 apply #fd7d7d7d7d7d7d7d -> #fc017d7d7d7d7d7d
-dece533 apply #fd00000000000000 -> -NaN
-dece534 apply #fe7e7e7e7e7e7e7e -> #fe007e7e7e7e7c7e
-dece535 apply #fe00000000000000 -> -sNaN
-dece536 apply #ff7f7f7f7f7f7f7f -> #fe007f7f7f7f7c7f
-dece537 apply #ff00000000000000 -> -sNaN
-dece538 apply #ffffffffffffffff -> -sNaN999999999999999
-dece539 apply #ffffffffffffffff -> #fe00ff3fcff3fcff
-
--- diagnostic NaNs
-dece540 apply NaN -> #7c00000000000000
-dece541 apply NaN0 -> #7c00000000000000
-dece542 apply NaN1 -> #7c00000000000001
-dece543 apply NaN12 -> #7c00000000000012
-dece544 apply NaN79 -> #7c00000000000079
-dece545 apply NaN12345 -> #7c000000000049c5
-dece546 apply NaN123456 -> #7c00000000028e56
-dece547 apply NaN799799 -> #7c000000000f7fdf
-dece548 apply NaN799799799799799 -> #7c03dff7fdff7fdf
-dece549 apply NaN999999999999999 -> #7c00ff3fcff3fcff
-dece550 apply NaN1234567890123456 -> #7c00000000000000 -- too many digits
-
--- fold-down full sequence
-dece601 apply 1E+384 -> #47fc000000000000 Clamped
-dece602 apply #47fc000000000000 -> 1.000000000000000E+384
-dece603 apply 1E+383 -> #43fc800000000000 Clamped
-dece604 apply #43fc800000000000 -> 1.00000000000000E+383
-dece605 apply 1E+382 -> #43fc100000000000 Clamped
-dece606 apply #43fc100000000000 -> 1.0000000000000E+382
-dece607 apply 1E+381 -> #43fc010000000000 Clamped
-dece608 apply #43fc010000000000 -> 1.000000000000E+381
-dece609 apply 1E+380 -> #43fc002000000000 Clamped
-dece610 apply #43fc002000000000 -> 1.00000000000E+380
-dece611 apply 1E+379 -> #43fc000400000000 Clamped
-dece612 apply #43fc000400000000 -> 1.0000000000E+379
-dece613 apply 1E+378 -> #43fc000040000000 Clamped
-dece614 apply #43fc000040000000 -> 1.000000000E+378
-dece615 apply 1E+377 -> #43fc000008000000 Clamped
-dece616 apply #43fc000008000000 -> 1.00000000E+377
-dece617 apply 1E+376 -> #43fc000001000000 Clamped
-dece618 apply #43fc000001000000 -> 1.0000000E+376
-dece619 apply 1E+375 -> #43fc000000100000 Clamped
-dece620 apply #43fc000000100000 -> 1.000000E+375
-dece621 apply 1E+374 -> #43fc000000020000 Clamped
-dece622 apply #43fc000000020000 -> 1.00000E+374
-dece623 apply 1E+373 -> #43fc000000004000 Clamped
-dece624 apply #43fc000000004000 -> 1.0000E+373
-dece625 apply 1E+372 -> #43fc000000000400 Clamped
-dece626 apply #43fc000000000400 -> 1.000E+372
-dece627 apply 1E+371 -> #43fc000000000080 Clamped
-dece628 apply #43fc000000000080 -> 1.00E+371
-dece629 apply 1E+370 -> #43fc000000000010 Clamped
-dece630 apply #43fc000000000010 -> 1.0E+370
-dece631 apply 1E+369 -> #43fc000000000001
-dece632 apply #43fc000000000001 -> 1E+369
-dece633 apply 1E+368 -> #43f8000000000001
-dece634 apply #43f8000000000001 -> 1E+368
--- same with 9s
-dece641 apply 9E+384 -> #77fc000000000000 Clamped
-dece642 apply #77fc000000000000 -> 9.000000000000000E+384
-dece643 apply 9E+383 -> #43fc8c0000000000 Clamped
-dece644 apply #43fc8c0000000000 -> 9.00000000000000E+383
-dece645 apply 9E+382 -> #43fc1a0000000000 Clamped
-dece646 apply #43fc1a0000000000 -> 9.0000000000000E+382
-dece647 apply 9E+381 -> #43fc090000000000 Clamped
-dece648 apply #43fc090000000000 -> 9.000000000000E+381
-dece649 apply 9E+380 -> #43fc002300000000 Clamped
-dece650 apply #43fc002300000000 -> 9.00000000000E+380
-dece651 apply 9E+379 -> #43fc000680000000 Clamped
-dece652 apply #43fc000680000000 -> 9.0000000000E+379
-dece653 apply 9E+378 -> #43fc000240000000 Clamped
-dece654 apply #43fc000240000000 -> 9.000000000E+378
-dece655 apply 9E+377 -> #43fc000008c00000 Clamped
-dece656 apply #43fc000008c00000 -> 9.00000000E+377
-dece657 apply 9E+376 -> #43fc000001a00000 Clamped
-dece658 apply #43fc000001a00000 -> 9.0000000E+376
-dece659 apply 9E+375 -> #43fc000000900000 Clamped
-dece660 apply #43fc000000900000 -> 9.000000E+375
-dece661 apply 9E+374 -> #43fc000000023000 Clamped
-dece662 apply #43fc000000023000 -> 9.00000E+374
-dece663 apply 9E+373 -> #43fc000000006800 Clamped
-dece664 apply #43fc000000006800 -> 9.0000E+373
-dece665 apply 9E+372 -> #43fc000000002400 Clamped
-dece666 apply #43fc000000002400 -> 9.000E+372
-dece667 apply 9E+371 -> #43fc00000000008c Clamped
-dece668 apply #43fc00000000008c -> 9.00E+371
-dece669 apply 9E+370 -> #43fc00000000001a Clamped
-dece670 apply #43fc00000000001a -> 9.0E+370
-dece671 apply 9E+369 -> #43fc000000000009
-dece672 apply #43fc000000000009 -> 9E+369
-dece673 apply 9E+368 -> #43f8000000000009
-dece674 apply #43f8000000000009 -> 9E+368
-
-
--- Selected DPD codes
-dece700 apply #2238000000000000 -> 0
-dece701 apply #2238000000000009 -> 9
-dece702 apply #2238000000000010 -> 10
-dece703 apply #2238000000000019 -> 19
-dece704 apply #2238000000000020 -> 20
-dece705 apply #2238000000000029 -> 29
-dece706 apply #2238000000000030 -> 30
-dece707 apply #2238000000000039 -> 39
-dece708 apply #2238000000000040 -> 40
-dece709 apply #2238000000000049 -> 49
-dece710 apply #2238000000000050 -> 50
-dece711 apply #2238000000000059 -> 59
-dece712 apply #2238000000000060 -> 60
-dece713 apply #2238000000000069 -> 69
-dece714 apply #2238000000000070 -> 70
-dece715 apply #2238000000000071 -> 71
-dece716 apply #2238000000000072 -> 72
-dece717 apply #2238000000000073 -> 73
-dece718 apply #2238000000000074 -> 74
-dece719 apply #2238000000000075 -> 75
-dece720 apply #2238000000000076 -> 76
-dece721 apply #2238000000000077 -> 77
-dece722 apply #2238000000000078 -> 78
-dece723 apply #2238000000000079 -> 79
-
-dece730 apply #223800000000029e -> 994
-dece731 apply #223800000000029f -> 995
-dece732 apply #22380000000002a0 -> 520
-dece733 apply #22380000000002a1 -> 521
-
--- DPD: one of each of the huffman groups
-dece740 apply #22380000000003f7 -> 777
-dece741 apply #22380000000003f8 -> 778
-dece742 apply #22380000000003eb -> 787
-dece743 apply #223800000000037d -> 877
-dece744 apply #223800000000039f -> 997
-dece745 apply #22380000000003bf -> 979
-dece746 apply #22380000000003df -> 799
-dece747 apply #223800000000006e -> 888
-
-
--- DPD all-highs cases (includes the 24 redundant codes)
-dece750 apply #223800000000006e -> 888
-dece751 apply #223800000000016e -> 888
-dece752 apply #223800000000026e -> 888
-dece753 apply #223800000000036e -> 888
-dece754 apply #223800000000006f -> 889
-dece755 apply #223800000000016f -> 889
-dece756 apply #223800000000026f -> 889
-dece757 apply #223800000000036f -> 889
-
-dece760 apply #223800000000007e -> 898
-dece761 apply #223800000000017e -> 898
-dece762 apply #223800000000027e -> 898
-dece763 apply #223800000000037e -> 898
-dece764 apply #223800000000007f -> 899
-dece765 apply #223800000000017f -> 899
-dece766 apply #223800000000027f -> 899
-dece767 apply #223800000000037f -> 899
-
-dece770 apply #22380000000000ee -> 988
-dece771 apply #22380000000001ee -> 988
-dece772 apply #22380000000002ee -> 988
-dece773 apply #22380000000003ee -> 988
-dece774 apply #22380000000000ef -> 989
-dece775 apply #22380000000001ef -> 989
-dece776 apply #22380000000002ef -> 989
-dece777 apply #22380000000003ef -> 989
-
-dece780 apply #22380000000000fe -> 998
-dece781 apply #22380000000001fe -> 998
-dece782 apply #22380000000002fe -> 998
-dece783 apply #22380000000003fe -> 998
-dece784 apply #22380000000000ff -> 999
-dece785 apply #22380000000001ff -> 999
-dece786 apply #22380000000002ff -> 999
-dece787 apply #22380000000003ff -> 999
-
Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/divide.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/divide.decTest (original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/divide.decTest Fri Sep 21 03:17:09 2007
@@ -1,6 +1,6 @@
------------------------------------------------------------------------
-- divide.decTest -- decimal division --
--- Copyright (c) IBM Corporation, 1981, 2004. All rights reserved. --
+-- Copyright (c) IBM Corporation, 1981, 2007. All rights reserved. --
------------------------------------------------------------------------
-- Please see the document "General Decimal Arithmetic Testcases" --
-- at http://www2.hursley.ibm.com/decimal for the description of --
@@ -17,7 +17,7 @@
-- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
-- mfc at uk.ibm.com --
------------------------------------------------------------------------
-version: 2.39
+version: 2.56
extended: 1
precision: 9
@@ -47,41 +47,45 @@
divx018 divide 2. 2 -> 1
divx019 divide 20 20 -> 1
-divx020 divide 187 187 -> 1
-divx021 divide 5 2 -> 2.5
-divx022 divide 5 2.0 -> 2.5
-divx023 divide 5 2.000 -> 2.5
-divx024 divide 5 0.20 -> 25
-divx025 divide 5 0.200 -> 25
-divx026 divide 10 1 -> 10
-divx027 divide 100 1 -> 100
-divx028 divide 1000 1 -> 1000
-divx029 divide 1000 100 -> 10
-
-divx030 divide 1 2 -> 0.5
-divx031 divide 1 4 -> 0.25
-divx032 divide 1 8 -> 0.125
-divx033 divide 1 16 -> 0.0625
-divx034 divide 1 32 -> 0.03125
-divx035 divide 1 64 -> 0.015625
-divx040 divide 1 -2 -> -0.5
-divx041 divide 1 -4 -> -0.25
-divx042 divide 1 -8 -> -0.125
-divx043 divide 1 -16 -> -0.0625
-divx044 divide 1 -32 -> -0.03125
-divx045 divide 1 -64 -> -0.015625
-divx050 divide -1 2 -> -0.5
-divx051 divide -1 4 -> -0.25
-divx052 divide -1 8 -> -0.125
-divx053 divide -1 16 -> -0.0625
-divx054 divide -1 32 -> -0.03125
-divx055 divide -1 64 -> -0.015625
-divx060 divide -1 -2 -> 0.5
-divx061 divide -1 -4 -> 0.25
-divx062 divide -1 -8 -> 0.125
-divx063 divide -1 -16 -> 0.0625
-divx064 divide -1 -32 -> 0.03125
-divx065 divide -1 -64 -> 0.015625
+divx020 divide 187 187 -> 1
+divx021 divide 5 2 -> 2.5
+divx022 divide 50 20 -> 2.5
+divx023 divide 500 200 -> 2.5
+divx024 divide 50.0 20.0 -> 2.5
+divx025 divide 5.00 2.00 -> 2.5
+divx026 divide 5 2.0 -> 2.5
+divx027 divide 5 2.000 -> 2.5
+divx028 divide 5 0.20 -> 25
+divx029 divide 5 0.200 -> 25
+divx030 divide 10 1 -> 10
+divx031 divide 100 1 -> 100
+divx032 divide 1000 1 -> 1000
+divx033 divide 1000 100 -> 10
+
+divx035 divide 1 2 -> 0.5
+divx036 divide 1 4 -> 0.25
+divx037 divide 1 8 -> 0.125
+divx038 divide 1 16 -> 0.0625
+divx039 divide 1 32 -> 0.03125
+divx040 divide 1 64 -> 0.015625
+divx041 divide 1 -2 -> -0.5
+divx042 divide 1 -4 -> -0.25
+divx043 divide 1 -8 -> -0.125
+divx044 divide 1 -16 -> -0.0625
+divx045 divide 1 -32 -> -0.03125
+divx046 divide 1 -64 -> -0.015625
+divx047 divide -1 2 -> -0.5
+divx048 divide -1 4 -> -0.25
+divx049 divide -1 8 -> -0.125
+divx050 divide -1 16 -> -0.0625
+divx051 divide -1 32 -> -0.03125
+divx052 divide -1 64 -> -0.015625
+divx053 divide -1 -2 -> 0.5
+divx054 divide -1 -4 -> 0.25
+divx055 divide -1 -8 -> 0.125
+divx056 divide -1 -16 -> 0.0625
+divx057 divide -1 -32 -> 0.03125
+divx058 divide -1 -64 -> 0.015625
divx070 divide 999999999 1 -> 999999999
divx071 divide 999999999.4 1 -> 999999999 Inexact Rounded
@@ -763,9 +767,9 @@
divx964 divide 1e-600000000 1e+400000005 -> 1E-1000000005 Subnormal
divx965 divide 1e-600000000 1e+400000006 -> 1E-1000000006 Subnormal
divx966 divide 1e-600000000 1e+400000007 -> 1E-1000000007 Subnormal
-divx967 divide 1e-600000000 1e+400000008 -> 0E-1000000007 Underflow Subnormal Inexact Rounded
-divx968 divide 1e-600000000 1e+400000009 -> 0E-1000000007 Underflow Subnormal Inexact Rounded
-divx969 divide 1e-600000000 1e+400000010 -> 0E-1000000007 Underflow Subnormal Inexact Rounded
+divx967 divide 1e-600000000 1e+400000008 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+divx968 divide 1e-600000000 1e+400000009 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+divx969 divide 1e-600000000 1e+400000010 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
-- [no equivalent of 'subnormal' for overflow]
divx970 divide 1e+600000000 1e-400000001 -> Infinity Overflow Inexact Rounded
divx971 divide 1e+600000000 1e-400000002 -> Infinity Overflow Inexact Rounded
@@ -779,10 +783,10 @@
divx979 divide 1e+600000000 1e-400000010 -> Infinity Overflow Inexact Rounded
-- Sign after overflow and underflow
-divx980 divide 1e-600000000 1e+400000009 -> 0E-1000000007 Underflow Subnormal Inexact Rounded
-divx981 divide 1e-600000000 -1e+400000009 -> -0E-1000000007 Underflow Subnormal Inexact Rounded
-divx982 divide -1e-600000000 1e+400000009 -> -0E-1000000007 Underflow Subnormal Inexact Rounded
-divx983 divide -1e-600000000 -1e+400000009 -> 0E-1000000007 Underflow Subnormal Inexact Rounded
+divx980 divide 1e-600000000 1e+400000009 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+divx981 divide 1e-600000000 -1e+400000009 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+divx982 divide -1e-600000000 1e+400000009 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+divx983 divide -1e-600000000 -1e+400000009 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
divx984 divide 1e+600000000 1e-400000009 -> Infinity Overflow Inexact Rounded
divx985 divide 1e+600000000 -1e-400000009 -> -Infinity Overflow Inexact Rounded
divx986 divide -1e+600000000 1e-400000009 -> -Infinity Overflow Inexact Rounded
@@ -812,6 +816,38 @@
-- 1.465811965811965811965811965811965811966E+7000
divx1010 divide 343E6000 234E-1000 -> Infinity Overflow Inexact Rounded
+precision: 34
+rounding: half_up
+maxExponent: 6144
+minExponent: -6143
+
+-- Examples from SQL proposal (Krishna Kulkarni)
+precision: 7
+divx1021 divide 1E0 1E0 -> 1
+divx1022 divide 1E0 2E0 -> 0.5
+divx1023 divide 1E0 3E0 -> 0.3333333 Inexact Rounded
+divx1024 divide 100E-2 1000E-3 -> 1
+divx1025 divide 24E-1 2E0 -> 1.2
+divx1026 divide 2400E-3 2E0 -> 1.200
+divx1027 divide 5E0 2E0 -> 2.5
+divx1028 divide 5E0 20E-1 -> 2.5
+divx1029 divide 5E0 2000E-3 -> 2.5
+divx1030 divide 5E0 2E-1 -> 25
+divx1031 divide 5E0 20E-2 -> 25
+divx1032 divide 480E-2 3E0 -> 1.60
+divx1033 divide 47E-1 2E0 -> 2.35
+
+-- ECMAScript bad examples
+rounding: half_down
+precision: 7
+divx1050 divide 5 9 -> 0.5555556 Inexact Rounded
+rounding: half_even
+divx1051 divide 5 11 -> 0.4545455 Inexact Rounded
+
+-- payload decapitate
+precision: 5
+divx1055 divide sNaN987654321 1 -> NaN54321 Invalid_operation
+
-- Null tests
divx9998 divide 10 # -> NaN Invalid_operation
divx9999 divide # 10 -> NaN Invalid_operation
Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/divideint.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/divideint.decTest (original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/divideint.decTest Fri Sep 21 03:17:09 2007
@@ -1,6 +1,6 @@
------------------------------------------------------------------------
-- divideint.decTest -- decimal integer division --
--- Copyright (c) IBM Corporation, 1981, 2004. All rights reserved. --
+-- Copyright (c) IBM Corporation, 1981, 2007. All rights reserved. --
------------------------------------------------------------------------
-- Please see the document "General Decimal Arithmetic Testcases" --
-- at http://www2.hursley.ibm.com/decimal for the description of --
@@ -17,7 +17,7 @@
-- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
-- mfc at uk.ibm.com --
------------------------------------------------------------------------
-version: 2.39
+version: 2.56
extended: 1
precision: 9
@@ -234,6 +234,22 @@
dvix287 divideint 0.1 9999e-999999997 -> NaN Division_impossible
dvix288 divideint 0.1 99999e-999999997 -> NaN Division_impossible
+-- GD edge cases: lhs smaller than rhs but more digits
+dvix301 divideint 0.9 2 -> 0
+dvix302 divideint 0.9 2.0 -> 0
+dvix303 divideint 0.9 2.1 -> 0
+dvix304 divideint 0.9 2.00 -> 0
+dvix305 divideint 0.9 2.01 -> 0
+dvix306 divideint 0.12 1 -> 0
+dvix307 divideint 0.12 1.0 -> 0
+dvix308 divideint 0.12 1.00 -> 0
+dvix309 divideint 0.12 1.0 -> 0
+dvix310 divideint 0.12 1.00 -> 0
+dvix311 divideint 0.12 2 -> 0
+dvix312 divideint 0.12 2.0 -> 0
+dvix313 divideint 0.12 2.1 -> 0
+dvix314 divideint 0.12 2.00 -> 0
+dvix315 divideint 0.12 2.01 -> 0
-- overflow and underflow tests [from divide]
maxexponent: 999999999
Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/inexact.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/inexact.decTest (original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/inexact.decTest Fri Sep 21 03:17:09 2007
@@ -1,6 +1,6 @@
------------------------------------------------------------------------
-- inexact.decTest -- decimal inexact and rounded edge cases --
--- Copyright (c) IBM Corporation, 1981, 2003. All rights reserved. --
+-- Copyright (c) IBM Corporation, 1981, 2007. All rights reserved. --
------------------------------------------------------------------------
-- Please see the document "General Decimal Arithmetic Testcases" --
-- at http://www2.hursley.ibm.com/decimal for the description of --
@@ -17,7 +17,7 @@
-- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
-- mfc at uk.ibm.com --
------------------------------------------------------------------------
-version: 2.39
+version: 2.56
extended: 1
precision: 9
Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/max.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/max.decTest (original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/max.decTest Fri Sep 21 03:17:09 2007
@@ -1,6 +1,6 @@
------------------------------------------------------------------------
-- max.decTest -- decimal maximum --
--- Copyright (c) IBM Corporation, 1981, 2004. All rights reserved. --
+-- Copyright (c) IBM Corporation, 1981, 2007. All rights reserved. --
------------------------------------------------------------------------
-- Please see the document "General Decimal Arithmetic Testcases" --
-- at http://www2.hursley.ibm.com/decimal for the description of --
@@ -17,7 +17,7 @@
-- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
-- mfc at uk.ibm.com --
------------------------------------------------------------------------
-version: 2.39
+version: 2.56
-- we assume that base comparison is tested in compare.decTest, so
-- these mainly cover special cases and rounding
@@ -331,6 +331,33 @@
maxx466 max -1000 -1E+3 -> -1000
maxx467 max -1E+3 -1000 -> -1000
+-- rounding (results treated as though plus)
+maxexponent: 999999999
+minexponent: -999999999
+precision: 3
+
+maxx470 max 1 .5 -> 1
+maxx471 max 10 5 -> 10
+maxx472 max 100 50 -> 100
+maxx473 max 1000 500 -> 1.00E+3 Rounded
+maxx474 max 10000 5000 -> 1.00E+4 Rounded
+maxx475 max 6 .5 -> 6
+maxx476 max 66 5 -> 66
+maxx477 max 666 50 -> 666
+maxx478 max 6666 500 -> 6.67E+3 Rounded Inexact
+maxx479 max 66666 5000 -> 6.67E+4 Rounded Inexact
+maxx480 max 33333 5000 -> 3.33E+4 Rounded Inexact
+maxx481 max .5 1 -> 1
+maxx482 max .5 10 -> 10
+maxx483 max .5 100 -> 100
+maxx484 max .5 1000 -> 1.00E+3 Rounded
+maxx485 max .5 10000 -> 1.00E+4 Rounded
+maxx486 max .5 6 -> 6
+maxx487 max .5 66 -> 66
+maxx488 max .5 666 -> 666
+maxx489 max .5 6666 -> 6.67E+3 Rounded Inexact
+maxx490 max .5 66666 -> 6.67E+4 Rounded Inexact
+maxx491 max .5 33333 -> 3.33E+4 Rounded Inexact
-- overflow tests
maxexponent: 999999999
@@ -348,13 +375,13 @@
maxx512 max 0.10E-999 0 -> 1.0E-1000 Subnormal
maxx513 max 0.100E-999 0 -> 1.0E-1000 Subnormal Rounded
maxx514 max 0.01E-999 0 -> 1E-1001 Subnormal
--- next is rounded to Emin
+-- next is rounded to Nmin
maxx515 max 0.999E-999 0 -> 1.00E-999 Inexact Rounded Subnormal Underflow
maxx516 max 0.099E-999 0 -> 1.0E-1000 Inexact Rounded Subnormal Underflow
maxx517 max 0.009E-999 0 -> 1E-1001 Inexact Rounded Subnormal Underflow
-maxx518 max 0.001E-999 0 -> 0E-1001 Inexact Rounded Subnormal Underflow
-maxx519 max 0.0009E-999 0 -> 0E-1001 Inexact Rounded Subnormal Underflow
-maxx520 max 0.0001E-999 0 -> 0E-1001 Inexact Rounded Subnormal Underflow
+maxx518 max 0.001E-999 0 -> 0E-1001 Inexact Rounded Subnormal Underflow Clamped
+maxx519 max 0.0009E-999 0 -> 0E-1001 Inexact Rounded Subnormal Underflow Clamped
+maxx520 max 0.0001E-999 0 -> 0E-1001 Inexact Rounded Subnormal Underflow Clamped
maxx530 max -1.00E-999 0 -> 0
maxx531 max -0.1E-999 0 -> 0
@@ -368,6 +395,27 @@
maxx539 max -0.0009E-999 0 -> 0
maxx540 max -0.0001E-999 0 -> 0
+-- misalignment traps for little-endian
+precision: 9
+maxx551 max 1.0 0.1 -> 1.0
+maxx552 max 0.1 1.0 -> 1.0
+maxx553 max 10.0 0.1 -> 10.0
+maxx554 max 0.1 10.0 -> 10.0
+maxx555 max 100 1.0 -> 100
+maxx556 max 1.0 100 -> 100
+maxx557 max 1000 10.0 -> 1000
+maxx558 max 10.0 1000 -> 1000
+maxx559 max 10000 100.0 -> 10000
+maxx560 max 100.0 10000 -> 10000
+maxx661 max 100000 1000.0 -> 100000
+maxx662 max 1000.0 100000 -> 100000
+maxx663 max 1000000 10000.0 -> 1000000
+maxx664 max 10000.0 1000000 -> 1000000
+
+-- payload decapitate
+precision: 5
+maxx670 max 11 -sNaN12345678901 -> -NaN78901 Invalid_operation
+
-- Null tests
maxx900 max 10 # -> NaN Invalid_operation
maxx901 max # 10 -> NaN Invalid_operation
Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/min.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/min.decTest (original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/min.decTest Fri Sep 21 03:17:09 2007
@@ -1,6 +1,6 @@
------------------------------------------------------------------------
-- min.decTest -- decimal minimum --
--- Copyright (c) IBM Corporation, 1981, 2004. All rights reserved. --
+-- Copyright (c) IBM Corporation, 1981, 2007. All rights reserved. --
------------------------------------------------------------------------
-- Please see the document "General Decimal Arithmetic Testcases" --
-- at http://www2.hursley.ibm.com/decimal for the description of --
@@ -17,7 +17,7 @@
-- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
-- mfc at uk.ibm.com --
------------------------------------------------------------------------
-version: 2.39
+version: 2.56
-- we assume that base comparison is tested in compare.decTest, so
-- these mainly cover special cases and rounding
@@ -320,6 +320,34 @@
mnmx466 min -1000 -1E+3 -> -1E+3
mnmx467 min -1E+3 -1000 -> -1E+3
+-- rounding (results treated as though plus)
+maxexponent: 999999999
+minexponent: -999999999
+precision: 3
+
+mnmx470 min 1 5 -> 1
+mnmx471 min 10 50 -> 10
+mnmx472 min 100 500 -> 100
+mnmx473 min 1000 5000 -> 1.00E+3 Rounded
+mnmx474 min 10000 50000 -> 1.00E+4 Rounded
+mnmx475 min 6 50 -> 6
+mnmx476 min 66 500 -> 66
+mnmx477 min 666 5000 -> 666
+mnmx478 min 6666 50000 -> 6.67E+3 Rounded Inexact
+mnmx479 min 66666 500000 -> 6.67E+4 Rounded Inexact
+mnmx480 min 33333 500000 -> 3.33E+4 Rounded Inexact
+mnmx481 min 75401 1 -> 1
+mnmx482 min 75402 10 -> 10
+mnmx483 min 75403 100 -> 100
+mnmx484 min 75404 1000 -> 1.00E+3 Rounded
+mnmx485 min 75405 10000 -> 1.00E+4 Rounded
+mnmx486 min 75406 6 -> 6
+mnmx487 min 75407 66 -> 66
+mnmx488 min 75408 666 -> 666
+mnmx489 min 75409 6666 -> 6.67E+3 Rounded Inexact
+mnmx490 min 75410 66666 -> 6.67E+4 Rounded Inexact
+mnmx491 min 75411 33333 -> 3.33E+4 Rounded Inexact
+
-- overflow tests
maxexponent: 999999999
@@ -349,14 +377,30 @@
mnmx532 min -0.10E-999 0 -> -1.0E-1000 Subnormal
mnmx533 min -0.100E-999 0 -> -1.0E-1000 Subnormal Rounded
mnmx534 min -0.01E-999 0 -> -1E-1001 Subnormal
--- next is rounded to Emin
+-- next is rounded to Nmin
mnmx535 min -0.999E-999 0 -> -1.00E-999 Inexact Rounded Subnormal Underflow
mnmx536 min -0.099E-999 0 -> -1.0E-1000 Inexact Rounded Subnormal Underflow
mnmx537 min -0.009E-999 0 -> -1E-1001 Inexact Rounded Subnormal Underflow
-mnmx538 min -0.001E-999 0 -> -0E-1001 Inexact Rounded Subnormal Underflow
-mnmx539 min -0.0009E-999 0 -> -0E-1001 Inexact Rounded Subnormal Underflow
-mnmx540 min -0.0001E-999 0 -> -0E-1001 Inexact Rounded Subnormal Underflow
+mnmx538 min -0.001E-999 0 -> -0E-1001 Inexact Rounded Subnormal Underflow Clamped
+mnmx539 min -0.0009E-999 0 -> -0E-1001 Inexact Rounded Subnormal Underflow Clamped
+mnmx540 min -0.0001E-999 0 -> -0E-1001 Inexact Rounded Subnormal Underflow Clamped
+-- misalignment traps for little-endian
+precision: 9
+mnmx551 min 1.0 0.1 -> 0.1
+mnmx552 min 0.1 1.0 -> 0.1
+mnmx553 min 10.0 0.1 -> 0.1
+mnmx554 min 0.1 10.0 -> 0.1
+mnmx555 min 100 1.0 -> 1.0
+mnmx556 min 1.0 100 -> 1.0
+mnmx557 min 1000 10.0 -> 10.0
+mnmx558 min 10.0 1000 -> 10.0
+mnmx559 min 10000 100.0 -> 100.0
+mnmx560 min 100.0 10000 -> 100.0
+mnmx561 min 100000 1000.0 -> 1000.0
+mnmx562 min 1000.0 100000 -> 1000.0
+mnmx563 min 1000000 10000.0 -> 10000.0
+mnmx564 min 10000.0 1000000 -> 10000.0
-- Null tests
mnm900 min 10 # -> NaN Invalid_operation
Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/minus.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/minus.decTest (original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/minus.decTest Fri Sep 21 03:17:09 2007
@@ -1,6 +1,6 @@
------------------------------------------------------------------------
-- minus.decTest -- decimal negation --
--- Copyright (c) IBM Corporation, 1981, 2004. All rights reserved. --
+-- Copyright (c) IBM Corporation, 1981, 2007. All rights reserved. --
------------------------------------------------------------------------
-- Please see the document "General Decimal Arithmetic Testcases" --
-- at http://www2.hursley.ibm.com/decimal for the description of --
@@ -17,7 +17,7 @@
-- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
-- mfc at uk.ibm.com --
------------------------------------------------------------------------
-version: 2.39
+version: 2.56
-- This set of tests primarily tests the existence of the operator.
-- Subtraction, rounding, and more overflows are tested elsewhere.
@@ -127,9 +127,9 @@
minx115 minus 0.999E-999 -> -1.00E-999 Inexact Rounded Subnormal Underflow
minx116 minus 0.099E-999 -> -1.0E-1000 Inexact Rounded Subnormal Underflow
minx117 minus 0.009E-999 -> -1E-1001 Inexact Rounded Subnormal Underflow
-minx118 minus 0.001E-999 -> -0E-1001 Inexact Rounded Subnormal Underflow
-minx119 minus 0.0009E-999 -> -0E-1001 Inexact Rounded Subnormal Underflow
-minx120 minus 0.0001E-999 -> -0E-1001 Inexact Rounded Subnormal Underflow
+minx118 minus 0.001E-999 -> -0E-1001 Inexact Rounded Subnormal Underflow Clamped
+minx119 minus 0.0009E-999 -> -0E-1001 Inexact Rounded Subnormal Underflow Clamped
+minx120 minus 0.0001E-999 -> -0E-1001 Inexact Rounded Subnormal Underflow Clamped
minx130 minus -1.00E-999 -> 1.00E-999
minx131 minus -0.1E-999 -> 1E-1000 Subnormal
@@ -140,9 +140,9 @@
minx135 minus -0.999E-999 -> 1.00E-999 Inexact Rounded Subnormal Underflow
minx136 minus -0.099E-999 -> 1.0E-1000 Inexact Rounded Subnormal Underflow
minx137 minus -0.009E-999 -> 1E-1001 Inexact Rounded Subnormal Underflow
-minx138 minus -0.001E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow
-minx139 minus -0.0009E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow
-minx140 minus -0.0001E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow
+minx138 minus -0.001E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow Clamped
+minx139 minus -0.0009E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow Clamped
+minx140 minus -0.0001E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow Clamped
-- long operand checks
Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/multiply.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/multiply.decTest (original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/multiply.decTest Fri Sep 21 03:17:09 2007
@@ -1,6 +1,6 @@
------------------------------------------------------------------------
-- multiply.decTest -- decimal multiplication --
--- Copyright (c) IBM Corporation, 1981, 2004. All rights reserved. --
+-- Copyright (c) IBM Corporation, 1981, 2007. All rights reserved. --
------------------------------------------------------------------------
-- Please see the document "General Decimal Arithmetic Testcases" --
-- at http://www2.hursley.ibm.com/decimal for the description of --
@@ -17,7 +17,7 @@
-- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
-- mfc at uk.ibm.com --
------------------------------------------------------------------------
-version: 2.39
+version: 2.56
extended: 1
precision: 9
@@ -44,21 +44,28 @@
mulx015 multiply 2.50 4 -> 10.00
precision: 6
mulx016 multiply 2.50 4 -> 10.00
-mulx017 multiply 9.999999999 9.999999999 -> 100.000 Inexact Rounded
+mulx017 multiply 9.999999999 9.999999999 -> 100.000 Inexact Rounded
+mulx018 multiply 9.999999999 -9.999999999 -> -100.000 Inexact Rounded
+mulx019 multiply -9.999999999 9.999999999 -> -100.000 Inexact Rounded
+mulx020 multiply -9.999999999 -9.999999999 -> 100.000 Inexact Rounded
-- 1999.12.21: next one is a edge case if intermediate longs are used
precision: 15
-mulx019 multiply 999999999999 9765625 -> 9.76562499999023E+18 Inexact Rounded
+mulx059 multiply 999999999999 9765625 -> 9.76562499999023E+18 Inexact Rounded
precision: 30
mulx160 multiply 999999999999 9765625 -> 9765624999990234375
precision: 9
-----
-- zeros, etc.
-mulx020 multiply 0 0 -> 0
-mulx021 multiply 0 -0 -> -0
-mulx022 multiply -0 0 -> -0
-mulx023 multiply -0 -0 -> 0
+mulx021 multiply 0 0 -> 0
+mulx022 multiply 0 -0 -> -0
+mulx023 multiply -0 0 -> -0
+mulx024 multiply -0 -0 -> 0
+mulx025 multiply -0.0 -0.0 -> 0.00
+mulx026 multiply -0.0 -0.0 -> 0.00
+mulx027 multiply -0.0 -0.0 -> 0.00
+mulx028 multiply -0.0 -0.0 -> 0.00
mulx030 multiply 5.00 1E-3 -> 0.00500
mulx031 multiply 00.00 0.000 -> 0.00000
mulx032 multiply 00.00 0E-3 -> 0.00000 -- rhs is 0
@@ -94,17 +101,17 @@
-- test some intermediate lengths
precision: 9
-mulx080 multiply 0.1 123456789 -> 12345678.9
-mulx081 multiply 0.1 1234567891 -> 123456789 Inexact Rounded
-mulx082 multiply 0.1 12345678912 -> 1.23456789E+9 Inexact Rounded
-mulx083 multiply 0.1 12345678912345 -> 1.23456789E+12 Inexact Rounded
-mulx084 multiply 0.1 123456789 -> 12345678.9
+mulx080 multiply 0.1 123456789 -> 12345678.9
+mulx081 multiply 0.1 1234567891 -> 123456789 Inexact Rounded
+mulx082 multiply 0.1 12345678912 -> 1.23456789E+9 Inexact Rounded
+mulx083 multiply 0.1 12345678912345 -> 1.23456789E+12 Inexact Rounded
+mulx084 multiply 0.1 123456789 -> 12345678.9
precision: 8
-mulx085 multiply 0.1 12345678912 -> 1.2345679E+9 Inexact Rounded
-mulx086 multiply 0.1 12345678912345 -> 1.2345679E+12 Inexact Rounded
+mulx085 multiply 0.1 12345678912 -> 1.2345679E+9 Inexact Rounded
+mulx086 multiply 0.1 12345678912345 -> 1.2345679E+12 Inexact Rounded
precision: 7
-mulx087 multiply 0.1 12345678912 -> 1.234568E+9 Inexact Rounded
-mulx088 multiply 0.1 12345678912345 -> 1.234568E+12 Inexact Rounded
+mulx087 multiply 0.1 12345678912 -> 1.234568E+9 Inexact Rounded
+mulx088 multiply 0.1 12345678912345 -> 1.234568E+12 Inexact Rounded
precision: 9
mulx090 multiply 123456789 0.1 -> 12345678.9
@@ -280,6 +287,41 @@
precision: 1
mulx278 multiply 30269.587755640502150977251770554 4.8046009735990873395936309640543 -> 1E+5 Inexact Rounded
+-- test some edge cases with exact rounding
+maxexponent: 9999
+minexponent: -9999
+precision: 9
+mulx301 multiply 9 9 -> 81
+mulx302 multiply 9 90 -> 810
+mulx303 multiply 9 900 -> 8100
+mulx304 multiply 9 9000 -> 81000
+mulx305 multiply 9 90000 -> 810000
+mulx306 multiply 9 900000 -> 8100000
+mulx307 multiply 9 9000000 -> 81000000
+mulx308 multiply 9 90000000 -> 810000000
+mulx309 multiply 9 900000000 -> 8.10000000E+9 Rounded
+mulx310 multiply 9 9000000000 -> 8.10000000E+10 Rounded
+mulx311 multiply 9 90000000000 -> 8.10000000E+11 Rounded
+mulx312 multiply 9 900000000000 -> 8.10000000E+12 Rounded
+mulx313 multiply 9 9000000000000 -> 8.10000000E+13 Rounded
+mulx314 multiply 9 90000000000000 -> 8.10000000E+14 Rounded
+mulx315 multiply 9 900000000000000 -> 8.10000000E+15 Rounded
+mulx316 multiply 9 9000000000000000 -> 8.10000000E+16 Rounded
+mulx317 multiply 9 90000000000000000 -> 8.10000000E+17 Rounded
+mulx318 multiply 9 900000000000000000 -> 8.10000000E+18 Rounded
+mulx319 multiply 9 9000000000000000000 -> 8.10000000E+19 Rounded
+mulx320 multiply 9 90000000000000000000 -> 8.10000000E+20 Rounded
+mulx321 multiply 9 900000000000000000000 -> 8.10000000E+21 Rounded
+mulx322 multiply 9 9000000000000000000000 -> 8.10000000E+22 Rounded
+mulx323 multiply 9 90000000000000000000000 -> 8.10000000E+23 Rounded
+
+-- fastpath breakers
+precision: 29
+mulx330 multiply 1.491824697641270317824852952837224 1.105170918075647624811707826490246514675628614562883537345747603 -> 1.6487212707001281468486507878 Inexact Rounded
+precision: 55
+mulx331 multiply 0.8958341352965282506768545828765117803873717284891040428 0.8958341352965282506768545828765117803873717284891040428 -> 0.8025187979624784829842553829934069955890983696752228299 Inexact Rounded
+
+
-- tryzeros cases
precision: 7
rounding: half_up
@@ -486,10 +528,10 @@
mulx752 multiply 1e+777777777 -1e+411111111 -> -Infinity Overflow Inexact Rounded
mulx753 multiply -1e+777777777 1e+411111111 -> -Infinity Overflow Inexact Rounded
mulx754 multiply -1e+777777777 -1e+411111111 -> Infinity Overflow Inexact Rounded
-mulx755 multiply 1e-777777777 1e-411111111 -> 0E-1000000007 Underflow Subnormal Inexact Rounded
-mulx756 multiply 1e-777777777 -1e-411111111 -> -0E-1000000007 Underflow Subnormal Inexact Rounded
-mulx757 multiply -1e-777777777 1e-411111111 -> -0E-1000000007 Underflow Subnormal Inexact Rounded
-mulx758 multiply -1e-777777777 -1e-411111111 -> 0E-1000000007 Underflow Subnormal Inexact Rounded
+mulx755 multiply 1e-777777777 1e-411111111 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+mulx756 multiply 1e-777777777 -1e-411111111 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+mulx757 multiply -1e-777777777 1e-411111111 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+mulx758 multiply -1e-777777777 -1e-411111111 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
-- 'subnormal' boundary (all hard underflow or overflow in base arithemtic)
precision: 9
@@ -500,9 +542,9 @@
mulx764 multiply 1e-600000000 1e-400000005 -> 1E-1000000005 Subnormal
mulx765 multiply 1e-600000000 1e-400000006 -> 1E-1000000006 Subnormal
mulx766 multiply 1e-600000000 1e-400000007 -> 1E-1000000007 Subnormal
-mulx767 multiply 1e-600000000 1e-400000008 -> 0E-1000000007 Underflow Subnormal Inexact Rounded
-mulx768 multiply 1e-600000000 1e-400000009 -> 0E-1000000007 Underflow Subnormal Inexact Rounded
-mulx769 multiply 1e-600000000 1e-400000010 -> 0E-1000000007 Underflow Subnormal Inexact Rounded
+mulx767 multiply 1e-600000000 1e-400000008 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+mulx768 multiply 1e-600000000 1e-400000009 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+mulx769 multiply 1e-600000000 1e-400000010 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
-- [no equivalent of 'subnormal' for overflow]
mulx770 multiply 1e+600000000 1e+400000001 -> Infinity Overflow Inexact Rounded
mulx771 multiply 1e+600000000 1e+400000002 -> Infinity Overflow Inexact Rounded
@@ -520,31 +562,31 @@
mulx780 multiply 1e-600000000 1e-400000007 -> 1E-1000000007 Subnormal
mulx781 multiply 1e-600000000 1e-400000008 -> 1E-1000000008 Subnormal
mulx782 multiply 1e-600000000 1e-400000097 -> 1E-1000000097 Subnormal
-mulx783 multiply 1e-600000000 1e-400000098 -> 0E-1000000097 Underflow Subnormal Inexact Rounded
+mulx783 multiply 1e-600000000 1e-400000098 -> 0E-1000000097 Underflow Subnormal Inexact Rounded Clamped
precision: 999
mulx784 multiply 1e-600000000 1e-400000997 -> 1E-1000000997 Subnormal
-mulx785 multiply 1e-600000000 1e-400000998 -> 0E-1000000997 Underflow Subnormal Inexact Rounded
+mulx785 multiply 1e-600000000 1e-400000998 -> 0E-1000000997 Underflow Subnormal Inexact Rounded Clamped
-- following testcases [through mulx800] not yet run against code
precision: 9999
mulx786 multiply 1e-600000000 1e-400009997 -> 1E-1000009997 Subnormal
-mulx787 multiply 1e-600000000 1e-400009998 -> 0E-1000009997 Underflow Subnormal Inexact Rounded
+mulx787 multiply 1e-600000000 1e-400009998 -> 0E-1000009997 Underflow Subnormal Inexact Rounded Clamped
precision: 99999
mulx788 multiply 1e-600000000 1e-400099997 -> 1E-1000099997 Subnormal
-mulx789 multiply 1e-600000000 1e-400099998 -> 0E-1000099997 Underflow Subnormal Inexact Rounded
+mulx789 multiply 1e-600000000 1e-400099998 -> 0E-1000099997 Underflow Subnormal Inexact Rounded Clamped
precision: 999999
mulx790 multiply 1e-600000000 1e-400999997 -> 1E-1000999997 Subnormal
-mulx791 multiply 1e-600000000 1e-400999998 -> 0E-1000999997 Underflow Subnormal Inexact Rounded
+mulx791 multiply 1e-600000000 1e-400999998 -> 0E-1000999997 Underflow Subnormal Inexact Rounded Clamped
precision: 9999999
mulx792 multiply 1e-600000000 1e-409999997 -> 1E-1009999997 Subnormal
-mulx793 multiply 1e-600000000 1e-409999998 -> 0E-1009999997 Underflow Subnormal Inexact Rounded
+mulx793 multiply 1e-600000000 1e-409999998 -> 0E-1009999997 Underflow Subnormal Inexact Rounded Clamped
precision: 99999999
mulx794 multiply 1e-600000000 1e-499999997 -> 1E-1099999997 Subnormal
-mulx795 multiply 1e-600000000 1e-499999998 -> 0E-1099999997 Underflow Subnormal Inexact Rounded
+mulx795 multiply 1e-600000000 1e-499999998 -> 0E-1099999997 Underflow Subnormal Inexact Rounded Clamped
precision: 999999999
mulx796 multiply 1e-999999999 1e-999999997 -> 1E-1999999996 Subnormal
mulx797 multiply 1e-999999999 1e-999999998 -> 1E-1999999997 Subnormal
-mulx798 multiply 1e-999999999 1e-999999999 -> 0E-1999999997 Underflow Subnormal Inexact Rounded
+mulx798 multiply 1e-999999999 1e-999999999 -> 0E-1999999997 Underflow Subnormal Inexact Rounded Clamped
mulx799 multiply 1e-600000000 1e-400000007 -> 1E-1000000007 Subnormal
mulx800 multiply 1e-600000000 1e-400000008 -> 1E-1000000008 Subnormal
@@ -573,19 +615,19 @@
mulx817 multiply 2.51E-999 1e-4 -> 3E-1003 Underflow Subnormal Inexact Rounded
mulx818 multiply 1E-999 1e-4 -> 1E-1003 Subnormal
-mulx819 multiply 3E-999 1e-5 -> 0E-1003 Underflow Subnormal Inexact Rounded
-mulx820 multiply 5E-999 1e-5 -> 0E-1003 Underflow Subnormal Inexact Rounded
+mulx819 multiply 3E-999 1e-5 -> 0E-1003 Underflow Subnormal Inexact Rounded Clamped
+mulx820 multiply 5E-999 1e-5 -> 0E-1003 Underflow Subnormal Inexact Rounded Clamped
mulx821 multiply 7E-999 1e-5 -> 1E-1003 Underflow Subnormal Inexact Rounded
mulx822 multiply 9E-999 1e-5 -> 1E-1003 Underflow Subnormal Inexact Rounded
mulx823 multiply 9.9E-999 1e-5 -> 1E-1003 Underflow Subnormal Inexact Rounded
mulx824 multiply 1E-999 -1e-4 -> -1E-1003 Subnormal
-mulx825 multiply 3E-999 -1e-5 -> -0E-1003 Underflow Subnormal Inexact Rounded
-mulx826 multiply -5E-999 1e-5 -> -0E-1003 Underflow Subnormal Inexact Rounded
+mulx825 multiply 3E-999 -1e-5 -> -0E-1003 Underflow Subnormal Inexact Rounded Clamped
+mulx826 multiply -5E-999 1e-5 -> -0E-1003 Underflow Subnormal Inexact Rounded Clamped
mulx827 multiply 7E-999 -1e-5 -> -1E-1003 Underflow Subnormal Inexact Rounded
mulx828 multiply -9E-999 1e-5 -> -1E-1003 Underflow Subnormal Inexact Rounded
mulx829 multiply 9.9E-999 -1e-5 -> -1E-1003 Underflow Subnormal Inexact Rounded
-mulx830 multiply 3.0E-999 -1e-5 -> -0E-1003 Underflow Subnormal Inexact Rounded
+mulx830 multiply 3.0E-999 -1e-5 -> -0E-1003 Underflow Subnormal Inexact Rounded Clamped
mulx831 multiply 1.0E-501 1e-501 -> 1.0E-1002 Subnormal
mulx832 multiply 2.0E-501 2e-501 -> 4.0E-1002 Subnormal
@@ -595,7 +637,7 @@
mulx836 multiply 40.0E-501 40e-501 -> 1.6000E-999
-- squares
-mulx840 multiply 1E-502 1e-502 -> 0E-1003 Underflow Subnormal Inexact Rounded
+mulx840 multiply 1E-502 1e-502 -> 0E-1003 Underflow Subnormal Inexact Rounded Clamped
mulx841 multiply 1E-501 1e-501 -> 1E-1002 Subnormal
mulx842 multiply 2E-501 2e-501 -> 4E-1002 Subnormal
mulx843 multiply 4E-501 4e-501 -> 1.6E-1001 Subnormal
@@ -604,7 +646,7 @@
mulx846 multiply 40E-501 40e-501 -> 1.600E-999
-- cubes
-mulx850 multiply 1E-670 1e-335 -> 0E-1003 Underflow Subnormal Inexact Rounded
+mulx850 multiply 1E-670 1e-335 -> 0E-1003 Underflow Subnormal Inexact Rounded Clamped
mulx851 multiply 1E-668 1e-334 -> 1E-1002 Subnormal
mulx852 multiply 4E-668 2e-334 -> 8E-1002 Subnormal
mulx853 multiply 9E-668 3e-334 -> 2.7E-1001 Subnormal
@@ -612,7 +654,7 @@
mulx855 multiply 25E-668 5e-334 -> 1.25E-1000 Subnormal
mulx856 multiply 10E-668 100e-334 -> 1.000E-999
--- test from 0.099 ** 999 at 15 digits
+-- test derived from result of 0.099 ** 999 at 15 digits with unlimited exponent
precision: 19
mulx860 multiply 6636851557994578716E-520 6636851557994578716E-520 -> 4.40477986028551E-1003 Underflow Subnormal Inexact Rounded
@@ -629,14 +671,16 @@
precision: 5
maxexponent: 79
minexponent: -79
-mulx881 multiply 1.2347E-40 1.2347E-40 -> 1.524E-80 Inexact Rounded Subnormal Underflow
-mulx882 multiply 1.234E-40 1.234E-40 -> 1.523E-80 Inexact Rounded Subnormal Underflow
-mulx883 multiply 1.23E-40 1.23E-40 -> 1.513E-80 Inexact Rounded Subnormal Underflow
-mulx884 multiply 1.2E-40 1.2E-40 -> 1.44E-80 Subnormal
-mulx885 multiply 1.2E-40 1.2E-41 -> 1.44E-81 Subnormal
-mulx886 multiply 1.2E-40 1.2E-42 -> 1.4E-82 Subnormal Inexact Rounded Underflow
-mulx887 multiply 1.2E-40 1.3E-42 -> 1.6E-82 Subnormal Inexact Rounded Underflow
-mulx888 multiply 1.3E-40 1.3E-42 -> 1.7E-82 Subnormal Inexact Rounded Underflow
+mulx881 multiply 1.2347E-40 1.2347E-40 -> 1.524E-80 Inexact Rounded Subnormal Underflow
+mulx882 multiply 1.234E-40 1.234E-40 -> 1.523E-80 Inexact Rounded Subnormal Underflow
+mulx883 multiply 1.23E-40 1.23E-40 -> 1.513E-80 Inexact Rounded Subnormal Underflow
+mulx884 multiply 1.2E-40 1.2E-40 -> 1.44E-80 Subnormal
+mulx885 multiply 1.2E-40 1.2E-41 -> 1.44E-81 Subnormal
+mulx886 multiply 1.2E-40 1.2E-42 -> 1.4E-82 Subnormal Inexact Rounded Underflow
+mulx887 multiply 1.2E-40 1.3E-42 -> 1.6E-82 Subnormal Inexact Rounded Underflow
+mulx888 multiply 1.3E-40 1.3E-42 -> 1.7E-82 Subnormal Inexact Rounded Underflow
+mulx889 multiply 1.3E-40 1.3E-43 -> 2E-83 Subnormal Inexact Rounded Underflow
+mulx890 multiply 1.3E-41 1.3E-43 -> 0E-83 Clamped Subnormal Inexact Rounded Underflow
mulx891 multiply 1.2345E-39 1.234E-40 -> 1.5234E-79 Inexact Rounded
mulx892 multiply 1.23456E-39 1.234E-40 -> 1.5234E-79 Inexact Rounded
@@ -645,7 +689,43 @@
mulx895 multiply 1.2345E-41 1.234E-40 -> 1.52E-81 Inexact Rounded Subnormal Underflow
mulx896 multiply 1.23456E-41 1.234E-40 -> 1.52E-81 Inexact Rounded Subnormal Underflow
+-- Now explore the case where we get a normal result with Underflow
+precision: 16
+rounding: half_up
+maxExponent: 384
+minExponent: -383
+
+mulx900 multiply 0.3000000000E-191 0.3000000000E-191 -> 9.00000000000000E-384 Subnormal Rounded
+mulx901 multiply 0.3000000001E-191 0.3000000001E-191 -> 9.00000000600000E-384 Underflow Inexact Subnormal Rounded
+mulx902 multiply 9.999999999999999E-383 0.0999999999999 -> 9.99999999999000E-384 Underflow Inexact Subnormal Rounded
+mulx903 multiply 9.999999999999999E-383 0.09999999999999 -> 9.99999999999900E-384 Underflow Inexact Subnormal Rounded
+mulx904 multiply 9.999999999999999E-383 0.099999999999999 -> 9.99999999999990E-384 Underflow Inexact Subnormal Rounded
+mulx905 multiply 9.999999999999999E-383 0.0999999999999999 -> 9.99999999999999E-384 Underflow Inexact Subnormal Rounded
+-- prove operands are exact
+mulx906 multiply 9.999999999999999E-383 1 -> 9.999999999999999E-383
+mulx907 multiply 1 0.09999999999999999 -> 0.09999999999999999
+-- the next rounds to Nmin
+mulx908 multiply 9.999999999999999E-383 0.09999999999999999 -> 1.000000000000000E-383 Underflow Inexact Subnormal Rounded
+mulx909 multiply 9.999999999999999E-383 0.099999999999999999 -> 1.000000000000000E-383 Underflow Inexact Subnormal Rounded
+mulx910 multiply 9.999999999999999E-383 0.0999999999999999999 -> 1.000000000000000E-383 Underflow Inexact Subnormal Rounded
+mulx911 multiply 9.999999999999999E-383 0.09999999999999999999 -> 1.000000000000000E-383 Underflow Inexact Subnormal Rounded
+
+
+-- Examples from SQL proposal (Krishna Kulkarni)
+precision: 34
+rounding: half_up
+maxExponent: 6144
+minExponent: -6143
+mulx1001 multiply 130E-2 120E-2 -> 1.5600
+mulx1002 multiply 130E-2 12E-1 -> 1.560
+mulx1003 multiply 130E-2 1E0 -> 1.30
+mulx1004 multiply 1E2 1E4 -> 1E+6
+
+-- payload decapitate
+precision: 5
+mulx1010 multiply 11 -sNaN1234567890 -> -NaN67890 Invalid_operation
+
-- Null tests
-mulx900 multiply 10 # -> NaN Invalid_operation
-mulx901 multiply # 10 -> NaN Invalid_operation
+mulx990 multiply 10 # -> NaN Invalid_operation
+mulx991 multiply # 10 -> NaN Invalid_operation
Deleted: /python/branches/py3k-importlib/Lib/test/decimaltestdata/normalize.decTest
==============================================================================
--- /python/branches/py3k-importlib/Lib/test/decimaltestdata/normalize.decTest Fri Sep 21 03:17:09 2007
+++ (empty file)
@@ -1,225 +0,0 @@
-------------------------------------------------------------------------
--- normalize.decTest -- remove trailing zeros --
--- Copyright (c) IBM Corporation, 2003. All rights reserved. --
-------------------------------------------------------------------------
--- Please see the document "General Decimal Arithmetic Testcases" --
--- at http://www2.hursley.ibm.com/decimal for the description of --
--- these testcases. --
--- --
--- These testcases are experimental ('beta' versions), and they --
--- may contain errors. They are offered on an as-is basis. In --
--- particular, achieving the same results as the tests here is not --
--- a guarantee that an implementation complies with any Standard --
--- or specification. The tests are not exhaustive. --
--- --
--- Please send comments, suggestions, and corrections to the author: --
--- Mike Cowlishaw, IBM Fellow --
--- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
--- mfc at uk.ibm.com --
-------------------------------------------------------------------------
-version: 2.39
-
-extended: 1
-precision: 9
-rounding: half_up
-maxExponent: 999
-minexponent: -999
-
-nrmx001 normalize '1' -> '1'
-nrmx002 normalize '-1' -> '-1'
-nrmx003 normalize '1.00' -> '1'
-nrmx004 normalize '-1.00' -> '-1'
-nrmx005 normalize '0' -> '0'
-nrmx006 normalize '0.00' -> '0'
-nrmx007 normalize '00.0' -> '0'
-nrmx008 normalize '00.00' -> '0'
-nrmx009 normalize '00' -> '0'
-nrmx010 normalize '0E+1' -> '0'
-nrmx011 normalize '0E+5' -> '0'
-
-nrmx012 normalize '-2' -> '-2'
-nrmx013 normalize '2' -> '2'
-nrmx014 normalize '-2.00' -> '-2'
-nrmx015 normalize '2.00' -> '2'
-nrmx016 normalize '-0' -> '-0'
-nrmx017 normalize '-0.00' -> '-0'
-nrmx018 normalize '-00.0' -> '-0'
-nrmx019 normalize '-00.00' -> '-0'
-nrmx020 normalize '-00' -> '-0'
-nrmx021 normalize '-0E+5' -> '-0'
-nrmx022 normalize '-0E+1' -> '-0'
-
-nrmx030 normalize '+0.1' -> '0.1'
-nrmx031 normalize '-0.1' -> '-0.1'
-nrmx032 normalize '+0.01' -> '0.01'
-nrmx033 normalize '-0.01' -> '-0.01'
-nrmx034 normalize '+0.001' -> '0.001'
-nrmx035 normalize '-0.001' -> '-0.001'
-nrmx036 normalize '+0.000001' -> '0.000001'
-nrmx037 normalize '-0.000001' -> '-0.000001'
-nrmx038 normalize '+0.000000000001' -> '1E-12'
-nrmx039 normalize '-0.000000000001' -> '-1E-12'
-
-nrmx041 normalize 1.1 -> 1.1
-nrmx042 normalize 1.10 -> 1.1
-nrmx043 normalize 1.100 -> 1.1
-nrmx044 normalize 1.110 -> 1.11
-nrmx045 normalize -1.1 -> -1.1
-nrmx046 normalize -1.10 -> -1.1
-nrmx047 normalize -1.100 -> -1.1
-nrmx048 normalize -1.110 -> -1.11
-nrmx049 normalize 9.9 -> 9.9
-nrmx050 normalize 9.90 -> 9.9
-nrmx051 normalize 9.900 -> 9.9
-nrmx052 normalize 9.990 -> 9.99
-nrmx053 normalize -9.9 -> -9.9
-nrmx054 normalize -9.90 -> -9.9
-nrmx055 normalize -9.900 -> -9.9
-nrmx056 normalize -9.990 -> -9.99
-
--- some trailing fractional zeros with zeros in units
-nrmx060 normalize 10.0 -> 1E+1
-nrmx061 normalize 10.00 -> 1E+1
-nrmx062 normalize 100.0 -> 1E+2
-nrmx063 normalize 100.00 -> 1E+2
-nrmx064 normalize 1.1000E+3 -> 1.1E+3
-nrmx065 normalize 1.10000E+3 -> 1.1E+3
-nrmx066 normalize -10.0 -> -1E+1
-nrmx067 normalize -10.00 -> -1E+1
-nrmx068 normalize -100.0 -> -1E+2
-nrmx069 normalize -100.00 -> -1E+2
-nrmx070 normalize -1.1000E+3 -> -1.1E+3
-nrmx071 normalize -1.10000E+3 -> -1.1E+3
-
--- some insignificant trailing zeros with positive exponent
-nrmx080 normalize 10E+1 -> 1E+2
-nrmx081 normalize 100E+1 -> 1E+3
-nrmx082 normalize 1.0E+2 -> 1E+2
-nrmx083 normalize 1.0E+3 -> 1E+3
-nrmx084 normalize 1.1E+3 -> 1.1E+3
-nrmx085 normalize 1.00E+3 -> 1E+3
-nrmx086 normalize 1.10E+3 -> 1.1E+3
-nrmx087 normalize -10E+1 -> -1E+2
-nrmx088 normalize -100E+1 -> -1E+3
-nrmx089 normalize -1.0E+2 -> -1E+2
-nrmx090 normalize -1.0E+3 -> -1E+3
-nrmx091 normalize -1.1E+3 -> -1.1E+3
-nrmx092 normalize -1.00E+3 -> -1E+3
-nrmx093 normalize -1.10E+3 -> -1.1E+3
-
--- some significant trailing zeros, were we to be trimming
-nrmx100 normalize 11 -> 11
-nrmx101 normalize 10 -> 1E+1
-nrmx102 normalize 10. -> 1E+1
-nrmx103 normalize 1.1E+1 -> 11
-nrmx104 normalize 1.0E+1 -> 1E+1
-nrmx105 normalize 1.10E+2 -> 1.1E+2
-nrmx106 normalize 1.00E+2 -> 1E+2
-nrmx107 normalize 1.100E+3 -> 1.1E+3
-nrmx108 normalize 1.000E+3 -> 1E+3
-nrmx109 normalize 1.000000E+6 -> 1E+6
-nrmx110 normalize -11 -> -11
-nrmx111 normalize -10 -> -1E+1
-nrmx112 normalize -10. -> -1E+1
-nrmx113 normalize -1.1E+1 -> -11
-nrmx114 normalize -1.0E+1 -> -1E+1
-nrmx115 normalize -1.10E+2 -> -1.1E+2
-nrmx116 normalize -1.00E+2 -> -1E+2
-nrmx117 normalize -1.100E+3 -> -1.1E+3
-nrmx118 normalize -1.000E+3 -> -1E+3
-nrmx119 normalize -1.00000E+5 -> -1E+5
-nrmx120 normalize -1.000000E+6 -> -1E+6
-nrmx121 normalize -10.00000E+6 -> -1E+7
-nrmx122 normalize -100.0000E+6 -> -1E+8
-nrmx123 normalize -1000.000E+6 -> -1E+9
-nrmx124 normalize -10000.00E+6 -> -1E+10
-nrmx125 normalize -100000.0E+6 -> -1E+11
-nrmx126 normalize -1000000.E+6 -> -1E+12
-
--- examples from decArith
-nrmx140 normalize '2.1' -> '2.1'
-nrmx141 normalize '-2.0' -> '-2'
-nrmx142 normalize '1.200' -> '1.2'
-nrmx143 normalize '-120' -> '-1.2E+2'
-nrmx144 normalize '120.00' -> '1.2E+2'
-nrmx145 normalize '0.00' -> '0'
-
--- overflow tests
-maxexponent: 999999999
-minexponent: -999999999
-precision: 3
-nrmx160 normalize 9.999E+999999999 -> Infinity Inexact Overflow Rounded
-nrmx161 normalize -9.999E+999999999 -> -Infinity Inexact Overflow Rounded
-
--- subnormals and underflow
-precision: 3
-maxexponent: 999
-minexponent: -999
-nrmx210 normalize 1.00E-999 -> 1E-999
-nrmx211 normalize 0.1E-999 -> 1E-1000 Subnormal
-nrmx212 normalize 0.10E-999 -> 1E-1000 Subnormal
-nrmx213 normalize 0.100E-999 -> 1E-1000 Subnormal Rounded
-nrmx214 normalize 0.01E-999 -> 1E-1001 Subnormal
--- next is rounded to Emin
-nrmx215 normalize 0.999E-999 -> 1E-999 Inexact Rounded Subnormal Underflow
-nrmx216 normalize 0.099E-999 -> 1E-1000 Inexact Rounded Subnormal Underflow
-nrmx217 normalize 0.009E-999 -> 1E-1001 Inexact Rounded Subnormal Underflow
-nrmx218 normalize 0.001E-999 -> 0 Inexact Rounded Subnormal Underflow
-nrmx219 normalize 0.0009E-999 -> 0 Inexact Rounded Subnormal Underflow
-nrmx220 normalize 0.0001E-999 -> 0 Inexact Rounded Subnormal Underflow
-
-nrmx230 normalize -1.00E-999 -> -1E-999
-nrmx231 normalize -0.1E-999 -> -1E-1000 Subnormal
-nrmx232 normalize -0.10E-999 -> -1E-1000 Subnormal
-nrmx233 normalize -0.100E-999 -> -1E-1000 Subnormal Rounded
-nrmx234 normalize -0.01E-999 -> -1E-1001 Subnormal
--- next is rounded to Emin
-nrmx235 normalize -0.999E-999 -> -1E-999 Inexact Rounded Subnormal Underflow
-nrmx236 normalize -0.099E-999 -> -1E-1000 Inexact Rounded Subnormal Underflow
-nrmx237 normalize -0.009E-999 -> -1E-1001 Inexact Rounded Subnormal Underflow
-nrmx238 normalize -0.001E-999 -> -0 Inexact Rounded Subnormal Underflow
-nrmx239 normalize -0.0009E-999 -> -0 Inexact Rounded Subnormal Underflow
-nrmx240 normalize -0.0001E-999 -> -0 Inexact Rounded Subnormal Underflow
-
--- more reshaping
-precision: 9
-nrmx260 normalize '56260E-10' -> '0.000005626'
-nrmx261 normalize '56260E-5' -> '0.5626'
-nrmx262 normalize '56260E-2' -> '562.6'
-nrmx263 normalize '56260E-1' -> '5626'
-nrmx265 normalize '56260E-0' -> '5.626E+4'
-nrmx266 normalize '56260E+0' -> '5.626E+4'
-nrmx267 normalize '56260E+1' -> '5.626E+5'
-nrmx268 normalize '56260E+2' -> '5.626E+6'
-nrmx269 normalize '56260E+3' -> '5.626E+7'
-nrmx270 normalize '56260E+4' -> '5.626E+8'
-nrmx271 normalize '56260E+5' -> '5.626E+9'
-nrmx272 normalize '56260E+6' -> '5.626E+10'
-nrmx280 normalize '-56260E-10' -> '-0.000005626'
-nrmx281 normalize '-56260E-5' -> '-0.5626'
-nrmx282 normalize '-56260E-2' -> '-562.6'
-nrmx283 normalize '-56260E-1' -> '-5626'
-nrmx285 normalize '-56260E-0' -> '-5.626E+4'
-nrmx286 normalize '-56260E+0' -> '-5.626E+4'
-nrmx287 normalize '-56260E+1' -> '-5.626E+5'
-nrmx288 normalize '-56260E+2' -> '-5.626E+6'
-nrmx289 normalize '-56260E+3' -> '-5.626E+7'
-nrmx290 normalize '-56260E+4' -> '-5.626E+8'
-nrmx291 normalize '-56260E+5' -> '-5.626E+9'
-nrmx292 normalize '-56260E+6' -> '-5.626E+10'
-
-
--- specials
-nrmx820 normalize 'Inf' -> 'Infinity'
-nrmx821 normalize '-Inf' -> '-Infinity'
-nrmx822 normalize NaN -> NaN
-nrmx823 normalize sNaN -> NaN Invalid_operation
-nrmx824 normalize NaN101 -> NaN101
-nrmx825 normalize sNaN010 -> NaN10 Invalid_operation
-nrmx827 normalize -NaN -> -NaN
-nrmx828 normalize -sNaN -> -NaN Invalid_operation
-nrmx829 normalize -NaN101 -> -NaN101
-nrmx830 normalize -sNaN010 -> -NaN10 Invalid_operation
-
--- Null test
-nrmx900 normalize # -> NaN Invalid_operation
Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/plus.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/plus.decTest (original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/plus.decTest Fri Sep 21 03:17:09 2007
@@ -1,6 +1,6 @@
------------------------------------------------------------------------
-- plus.decTest -- decimal monadic addition --
--- Copyright (c) IBM Corporation, 1981, 2004. All rights reserved. --
+-- Copyright (c) IBM Corporation, 1981, 2007. All rights reserved. --
------------------------------------------------------------------------
-- Please see the document "General Decimal Arithmetic Testcases" --
-- at http://www2.hursley.ibm.com/decimal for the description of --
@@ -17,7 +17,7 @@
-- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
-- mfc at uk.ibm.com --
------------------------------------------------------------------------
-version: 2.39
+version: 2.56
-- This set of tests primarily tests the existence of the operator.
-- Addition and rounding, and most overflows, are tested elsewhere.
@@ -138,9 +138,9 @@
plux215 plus 0.999E-999 -> 1.00E-999 Inexact Rounded Subnormal Underflow
plux216 plus 0.099E-999 -> 1.0E-1000 Inexact Rounded Subnormal Underflow
plux217 plus 0.009E-999 -> 1E-1001 Inexact Rounded Subnormal Underflow
-plux218 plus 0.001E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow
-plux219 plus 0.0009E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow
-plux220 plus 0.0001E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow
+plux218 plus 0.001E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow Clamped
+plux219 plus 0.0009E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow Clamped
+plux220 plus 0.0001E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow Clamped
plux230 plus -1.00E-999 -> -1.00E-999
plux231 plus -0.1E-999 -> -1E-1000 Subnormal
@@ -151,9 +151,23 @@
plux235 plus -0.999E-999 -> -1.00E-999 Inexact Rounded Subnormal Underflow
plux236 plus -0.099E-999 -> -1.0E-1000 Inexact Rounded Subnormal Underflow
plux237 plus -0.009E-999 -> -1E-1001 Inexact Rounded Subnormal Underflow
-plux238 plus -0.001E-999 -> -0E-1001 Inexact Rounded Subnormal Underflow
-plux239 plus -0.0009E-999 -> -0E-1001 Inexact Rounded Subnormal Underflow
-plux240 plus -0.0001E-999 -> -0E-1001 Inexact Rounded Subnormal Underflow
+plux238 plus -0.001E-999 -> -0E-1001 Inexact Rounded Subnormal Underflow Clamped
+plux239 plus -0.0009E-999 -> -0E-1001 Inexact Rounded Subnormal Underflow Clamped
+plux240 plus -0.0001E-999 -> -0E-1001 Inexact Rounded Subnormal Underflow Clamped
+
+-- subnormals clamped to 0-Etiny
+precision: 16
+maxExponent: 384
+minExponent: -383
+plux251 plus 7E-398 -> 7E-398 Subnormal
+plux252 plus 0E-398 -> 0E-398
+plux253 plus 7E-399 -> 1E-398 Subnormal Underflow Inexact Rounded
+plux254 plus 4E-399 -> 0E-398 Clamped Subnormal Underflow Inexact Rounded
+plux255 plus 7E-400 -> 0E-398 Clamped Subnormal Underflow Inexact Rounded
+plux256 plus 7E-401 -> 0E-398 Clamped Subnormal Underflow Inexact Rounded
+plux257 plus 0E-399 -> 0E-398 Clamped
+plux258 plus 0E-400 -> 0E-398 Clamped
+plux259 plus 0E-401 -> 0E-398 Clamped
-- long operand checks
maxexponent: 999
Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/power.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/power.decTest (original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/power.decTest Fri Sep 21 03:17:09 2007
@@ -1,6 +1,6 @@
-----------------------------------------------------------------------
--- power.decTest -- decimal exponentiation --
--- Copyright (c) IBM Corporation, 1981, 2003. All rights reserved. --
+------------------------------------------------------------------------
+-- power.decTest -- decimal exponentiation [power(x, y)] --
+-- Copyright (c) IBM Corporation, 1981, 2007. All rights reserved. --
------------------------------------------------------------------------
-- Please see the document "General Decimal Arithmetic Testcases" --
-- at http://www2.hursley.ibm.com/decimal for the description of --
@@ -17,17 +17,17 @@
-- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
-- mfc at uk.ibm.com --
------------------------------------------------------------------------
-version: 2.39
+version: 2.56
--- This set of testcases tests raising numbers to an integer power only.
--- If arbitrary powers were supported, 1 ulp differences would be
--- permitted.
+-- In addition to the power operator testcases here, see also the file
+-- powersqrt.decTest which includes all the tests from
+-- squareroot.decTest implemented using power(x, 0.5)
extended: 1
-precision: 9
-rounding: half_up
-maxExponent: 999
-minexponent: -999
+precision: 16
+rounding: half_even
+maxExponent: 384
+minExponent: -383
-- base checks. Note 0**0 is an error.
powx001 power '0' '0' -> NaN Invalid_operation
@@ -52,51 +52,54 @@
powx022 power '2' '12' -> '4096'
powx023 power '2' '15' -> '32768'
powx024 power '2' '16' -> '65536'
-powx025 power '2' '31' -> '2.14748365E+9' Inexact Rounded
+powx025 power '2' '31' -> '2147483648'
+-- NB 0 not stripped in next
+powx026 power '2' '32' -> '4294967296'
+
+precision: 9
+powx027 power '2' '31' -> '2.14748365E+9' Inexact Rounded
-- NB 0 not stripped in next
-powx026 power '2' '32' -> '4.29496730E+9' Inexact Rounded
+powx028 power '2' '32' -> '4.29496730E+9' Inexact Rounded
precision: 10
-powx027 power '2' '31' -> '2147483648'
-powx028 power '2' '32' -> '4294967296'
+powx029 power '2' '31' -> '2147483648'
+powx030 power '2' '32' -> '4294967296'
precision: 9
-powx030 power '3' '2' -> 9
-powx031 power '4' '2' -> 16
-powx032 power '5' '2' -> 25
-powx033 power '6' '2' -> 36
-powx034 power '7' '2' -> 49
-powx035 power '8' '2' -> 64
-powx036 power '9' '2' -> 81
-powx037 power '10' '2' -> 100
-powx038 power '11' '2' -> 121
-powx039 power '12' '2' -> 144
-
-powx040 power '3' '3' -> 27
-powx041 power '4' '3' -> 64
-powx042 power '5' '3' -> 125
-powx043 power '6' '3' -> 216
-powx044 power '7' '3' -> 343
-
-powx050 power '10' '0' -> 1
-powx051 power '10' '1' -> 10
-powx052 power '10' '2' -> 100
-powx053 power '10' '3' -> 1000
-powx054 power '10' '4' -> 10000
-powx055 power '10' '5' -> 100000
-powx056 power '10' '6' -> 1000000
-powx057 power '10' '7' -> 10000000
-powx058 power '10' '8' -> 100000000
-powx059 power '10' '9' -> 1.00000000E+9 Rounded
-powx060 power '10' '22' -> 1.00000000E+22 Rounded
-powx061 power '10' '77' -> 1.00000000E+77 Rounded
-powx062 power '10' '99' -> 1.00000000E+99 Rounded
-
-maxexponent: 999999999
-minexponent: -999999999
-powx063 power '10' '999999999' -> '1.00000000E+999999999' Rounded
-powx064 power '10' '999999998' -> '1.00000000E+999999998' Rounded
-powx065 power '10' '999999997' -> '1.00000000E+999999997' Rounded
-powx066 power '10' '333333333' -> '1.00000000E+333333333' Rounded
+powx031 power '3' '2' -> 9
+powx032 power '4' '2' -> 16
+powx033 power '5' '2' -> 25
+powx034 power '6' '2' -> 36
+powx035 power '7' '2' -> 49
+powx036 power '8' '2' -> 64
+powx037 power '9' '2' -> 81
+powx038 power '10' '2' -> 100
+powx039 power '11' '2' -> 121
+powx040 power '12' '2' -> 144
+
+powx041 power '3' '3' -> 27
+powx042 power '4' '3' -> 64
+powx043 power '5' '3' -> 125
+powx044 power '6' '3' -> 216
+powx045 power '7' '3' -> 343
+powx047 power '-3' '3' -> -27
+powx048 power '-4' '3' -> -64
+powx049 power '-5' '3' -> -125
+powx050 power '-6' '3' -> -216
+powx051 power '-7' '3' -> -343
+
+powx052 power '10' '0' -> 1
+powx053 power '10' '1' -> 10
+powx054 power '10' '2' -> 100
+powx055 power '10' '3' -> 1000
+powx056 power '10' '4' -> 10000
+powx057 power '10' '5' -> 100000
+powx058 power '10' '6' -> 1000000
+powx059 power '10' '7' -> 10000000
+powx060 power '10' '8' -> 100000000
+powx061 power '10' '9' -> 1.00000000E+9 Rounded
+powx062 power '10' '22' -> 1.00000000E+22 Rounded
+powx063 power '10' '77' -> 1.00000000E+77 Rounded
+powx064 power '10' '99' -> 1.00000000E+99 Rounded
powx070 power '0.3' '0' -> '1'
powx071 power '0.3' '1' -> '0.3'
@@ -127,71 +130,52 @@
powx095 power 101 7 -> 1.07213535E+14 Inexact Rounded
-- negative powers
-powx101 power '2' '-1' -> 0.5
-powx102 power '2' '-2' -> 0.25
-powx103 power '2' '-4' -> 0.0625
-powx104 power '2' '-8' -> 0.00390625
-powx105 power '2' '-16' -> 0.0000152587891 Inexact Rounded
-powx106 power '2' '-32' -> 2.32830644E-10 Inexact Rounded
-powx108 power '2' '-64' -> 5.42101086E-20 Inexact Rounded
-powx110 power '10' '-8' -> 1E-8
-powx111 power '10' '-7' -> 1E-7
-powx112 power '10' '-6' -> 0.000001
-powx113 power '10' '-5' -> 0.00001
-powx114 power '10' '-4' -> 0.0001
-powx115 power '10' '-3' -> 0.001
-powx116 power '10' '-2' -> 0.01
-powx117 power '10' '-1' -> 0.1
-
-powx118 power '10' '-333333333' -> 1E-333333333
-powx119 power '10' '-999999998' -> 1E-999999998
-powx120 power '10' '-999999999' -> 1E-999999999
-powx121 power '10' '-77' -> '1E-77'
-powx122 power '10' '-22' -> '1E-22'
-
-powx123 power '2' '-1' -> '0.5'
-powx124 power '2' '-2' -> '0.25'
-powx125 power '2' '-4' -> '0.0625'
-powx126 power '0' '-1' -> Infinity Division_by_zero
-powx127 power '0' '-2' -> Infinity Division_by_zero
-powx128 power -0 '-1' -> -Infinity Division_by_zero
-powx129 power -0 '-2' -> Infinity Division_by_zero
-
--- out-of-range edge cases
-powx181 power '7' '999999998' -> 2.10892313E+845098038 Inexact Rounded
-powx182 power '7' '999999999' -> 1.47624619E+845098039 Inexact Rounded
-powx183 power '7' '1000000000' -> NaN Invalid_operation
-powx184 power '7' '1000000001' -> NaN Invalid_operation
-powx185 power '7' '10000000000' -> NaN Invalid_operation
-powx186 power '7' '-1000000001' -> NaN Invalid_operation
-powx187 power '7' '-1000000000' -> NaN Invalid_operation
-powx189 power '7' '-999999999' -> 6.77393787E-845098040 Inexact Rounded
-powx190 power '7' '-999999998' -> 4.74175651E-845098039 Inexact Rounded
-
--- some baddies [more below]
-powx191 power '2' '2.000001' -> NaN Invalid_operation
-powx192 power '2' '2.00000000' -> 4
-powx193 power '2' '2.000000001' -> NaN Invalid_operation
-powx194 power '2' '2.0000000001' -> NaN Invalid_operation
+powx099 power '1' '-1' -> 1
+powx100 power '3' '-1' -> 0.333333333 Inexact Rounded
+powx101 power '2' '-1' -> 0.5
+powx102 power '2' '-2' -> 0.25
+powx103 power '2' '-4' -> 0.0625
+powx104 power '2' '-8' -> 0.00390625
+powx105 power '2' '-16' -> 0.0000152587891 Inexact Rounded
+powx106 power '2' '-32' -> 2.32830644E-10 Inexact Rounded
+powx108 power '2' '-64' -> 5.42101086E-20 Inexact Rounded
+powx110 power '10' '-8' -> 1E-8
+powx111 power '10' '-7' -> 1E-7
+powx112 power '10' '-6' -> 0.000001
+powx113 power '10' '-5' -> 0.00001
+powx114 power '10' '-4' -> 0.0001
+powx115 power '10' '-3' -> 0.001
+powx116 power '10' '-2' -> 0.01
+powx117 power '10' '-1' -> 0.1
+powx121 power '10' '-77' -> '1E-77'
+powx122 power '10' '-22' -> '1E-22'
+
+powx123 power '2' '-1' -> '0.5'
+powx124 power '2' '-2' -> '0.25'
+powx125 power '2' '-4' -> '0.0625'
+
+powx126 power '0' '-1' -> Infinity
+powx127 power '0' '-2' -> Infinity
+powx128 power -0 '-1' -> -Infinity
+powx129 power -0 '-2' -> Infinity
-- "0.5" tests from original Rexx diagnostics [loop unrolled]
-powx200 power 0.5 0 -> 1
-powx201 power 0.5 1 -> 0.5
-powx202 power 0.5 2 -> 0.25
-powx203 power 0.5 3 -> 0.125
-powx204 power 0.5 4 -> 0.0625
-powx205 power 0.5 5 -> 0.03125
-powx206 power 0.5 6 -> 0.015625
-powx207 power 0.5 7 -> 0.0078125
-powx208 power 0.5 8 -> 0.00390625
-powx209 power 0.5 9 -> 0.001953125
-powx210 power 0.5 10 -> 0.0009765625
+powx200 power 0.5 0 -> 1
+powx201 power 0.5 1 -> 0.5
+powx202 power 0.5 2 -> 0.25
+powx203 power 0.5 3 -> 0.125
+powx204 power 0.5 4 -> 0.0625
+powx205 power 0.5 5 -> 0.03125
+powx206 power 0.5 6 -> 0.015625
+powx207 power 0.5 7 -> 0.0078125
+powx208 power 0.5 8 -> 0.00390625
+powx209 power 0.5 9 -> 0.001953125
+powx210 power 0.5 10 -> 0.0009765625
+
+powx211 power 1 100000000 -> 1
+powx212 power 1 999999998 -> 1
+powx213 power 1 999999999 -> 1
--- A (rare) case where the last digit is not within 0.5 ULP
-precision: 9
-powx215 power "-21971575.0E+31454441" "-7" -> "-4.04549503E-220181139" Inexact Rounded
-precision: 20
-powx216 power "-21971575.0E+31454441" "-7" -> "-4.0454950249324891788E-220181139" Inexact Rounded
-- The Vienna case. Checks both setup and 1/acc working precision
-- Modified 1998.12.14 as RHS no longer rounded before use (must fit)
@@ -201,185 +185,64 @@
-- Modified 2002.10.06 -- finally, no input rounding
-- With input rounding, result would be 8.74E-2226
precision: 3
+maxexponent: 5000
+minexponent: -5000
powx219 power '123456789E+10' '-1.23000e+2' -> '5.54E-2226' Inexact Rounded
--- whole number checks
-precision: 9
-powx221 power 1 1234 -> 1
-precision: 4
-powx222 power 1 1234 -> 1
-precision: 3
-powx223 power 1 1234 -> 1
-powx224 power 1 12.34e+2 -> 1
-powx225 power 1 12.3 -> NaN Invalid_operation
-powx226 power 1 12.0 -> 1
-powx227 power 1 1.01 -> NaN Invalid_operation
-powx228 power 2 1.00 -> 2
-powx229 power 2 2.00 -> 4
-precision: 9
-powx230 power 1 1.0001 -> NaN Invalid_operation
-powx231 power 1 1.0000001 -> NaN Invalid_operation
-powx232 power 1 1.0000000001 -> NaN Invalid_operation
-powx233 power 1 1.0000000000001 -> NaN Invalid_operation
-precision: 5
-powx234 power 1 1.0001 -> NaN Invalid_operation
-powx235 power 1 1.0000001 -> NaN Invalid_operation
-powx236 power 1 1.0000000001 -> NaN Invalid_operation
-powx237 power 1 1.0000000000001 -> NaN Invalid_operation
-powx238 power 1 1.0000000000001 -> NaN Invalid_operation
-
-maxexponent: 999999999
-minexponent: -999999999
-powx239 power 1 5.67E-987654321 -> NaN Invalid_operation
-
-powx240 power 1 100000000 -> 1
-powx241 power 1 999999998 -> 1
-powx242 power 1 999999999 -> 1
-powx243 power 1 1000000000 -> NaN Invalid_operation
-powx244 power 1 9999999999 -> NaN Invalid_operation
-
--- Checks for 'Too much precision needed'
--- For x^12, digits+elength+1 = digits+3
-precision: 999999999
-powx249 add 1 1 -> 2 -- check basic operation at this precision
-powx250 power 2 12 -> Infinity Overflow
-precision: 999999998
-powx251 power 2 12 -> Infinity Overflow
-precision: 999999997
-powx252 power 2 12 -> Infinity Overflow
-precision: 999999996
-powx253 power 2 12 -> 4096
-precision: 999999995
-powx254 power 2 12 -> 4096
-
-- zeros
maxexponent: +96
minexponent: -95
precision: 7
-powx260 power 0E-34 3 -> 0E-101 Clamped
-powx261 power 0E-33 3 -> 0E-99
-powx262 power 0E-32 3 -> 0E-96
-powx263 power 0E-30 3 -> 0E-90
-powx264 power 0E-10 3 -> 0E-30
-powx265 power 0E-1 3 -> 0.000
-powx266 power 0E+0 3 -> 0
-powx267 power 0 3 -> 0
-powx268 power 0E+1 3 -> 0E+3
-powx269 power 0E+10 3 -> 0E+30
-powx270 power 0E+30 3 -> 0E+90
-powx271 power 0E+32 3 -> 0E+96
-powx272 power 0E+33 3 -> 0E+96 Clamped
-
--- overflow and underflow tests
-maxexponent: 999999999
-minexponent: -999999999
-precision: 9
-powx280 power 9 999999999 -> 3.05550054E+954242508 Inexact Rounded
-powx281 power 10 999999999 -> 1.00000000E+999999999 Rounded
-powx282 power 10.0001 999999999 -> Infinity Overflow Inexact Rounded
-powx283 power 10.1 999999999 -> Infinity Overflow Inexact Rounded
-powx284 power 11 999999999 -> Infinity Overflow Inexact Rounded
-powx285 power 12 999999999 -> Infinity Overflow Inexact Rounded
-powx286 power 999 999999999 -> Infinity Overflow Inexact Rounded
-powx287 power 999999 999999999 -> Infinity Overflow Inexact Rounded
-powx288 power 999999999 999999999 -> Infinity Overflow Inexact Rounded
-powx289 power 9.9E999999999 999999999 -> Infinity Overflow Inexact Rounded
-
-powx290 power 0.5 999999999 -> 4.33559594E-301029996 Inexact Rounded
-powx291 power 0.1 999999999 -> 1E-999999999 -- unrounded
-powx292 power 0.09 999999999 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
-powx293 power 0.05 999999999 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
-powx294 power 0.01 999999999 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
-powx295 power 0.0001 999999999 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
-powx297 power 0.0000001 999999999 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
-powx298 power 0.0000000001 999999999 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
-powx299 power 1E-999999999 999999999 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
-
-powx310 power -9 999999999 -> -3.05550054E+954242508 Inexact Rounded
-powx311 power -10 999999999 -> -1.00000000E+999999999 Rounded
-powx312 power -10.0001 999999999 -> -Infinity Overflow Inexact Rounded
-powx313 power -10.1 999999999 -> -Infinity Overflow Inexact Rounded
-powx314 power -11 999999999 -> -Infinity Overflow Inexact Rounded
-powx315 power -12 999999999 -> -Infinity Overflow Inexact Rounded
-powx316 power -999 999999999 -> -Infinity Overflow Inexact Rounded
-powx317 power -999999 999999999 -> -Infinity Overflow Inexact Rounded
-powx318 power -999999999 999999999 -> -Infinity Overflow Inexact Rounded
-powx319 power -9.9E999999999 999999999 -> -Infinity Overflow Inexact Rounded
-
-powx320 power -0.5 999999999 -> -4.33559594E-301029996 Inexact Rounded
-powx321 power -0.1 999999999 -> -1E-999999999
-powx322 power -0.09 999999999 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
-powx323 power -0.05 999999999 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
-powx324 power -0.01 999999999 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
-powx325 power -0.0001 999999999 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
-powx327 power -0.0000001 999999999 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
-powx328 power -0.0000000001 999999999 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
-powx329 power -1E-999999999 999999999 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+powx223 power 0E-30 3 -> 0
+powx224 power 0E-10 3 -> 0
+powx225 power 0E-1 3 -> 0
+powx226 power 0E+0 3 -> 0
+powx227 power 0 3 -> 0
+powx228 power 0E+1 3 -> 0
+powx229 power 0E+10 3 -> 0
+powx230 power 0E+30 3 -> 0
+powx231 power 3 0E-30 -> 1
+powx232 power 3 0E-10 -> 1
+powx233 power 3 0E-1 -> 1
+powx234 power 3 0E+0 -> 1
+powx235 power 3 0 -> 1
+powx236 power 3 0E+1 -> 1
+powx237 power 3 0E+10 -> 1
+powx238 power 3 0E+30 -> 1
+powx239 power 0E-30 -3 -> Infinity
+powx240 power 0E-10 -3 -> Infinity
+powx241 power 0E-1 -3 -> Infinity
+powx242 power 0E+0 -3 -> Infinity
+powx243 power 0 -3 -> Infinity
+powx244 power 0E+1 -3 -> Infinity
+powx245 power 0E+10 -3 -> Infinity
+powx246 power 0E+30 -3 -> Infinity
+powx247 power -3 0E-30 -> 1
+powx248 power -3 0E-10 -> 1
+powx249 power -3 0E-1 -> 1
+powx250 power -3 0E+0 -> 1
+powx251 power -3 0 -> 1
+powx252 power -3 0E+1 -> 1
+powx253 power -3 0E+10 -> 1
+powx254 power -3 0E+30 -> 1
--- note no trim of next result
-powx330 power -9 999999998 -> 3.39500060E+954242507 Inexact Rounded
-powx331 power -10 999999998 -> 1.00000000E+999999998 Rounded
-powx332 power -10.0001 999999998 -> Infinity Overflow Inexact Rounded
-powx333 power -10.1 999999998 -> Infinity Overflow Inexact Rounded
-powx334 power -11 999999998 -> Infinity Overflow Inexact Rounded
-powx335 power -12 999999998 -> Infinity Overflow Inexact Rounded
-powx336 power -999 999999998 -> Infinity Overflow Inexact Rounded
-powx337 power -999999 999999998 -> Infinity Overflow Inexact Rounded
-powx338 power -999999999 999999998 -> Infinity Overflow Inexact Rounded
-powx339 power -9.9E999999999 999999998 -> Infinity Overflow Inexact Rounded
-
-powx340 power -0.5 999999998 -> 8.67119187E-301029996 Inexact Rounded
-powx341 power -0.1 999999998 -> 1E-999999998 -- NB exact unrounded
-powx342 power -0.09 999999998 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
-powx343 power -0.05 999999998 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
-powx344 power -0.01 999999998 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
-powx345 power -0.0001 999999998 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
-powx347 power -0.0000001 999999998 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
-powx348 power -0.0000000001 999999998 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
-powx349 power -1E-999999999 999999998 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
-
--- some subnormals
+-- a few lhs negatives
precision: 9
--- [precision is 9, so smallest exponent is -1000000007
-powx350 power 1e-1 500000000 -> 1E-500000000
-powx351 power 1e-2 999999999 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
-powx352 power 1e-2 500000000 -> 1E-1000000000 Subnormal
-powx353 power 1e-2 500000001 -> 1E-1000000002 Subnormal
-powx354 power 1e-2 500000002 -> 1E-1000000004 Subnormal
-powx355 power 1e-2 500000003 -> 1E-1000000006 Subnormal
-powx356 power 1e-2 500000004 -> 0E-1000000007 Underflow Subnormal Inexact Rounded
-
-powx360 power 0.010001 500000000 -> 4.34941988E-999978287 Inexact Rounded
-powx361 power 0.010000001 500000000 -> 5.18469257E-999999979 Inexact Rounded
-powx362 power 0.010000001 500000001 -> 5.18469309E-999999981 Inexact Rounded
-powx363 power 0.0100000009 500000000 -> 3.49342003E-999999981 Inexact Rounded
-powx364 power 0.0100000001 500000000 -> 1.48413155E-999999998 Inexact Rounded
-powx365 power 0.01 500000000 -> 1E-1000000000 Subnormal
-powx366 power 0.0099999999 500000000 -> 6.7379E-1000000003 Underflow Subnormal Inexact Rounded
-powx367 power 0.0099999998 500000000 -> 4.54E-1000000005 Underflow Subnormal Inexact Rounded
-powx368 power 0.0099999997 500000000 -> 3E-1000000007 Underflow Subnormal Inexact Rounded
-powx369 power 0.0099999996 500000000 -> 0E-1000000007 Underflow Subnormal Inexact Rounded
-powx370 power 0.009 500000000 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
-
--- 1/subnormal -> overflow
-powx371 power 1e-1 -500000000 -> 1E+500000000
-powx372 power 1e-2 -999999999 -> Infinity Overflow Inexact Rounded
-powx373 power 1e-2 -500000000 -> Infinity Overflow Inexact Rounded
-powx374 power 1e-2 -500000001 -> Infinity Overflow Inexact Rounded
-powx375 power 1e-2 -500000002 -> Infinity Overflow Inexact Rounded
-powx376 power 1e-2 -500000003 -> Infinity Overflow Inexact Rounded
-powx377 power 1e-2 -500000004 -> Infinity Overflow Inexact Rounded
-
-powx381 power 0.010001 -500000000 -> 2.29915719E+999978286 Inexact Rounded
-powx382 power 0.010000001 -500000000 -> 1.92875467E+999999978 Inexact Rounded
-powx383 power 0.010000001 -500000001 -> 1.92875448E+999999980 Inexact Rounded
-powx384 power 0.0100000009 -500000000 -> 2.86252438E+999999980 Inexact Rounded
-powx385 power 0.0100000001 -500000000 -> 6.73794717E+999999997 Inexact Rounded
-powx386 power 0.01 -500000000 -> Infinity Overflow Inexact Rounded
-powx387 power 0.009999 -500000000 -> Infinity Overflow Inexact Rounded
-
--- negative power giving subnormal
-powx388 power 100.000001 -500000000 -> 6.7379E-1000000003 Underflow Subnormal Inexact Rounded
+maxExponent: 999
+minexponent: -999
+powx260 power -10 '0' -> 1
+powx261 power -10 '1' -> -10
+powx262 power -10 '2' -> 100
+powx263 power -10 '3' -> -1000
+powx264 power -10 '4' -> 10000
+powx265 power -10 '5' -> -100000
+powx266 power -10 '6' -> 1000000
+powx267 power -10 '7' -> -10000000
+powx268 power -10 '8' -> 100000000
+powx269 power -10 '9' -> -1.00000000E+9 Rounded
+powx270 power -10 '22' -> 1.00000000E+22 Rounded
+powx271 power -10 '77' -> -1.00000000E+77 Rounded
+powx272 power -10 '99' -> -1.00000000E+99 Rounded
-- some more edge cases
precision: 15
@@ -389,8 +252,9 @@
powx392 power 0.099 999 -> 4.360732062E-1004 Underflow Subnormal Inexact Rounded
powx393 power 0.098 999 -> 1.71731E-1008 Underflow Subnormal Inexact Rounded
powx394 power 0.097 999 -> 6E-1013 Underflow Subnormal Inexact Rounded
-powx395 power 0.096 999 -> 0E-1013 Underflow Subnormal Inexact Rounded
+powx395 power 0.096 999 -> 0E-1013 Underflow Subnormal Inexact Rounded Clamped
powx396 power 0.01 999 -> 0E-1013 Underflow Subnormal Inexact Rounded Clamped
+powx397 power 0.02 100000000 -> 0E-1013 Underflow Subnormal Inexact Rounded Clamped
-- multiply tests are here to aid checking and test for consistent handling
-- of underflow
@@ -399,7 +263,7 @@
minexponent: -999
-- squares
-mulx400 multiply 1E-502 1e-502 -> 0E-1003 Subnormal Inexact Underflow Rounded
+mulx400 multiply 1E-502 1e-502 -> 0E-1003 Subnormal Inexact Underflow Rounded Clamped
mulx401 multiply 1E-501 1e-501 -> 1E-1002 Subnormal
mulx402 multiply 2E-501 2e-501 -> 4E-1002 Subnormal
mulx403 multiply 4E-501 4e-501 -> 1.6E-1001 Subnormal
@@ -407,7 +271,7 @@
mulx405 multiply 30E-501 30e-501 -> 9.00E-1000 Subnormal
mulx406 multiply 40E-501 40e-501 -> 1.600E-999
-powx400 power 1E-502 2 -> 0E-1003 Underflow Subnormal Inexact Rounded
+powx400 power 1E-502 2 -> 0E-1003 Underflow Subnormal Inexact Rounded Clamped
powx401 power 1E-501 2 -> 1E-1002 Subnormal
powx402 power 2E-501 2 -> 4E-1002 Subnormal
powx403 power 4E-501 2 -> 1.6E-1001 Subnormal
@@ -416,7 +280,7 @@
powx406 power 40E-501 2 -> 1.600E-999
-- cubes
-mulx410 multiply 1E-670 1e-335 -> 0E-1003 Underflow Subnormal Inexact Rounded
+mulx410 multiply 1E-670 1e-335 -> 0E-1003 Underflow Subnormal Inexact Rounded Clamped
mulx411 multiply 1E-668 1e-334 -> 1E-1002 Subnormal
mulx412 multiply 4E-668 2e-334 -> 8E-1002 Subnormal
mulx413 multiply 9E-668 3e-334 -> 2.7E-1001 Subnormal
@@ -424,7 +288,7 @@
mulx415 multiply 25E-668 5e-334 -> 1.25E-1000 Subnormal
mulx416 multiply 10E-668 100e-334 -> 1.000E-999
-powx410 power 1E-335 3 -> 0E-1003 Underflow Subnormal Inexact Rounded
+powx410 power 1E-335 3 -> 0E-1003 Underflow Subnormal Inexact Rounded Clamped
powx411 power 1E-334 3 -> 1E-1002 Subnormal
powx412 power 2E-334 3 -> 8E-1002 Subnormal
powx413 power 3E-334 3 -> 2.7E-1001 Subnormal
@@ -442,24 +306,24 @@
powx423 power 2.5E+499 -2 -> 1.6E-999
powx424 power 2.5E+500 -2 -> 1.6E-1001 Subnormal
powx425 power 2.5E+501 -2 -> 2E-1003 Underflow Subnormal Inexact Rounded
-powx426 power 2.5E+502 -2 -> 0E-1003 Underflow Subnormal Inexact Rounded
+powx426 power 2.5E+502 -2 -> 0E-1003 Underflow Subnormal Inexact Rounded Clamped
powx427 power 0.25E+499 -2 -> 1.6E-997
powx428 power 0.25E+500 -2 -> 1.6E-999
powx429 power 0.25E+501 -2 -> 1.6E-1001 Subnormal
powx430 power 0.25E+502 -2 -> 2E-1003 Underflow Subnormal Inexact Rounded
-powx431 power 0.25E+503 -2 -> 0E-1003 Underflow Subnormal Inexact Rounded
+powx431 power 0.25E+503 -2 -> 0E-1003 Underflow Subnormal Inexact Rounded Clamped
powx432 power 0.04E+499 -2 -> 6.25E-996
powx433 power 0.04E+500 -2 -> 6.25E-998
powx434 power 0.04E+501 -2 -> 6.25E-1000 Subnormal
-powx435 power 0.04E+502 -2 -> 6.3E-1002 Underflow Subnormal Inexact Rounded
+powx435 power 0.04E+502 -2 -> 6.2E-1002 Underflow Subnormal Inexact Rounded
powx436 power 0.04E+503 -2 -> 1E-1003 Underflow Subnormal Inexact Rounded
-powx437 power 0.04E+504 -2 -> 0E-1003 Underflow Subnormal Inexact Rounded
+powx437 power 0.04E+504 -2 -> 0E-1003 Underflow Subnormal Inexact Rounded Clamped
powx441 power 0.04E+334 -3 -> 1.5625E-998
powx442 power 0.04E+335 -3 -> 1.56E-1001 Underflow Subnormal Inexact Rounded
-powx443 power 0.04E+336 -3 -> 0E-1003 Underflow Subnormal Inexact Rounded
+powx443 power 0.04E+336 -3 -> 0E-1003 Underflow Subnormal Inexact Rounded Clamped
powx444 power 0.25E+333 -3 -> 6.4E-998
powx445 power 0.25E+334 -3 -> 6.4E-1001 Subnormal
powx446 power 0.25E+335 -3 -> 1E-1003 Underflow Subnormal Inexact Rounded
@@ -467,7 +331,7 @@
-- check sign for cubes and a few squares
powx448 power -0.04E+334 -3 -> -1.5625E-998
powx449 power -0.04E+335 -3 -> -1.56E-1001 Underflow Subnormal Inexact Rounded
-powx450 power -0.04E+336 -3 -> -0E-1003 Underflow Subnormal Inexact Rounded
+powx450 power -0.04E+336 -3 -> -0E-1003 Underflow Subnormal Inexact Rounded Clamped
powx451 power -0.25E+333 -3 -> -6.4E-998
powx452 power -0.25E+334 -3 -> -6.4E-1001 Subnormal
powx453 power -0.25E+335 -3 -> -1E-1003 Underflow Subnormal Inexact Rounded
@@ -475,7 +339,7 @@
powx455 power -0.04E+499 -2 -> 6.25E-996
powx456 power -0.04E+500 -2 -> 6.25E-998
powx457 power -0.04E+501 -2 -> 6.25E-1000 Subnormal
-powx458 power -0.04E+502 -2 -> 6.3E-1002 Underflow Subnormal Inexact Rounded
+powx458 power -0.04E+502 -2 -> 6.2E-1002 Underflow Subnormal Inexact Rounded
-- test -0s
precision: 9
@@ -488,123 +352,124 @@
powx566 power -1 0 -> 1
powx567 power -1 -0 -> 1
powx568 power 0 1 -> 0
-powx569 power 0 -1 -> Infinity Division_by_zero
+powx569 power 0 -1 -> Infinity
powx570 power -0 1 -> -0
-powx571 power -0 -1 -> -Infinity Division_by_zero
+powx571 power -0 -1 -> -Infinity
powx572 power 0 2 -> 0
-powx573 power 0 -2 -> Infinity Division_by_zero
+powx573 power 0 -2 -> Infinity
powx574 power -0 2 -> 0
-powx575 power -0 -2 -> Infinity Division_by_zero
+powx575 power -0 -2 -> Infinity
powx576 power 0 3 -> 0
-powx577 power 0 -3 -> Infinity Division_by_zero
+powx577 power 0 -3 -> Infinity
powx578 power -0 3 -> -0
-powx579 power -0 -3 -> -Infinity Division_by_zero
+powx579 power -0 -3 -> -Infinity
-- Specials
-powx580 power Inf -Inf -> NaN Invalid_operation
+powx580 power Inf -Inf -> 0
powx581 power Inf -1000 -> 0
powx582 power Inf -1 -> 0
-powx583 power Inf -0 -> 1
-powx584 power Inf 0 -> 1
-powx585 power Inf 1 -> Infinity
-powx586 power Inf 1000 -> Infinity
-powx587 power Inf Inf -> NaN Invalid_operation
-powx588 power -1000 Inf -> NaN Invalid_operation
-powx589 power -Inf Inf -> NaN Invalid_operation
-powx590 power -1 Inf -> NaN Invalid_operation
-powx591 power -0 Inf -> NaN Invalid_operation
-powx592 power 0 Inf -> NaN Invalid_operation
-powx593 power 1 Inf -> NaN Invalid_operation
-powx594 power 1000 Inf -> NaN Invalid_operation
-powx595 power Inf Inf -> NaN Invalid_operation
+powx583 power Inf -0.5 -> 0
+powx584 power Inf -0 -> 1
+powx585 power Inf 0 -> 1
+powx586 power Inf 0.5 -> Infinity
+powx587 power Inf 1 -> Infinity
+powx588 power Inf 1000 -> Infinity
+powx589 power Inf Inf -> Infinity
+powx590 power -1000 Inf -> NaN Invalid_operation
+powx591 power -Inf Inf -> NaN Invalid_operation
+powx592 power -1 Inf -> NaN Invalid_operation
+powx593 power -0.5 Inf -> NaN Invalid_operation
+powx594 power -0 Inf -> 0
+powx595 power 0 Inf -> 0
+powx596 power 0.5 Inf -> 0
+powx597 power 1 Inf -> 1.00000000 Inexact Rounded
+powx598 power 1000 Inf -> Infinity
+powx599 power Inf Inf -> Infinity
powx600 power -Inf -Inf -> NaN Invalid_operation
powx601 power -Inf -1000 -> 0
powx602 power -Inf -1 -> -0
-powx603 power -Inf -0 -> 1
-powx604 power -Inf 0 -> 1
-powx605 power -Inf 1 -> -Infinity
-powx606 power -Inf 1000 -> Infinity
-powx607 power -Inf Inf -> NaN Invalid_operation
-powx608 power -1000 Inf -> NaN Invalid_operation
-powx609 power -Inf -Inf -> NaN Invalid_operation
-powx610 power -1 -Inf -> NaN Invalid_operation
-powx611 power -0 -Inf -> NaN Invalid_operation
-powx612 power 0 -Inf -> NaN Invalid_operation
-powx613 power 1 -Inf -> NaN Invalid_operation
-powx614 power 1000 -Inf -> NaN Invalid_operation
-powx615 power Inf -Inf -> NaN Invalid_operation
+powx603 power -Inf -0.5 -> NaN Invalid_operation
+powx604 power -Inf -0 -> 1
+powx605 power -Inf 0 -> 1
+powx606 power -Inf 0.5 -> NaN Invalid_operation
+powx607 power -Inf 1 -> -Infinity
+powx608 power -Inf 1000 -> Infinity
+powx609 power -Inf Inf -> NaN Invalid_operation
+powx610 power -1000 Inf -> NaN Invalid_operation
+powx611 power -Inf -Inf -> NaN Invalid_operation
+powx612 power -1 -Inf -> NaN Invalid_operation
+powx613 power -0.5 -Inf -> NaN Invalid_operation
+powx614 power -0 -Inf -> Infinity
+powx615 power 0 -Inf -> Infinity
+powx616 power 0.5 -Inf -> Infinity
+powx617 power 1 -Inf -> 1.00000000 Inexact Rounded
+powx618 power 1000 -Inf -> 0
+powx619 power Inf -Inf -> 0
-powx621 power NaN -Inf -> NaN Invalid_operation
+powx621 power NaN -Inf -> NaN
powx622 power NaN -1000 -> NaN
powx623 power NaN -1 -> NaN
-powx624 power NaN -0 -> NaN
-powx625 power NaN 0 -> NaN
-powx626 power NaN 1 -> NaN
-powx627 power NaN 1000 -> NaN
-powx628 power NaN Inf -> NaN Invalid_operation
-powx629 power NaN NaN -> NaN
-powx630 power -Inf NaN -> NaN
-powx631 power -1000 NaN -> NaN
-powx632 power -1 NaN -> NaN
-powx633 power -0 NaN -> NaN
-powx634 power 0 NaN -> NaN
-powx635 power 1 NaN -> NaN
-powx636 power 1000 NaN -> NaN
-powx637 power Inf NaN -> NaN
+powx624 power NaN -0.5 -> NaN
+powx625 power NaN -0 -> NaN
+powx626 power NaN 0 -> NaN
+powx627 power NaN 0.5 -> NaN
+powx628 power NaN 1 -> NaN
+powx629 power NaN 1000 -> NaN
+powx630 power NaN Inf -> NaN
+powx631 power NaN NaN -> NaN
+powx632 power -Inf NaN -> NaN
+powx633 power -1000 NaN -> NaN
+powx634 power -1 NaN -> NaN
+powx635 power -0 NaN -> NaN
+powx636 power 0 NaN -> NaN
+powx637 power 1 NaN -> NaN
+powx638 power 1000 NaN -> NaN
+powx639 power Inf NaN -> NaN
powx641 power sNaN -Inf -> NaN Invalid_operation
powx642 power sNaN -1000 -> NaN Invalid_operation
powx643 power sNaN -1 -> NaN Invalid_operation
-powx644 power sNaN -0 -> NaN Invalid_operation
-powx645 power sNaN 0 -> NaN Invalid_operation
-powx646 power sNaN 1 -> NaN Invalid_operation
-powx647 power sNaN 1000 -> NaN Invalid_operation
-powx648 power sNaN NaN -> NaN Invalid_operation
-powx649 power sNaN sNaN -> NaN Invalid_operation
-powx650 power NaN sNaN -> NaN Invalid_operation
-powx651 power -Inf sNaN -> NaN Invalid_operation
-powx652 power -1000 sNaN -> NaN Invalid_operation
-powx653 power -1 sNaN -> NaN Invalid_operation
-powx654 power -0 sNaN -> NaN Invalid_operation
-powx655 power 0 sNaN -> NaN Invalid_operation
-powx656 power 1 sNaN -> NaN Invalid_operation
-powx657 power 1000 sNaN -> NaN Invalid_operation
-powx658 power Inf sNaN -> NaN Invalid_operation
-powx659 power NaN sNaN -> NaN Invalid_operation
+powx644 power sNaN -0.5 -> NaN Invalid_operation
+powx645 power sNaN -0 -> NaN Invalid_operation
+powx646 power sNaN 0 -> NaN Invalid_operation
+powx647 power sNaN 0.5 -> NaN Invalid_operation
+powx648 power sNaN 1 -> NaN Invalid_operation
+powx649 power sNaN 1000 -> NaN Invalid_operation
+powx650 power sNaN NaN -> NaN Invalid_operation
+powx651 power sNaN sNaN -> NaN Invalid_operation
+powx652 power NaN sNaN -> NaN Invalid_operation
+powx653 power -Inf sNaN -> NaN Invalid_operation
+powx654 power -1000 sNaN -> NaN Invalid_operation
+powx655 power -1 sNaN -> NaN Invalid_operation
+powx656 power -0.5 sNaN -> NaN Invalid_operation
+powx657 power -0 sNaN -> NaN Invalid_operation
+powx658 power 0 sNaN -> NaN Invalid_operation
+powx659 power 0.5 sNaN -> NaN Invalid_operation
+powx660 power 1 sNaN -> NaN Invalid_operation
+powx661 power 1000 sNaN -> NaN Invalid_operation
+powx662 power Inf sNaN -> NaN Invalid_operation
+powx663 power NaN sNaN -> NaN Invalid_operation
-- NaN propagation
-powx660 power NaN3 sNaN7 -> NaN7 Invalid_operation
-powx661 power sNaN8 NaN6 -> NaN8 Invalid_operation
-powx662 power 1 sNaN7 -> NaN7 Invalid_operation
-powx663 power sNaN8 1 -> NaN8 Invalid_operation
-powx664 power Inf sNaN7 -> NaN7 Invalid_operation
-powx665 power sNaN8 Inf -> NaN Invalid_operation
-powx666 power Inf NaN9 -> NaN9
-powx667 power NaN6 Inf -> NaN Invalid_operation
-powx668 power 1 NaN5 -> NaN5
-powx669 power NaN2 1 -> NaN2
-powx670 power NaN2 Nan4 -> NaN2
-powx671 power NaN Nan4 -> NaN
-powx672 power NaN345 Nan -> NaN345
-powx673 power Inf -sNaN7 -> -NaN7 Invalid_operation
-powx674 power -sNaN8 Inf -> NaN Invalid_operation
-powx675 power Inf -NaN9 -> -NaN9
-powx676 power -NaN6 Inf -> NaN Invalid_operation
-powx677 power -NaN2 -Nan4 -> -NaN2
-
--- Examples from extended specification
-powx690 power Inf -2 -> 0
-powx691 power Inf -1 -> 0
-powx692 power Inf 0 -> 1
-powx693 power Inf 1 -> Infinity
-powx694 power Inf 2 -> Infinity
-powx695 power -Inf -2 -> 0
-powx696 power -Inf -1 -> -0
-powx697 power -Inf 0 -> 1
-powx698 power -Inf 1 -> -Infinity
-powx699 power -Inf 2 -> Infinity
-powx700 power 0 0 -> NaN Invalid_operation
+powx670 power NaN3 sNaN7 -> NaN7 Invalid_operation
+powx671 power sNaN8 NaN6 -> NaN8 Invalid_operation
+powx672 power 1 sNaN7 -> NaN7 Invalid_operation
+powx673 power sNaN8 1 -> NaN8 Invalid_operation
+powx674 power Inf sNaN7 -> NaN7 Invalid_operation
+powx675 power sNaN8 Inf -> NaN8 Invalid_operation
+powx676 power Inf NaN9 -> NaN9
+powx677 power NaN6 Inf -> NaN6
+powx678 power 1 NaN5 -> NaN5
+powx679 power NaN2 1 -> NaN2
+powx680 power NaN2 Nan4 -> NaN2
+powx681 power NaN Nan4 -> NaN
+powx682 power NaN345 Nan -> NaN345
+powx683 power Inf -sNaN7 -> -NaN7 Invalid_operation
+powx684 power -sNaN8 Inf -> -NaN8 Invalid_operation
+powx685 power Inf -NaN9 -> -NaN9
+powx686 power -NaN6 Inf -> -NaN6
+powx687 power -NaN2 -Nan4 -> -NaN2
-- long operand and RHS range checks
maxexponent: 999
@@ -616,15 +481,6 @@
powx704 power 1234567891 1 -> 1.23456789E+9 Inexact Rounded
powx705 power 12345678901 1 -> 1.23456789E+10 Inexact Rounded
powx706 power 1234567896 1 -> 1.23456790E+9 Inexact Rounded
-powx707 power 1 12345678000 -> NaN Invalid_operation
-powx708 power 1 1234567800 -> NaN Invalid_operation
-powx709 power 1 1234567890 -> NaN Invalid_operation
-powx710 power 1 11234567891 -> NaN Invalid_operation
-powx711 power 1 12345678901 -> NaN Invalid_operation
-powx712 power 1 1234567896 -> NaN Invalid_operation
-powx713 power 1 -1234567896 -> NaN Invalid_operation
-powx714 power 1 1000000000 -> NaN Invalid_operation
-powx715 power 1 -1000000000 -> NaN Invalid_operation
precision: 15
-- still checking
@@ -634,12 +490,182 @@
powx744 power 1234567891 1 -> 1234567891
powx745 power 12345678901 1 -> 12345678901
powx746 power 1234567896 1 -> 1234567896
-powx747 power 1 12345678000 -> NaN Invalid_operation
-powx748 power 1 -1234567896 -> NaN Invalid_operation
-powx749 power 1 1000000000 -> NaN Invalid_operation
-powx740 power 1 -1000000000 -> NaN Invalid_operation
--- check for double-rounded subnormals
+maxexponent: 999999
+minexponent: -999999
+precision: 9
+
+-- near out-of-range edge cases
+powx163 power '10' '999999' -> '1.00000000E+999999' Rounded
+powx164 power '10' '999998' -> '1.00000000E+999998' Rounded
+powx165 power '10' '999997' -> '1.00000000E+999997' Rounded
+powx166 power '10' '333333' -> '1.00000000E+333333' Rounded
+powx183 power '7' '1000000' -> 1.09651419E+845098 Inexact Rounded
+powx184 power '7' '1000001' -> 7.67559934E+845098 Inexact Rounded
+powx186 power '7' '-1000001' -> 1.30282986E-845099 Inexact Rounded
+powx187 power '7' '-1000000' -> 9.11980901E-845099 Inexact Rounded
+powx118 power '10' '-333333' -> 1E-333333
+powx119 power '10' '-999998' -> 1E-999998
+powx120 power '10' '-999999' -> 1E-999999
+powx181 power '7' '999998' -> 2.23778406E+845096 Inexact Rounded
+powx182 power '7' '999999' -> 1.56644884E+845097 Inexact Rounded
+powx189 power '7' '-999999' -> 6.38386631E-845098 Inexact Rounded
+powx190 power '7' '-999998' -> 4.46870641E-845097 Inexact Rounded
+
+-- overflow and underflow tests
+precision: 9
+
+powx277 power 9 999999 -> 3.59084629E+954241 Inexact Rounded
+powx278 power 9.99999999 999999 -> 9.99000501E+999998 Inexact Rounded
+powx279 power 10 999999 -> 1.00000000E+999999 Rounded
+powx280 power 10.0000001 999999 -> 1.01005016E+999999 Inexact Rounded
+powx281 power 10.000001 999999 -> 1.10517080E+999999 Inexact Rounded
+powx282 power 10.00001 999999 -> 2.71827775E+999999 Inexact Rounded
+powx283 power 10.0001 999999 -> Infinity Overflow Inexact Rounded
+powx285 power 11 999999 -> Infinity Overflow Inexact Rounded
+powx286 power 12 999999 -> Infinity Overflow Inexact Rounded
+powx287 power 999 999999 -> Infinity Overflow Inexact Rounded
+powx288 power 999999999 999999 -> Infinity Overflow Inexact Rounded
+powx289 power 9.9E999999999 999999 -> Infinity Overflow Inexact Rounded
+
+powx290 power 0.5 999999 -> 2.02006812E-301030 Inexact Rounded
+powx291 power 0.1 999999 -> 1E-999999 -- unrounded
+powx292 power 0.09 999999 -> 0E-1000007 Underflow Subnormal Inexact Rounded Clamped
+powx293 power 0.05 999999 -> 0E-1000007 Underflow Subnormal Inexact Rounded Clamped
+powx294 power 0.01 999999 -> 0E-1000007 Underflow Subnormal Inexact Rounded Clamped
+powx295 power 0.0001 999999 -> 0E-1000007 Underflow Subnormal Inexact Rounded Clamped
+powx297 power 0.0000001 999999 -> 0E-1000007 Underflow Subnormal Inexact Rounded Clamped
+powx298 power 0.0000000001 999999 -> 0E-1000007 Underflow Subnormal Inexact Rounded Clamped
+powx299 power 1E-999999999 999999 -> 0E-1000007 Underflow Subnormal Inexact Rounded Clamped
+
+powx310 power -9 999999 -> -3.59084629E+954241 Inexact Rounded
+powx311 power -10 999999 -> -1.00000000E+999999 Rounded
+powx312 power -10.0001 999999 -> -Infinity Overflow Inexact Rounded
+powx313 power -10.1 999999 -> -Infinity Overflow Inexact Rounded
+powx314 power -11 999999 -> -Infinity Overflow Inexact Rounded
+powx315 power -12 999999 -> -Infinity Overflow Inexact Rounded
+powx316 power -999 999999 -> -Infinity Overflow Inexact Rounded
+powx317 power -999999 999999 -> -Infinity Overflow Inexact Rounded
+powx318 power -999999999 999999 -> -Infinity Overflow Inexact Rounded
+powx319 power -9.9E999999999 999999 -> -Infinity Overflow Inexact Rounded
+
+powx320 power -0.5 999999 -> -2.02006812E-301030 Inexact Rounded
+powx321 power -0.1 999999 -> -1E-999999
+powx322 power -0.09 999999 -> -0E-1000007 Underflow Subnormal Inexact Rounded Clamped
+powx323 power -0.05 999999 -> -0E-1000007 Underflow Subnormal Inexact Rounded Clamped
+powx324 power -0.01 999999 -> -0E-1000007 Underflow Subnormal Inexact Rounded Clamped
+powx325 power -0.0001 999999 -> -0E-1000007 Underflow Subnormal Inexact Rounded Clamped
+powx327 power -0.0000001 999999 -> -0E-1000007 Underflow Subnormal Inexact Rounded Clamped
+powx328 power -0.0000000001 999999 -> -0E-1000007 Underflow Subnormal Inexact Rounded Clamped
+powx329 power -1E-999999999 999999 -> -0E-1000007 Underflow Subnormal Inexact Rounded Clamped
+
+-- note no trim of next result
+powx330 power -9 999998 -> 3.98982921E+954240 Inexact Rounded
+powx331 power -10 999998 -> 1.00000000E+999998 Rounded
+powx332 power -10.0001 999998 -> Infinity Overflow Inexact Rounded
+powx333 power -10.1 999998 -> Infinity Overflow Inexact Rounded
+powx334 power -11 999998 -> Infinity Overflow Inexact Rounded
+powx335 power -12 999998 -> Infinity Overflow Inexact Rounded
+powx336 power -999 999998 -> Infinity Overflow Inexact Rounded
+powx337 power -999999 999998 -> Infinity Overflow Inexact Rounded
+powx338 power -999999999 999998 -> Infinity Overflow Inexact Rounded
+powx339 power -9.9E999999999 999998 -> Infinity Overflow Inexact Rounded
+
+powx340 power -0.5 999998 -> 4.04013624E-301030 Inexact Rounded
+powx341 power -0.1 999998 -> 1E-999998 -- NB exact unrounded
+powx342 power -0.09 999998 -> 0E-1000007 Underflow Subnormal Inexact Rounded Clamped
+powx343 power -0.05 999998 -> 0E-1000007 Underflow Subnormal Inexact Rounded Clamped
+powx344 power -0.01 999998 -> 0E-1000007 Underflow Subnormal Inexact Rounded Clamped
+powx345 power -0.0001 999998 -> 0E-1000007 Underflow Subnormal Inexact Rounded Clamped
+powx347 power -0.0000001 999998 -> 0E-1000007 Underflow Subnormal Inexact Rounded Clamped
+powx348 power -0.0000000001 999998 -> 0E-1000007 Underflow Subnormal Inexact Rounded Clamped
+powx349 power -1E-999999999 999998 -> 0E-1000007 Underflow Subnormal Inexact Rounded Clamped
+
+-- some subnormals
+precision: 9
+-- [precision is 9, so smallest exponent is -1000000007
+powx350 power 1e-1 500000 -> 1E-500000
+powx351 power 1e-2 999999 -> 0E-1000007 Underflow Subnormal Inexact Rounded Clamped
+powx352 power 1e-2 500000 -> 1E-1000000 Subnormal
+powx353 power 1e-2 500001 -> 1E-1000002 Subnormal
+powx354 power 1e-2 500002 -> 1E-1000004 Subnormal
+powx355 power 1e-2 500003 -> 1E-1000006 Subnormal
+powx356 power 1e-2 500004 -> 0E-1000007 Underflow Subnormal Inexact Rounded Clamped
+
+powx360 power 0.010001 500000 -> 5.17176082E-999979 Inexact Rounded
+powx361 power 0.010000001 500000 -> 1.0512711E-1000000 Underflow Subnormal Inexact Rounded
+powx362 power 0.010000001 500001 -> 1.05127E-1000002 Underflow Subnormal Inexact Rounded
+powx363 power 0.0100000009 500000 -> 1.0460279E-1000000 Underflow Subnormal Inexact Rounded
+powx364 power 0.0100000001 500000 -> 1.0050125E-1000000 Underflow Subnormal Inexact Rounded
+powx365 power 0.01 500000 -> 1E-1000000 Subnormal
+powx366 power 0.0099999999 500000 -> 9.950125E-1000001 Underflow Subnormal Inexact Rounded
+powx367 power 0.0099999998 500000 -> 9.900498E-1000001 Underflow Subnormal Inexact Rounded
+powx368 power 0.0099999997 500000 -> 9.851119E-1000001 Underflow Subnormal Inexact Rounded
+powx369 power 0.0099999996 500000 -> 9.801987E-1000001 Underflow Subnormal Inexact Rounded
+powx370 power 0.009 500000 -> 0E-1000007 Underflow Subnormal Inexact Rounded Clamped
+
+-- 1/subnormal -> overflow
+powx371 power 1e-1 -500000 -> 1E+500000
+powx372 power 1e-2 -999999 -> Infinity Overflow Inexact Rounded
+powx373 power 1e-2 -500000 -> Infinity Overflow Inexact Rounded
+powx374 power 1e-2 -500001 -> Infinity Overflow Inexact Rounded
+powx375 power 1e-2 -500002 -> Infinity Overflow Inexact Rounded
+powx376 power 1e-2 -500003 -> Infinity Overflow Inexact Rounded
+powx377 power 1e-2 -500004 -> Infinity Overflow Inexact Rounded
+
+powx381 power 0.010001 -500000 -> 1.93357743E+999978 Inexact Rounded
+powx382 power 0.010000001 -500000 -> 9.51229427E+999999 Inexact Rounded
+powx383 power 0.010000001 -500001 -> Infinity Overflow Inexact Rounded
+powx384 power 0.0100000009 -500000 -> 9.55997484E+999999 Inexact Rounded
+powx385 power 0.0100000001 -500000 -> 9.95012479E+999999 Inexact Rounded
+powx386 power 0.01 -500000 -> Infinity Overflow Inexact Rounded
+powx387 power 0.009999 -500000 -> Infinity Overflow Inexact Rounded
+
+-- negative power giving subnormal
+powx388 power 100.000001 -500000 -> 9.950125E-1000001 Underflow Subnormal Inexact Rounded
+
+
+-- test some 'false integer' boundaries
+precision: 16
+rounding: half_even
+maxExponent: 384
+minExponent: -383
+powx501 power 100 1E+1 -> 1.000000000000000E+20 Rounded
+powx502 power 100 1E+2 -> 1.000000000000000E+200 Rounded
+powx503 power 100 1E+3 -> Infinity Overflow Inexact Rounded
+powx504 power 100 1E+4 -> Infinity Overflow Inexact Rounded
+powx505 power 100 1E+5 -> Infinity Overflow Inexact Rounded
+powx506 power 100 1E+6 -> Infinity Overflow Inexact Rounded
+powx507 power 100 1E+7 -> Infinity Overflow Inexact Rounded
+powx508 power 100 1E+8 -> Infinity Overflow Inexact Rounded
+powx509 power 100 1E+9 -> Infinity Overflow Inexact Rounded
+powx510 power 100 1E+10 -> Infinity Overflow Inexact Rounded
+powx511 power 100 1E+11 -> Infinity Overflow Inexact Rounded
+powx512 power 100 1E+12 -> Infinity Overflow Inexact Rounded
+powx513 power 100 1E+13 -> Infinity Overflow Inexact Rounded
+powx514 power 100 1E+14 -> Infinity Overflow Inexact Rounded
+powx515 power 100 1E+15 -> Infinity Overflow Inexact Rounded
+powx516 power 100 1E+16 -> Infinity Overflow Inexact Rounded
+powx517 power 100 1E+17 -> Infinity Overflow Inexact Rounded
+powx518 power 100 1E+18 -> Infinity Overflow Inexact Rounded
+powx519 power 100 1E+19 -> Infinity Overflow Inexact Rounded
+powx520 power 100 1E+20 -> Infinity Overflow Inexact Rounded
+powx521 power 100 1E+21 -> Infinity Overflow Inexact Rounded
+powx522 power 100 1E+22 -> Infinity Overflow Inexact Rounded
+powx523 power 100 1E+23 -> Infinity Overflow Inexact Rounded
+powx524 power 100 1E+24 -> Infinity Overflow Inexact Rounded
+powx525 power 100 1E+25 -> Infinity Overflow Inexact Rounded
+powx526 power 100 1E+26 -> Infinity Overflow Inexact Rounded
+powx527 power 100 1E+27 -> Infinity Overflow Inexact Rounded
+powx528 power 100 1E+28 -> Infinity Overflow Inexact Rounded
+powx529 power 100 1E+29 -> Infinity Overflow Inexact Rounded
+powx530 power 100 1E+30 -> Infinity Overflow Inexact Rounded
+powx531 power 100 1E+40 -> Infinity Overflow Inexact Rounded
+powx532 power 100 1E+50 -> Infinity Overflow Inexact Rounded
+powx533 power 100 1E+100 -> Infinity Overflow Inexact Rounded
+powx534 power 100 1E+383 -> Infinity Overflow Inexact Rounded
+
+-- a check for double-rounded subnormals
precision: 5
maxexponent: 79
minexponent: -79
@@ -649,3 +675,950 @@
powx900 power 1 # -> NaN Invalid_operation
powx901 power # 1 -> NaN Invalid_operation
+----------------------------------------------------------------------
+-- Below here are tests with a precision or context outside of the --
+-- decNumber 'mathematical functions' restricted range. These --
+-- remain supported in decNumber to minimize breakage, but may be --
+-- outside the range of other implementations. --
+----------------------------------------------------------------------
+maxexponent: 999999999
+minexponent: -999999999
+precision: 9
+powx1063 power '10' '999999999' -> '1.00000000E+999999999' Rounded
+powx1064 power '10' '999999998' -> '1.00000000E+999999998' Rounded
+powx1065 power '10' '999999997' -> '1.00000000E+999999997' Rounded
+powx1066 power '10' '333333333' -> '1.00000000E+333333333' Rounded
+-- next two are integer-out-of range
+powx1183 power '7' '1000000000' -> NaN Invalid_context
+powx1184 power '7' '1000000001' -> NaN Invalid_context
+powx1186 power '7' '-1000000001' -> 1.38243630E-845098041 Inexact Rounded
+powx1187 power '7' '-1000000000' -> 9.67705411E-845098041 Inexact Rounded
+
+-- out-of-range edge cases
+powx1118 power '10' '-333333333' -> 1E-333333333
+powx1119 power '10' '-999999998' -> 1E-999999998
+powx1120 power '10' '-999999999' -> 1E-999999999
+powx1181 power '7' '999999998' -> 2.10892313E+845098038 Inexact Rounded
+powx1182 power '7' '999999999' -> 1.47624619E+845098039 Inexact Rounded
+powx1189 power '7' '-999999999' -> 6.77393787E-845098040 Inexact Rounded
+powx1190 power '7' '-999999998' -> 4.74175651E-845098039 Inexact Rounded
+
+-- A (rare) case where the last digit is not within 0.5 ULP with classic precision
+precision: 9
+powx1215 power "-21971575.0E+31454441" "-7" -> "-4.04549502E-220181139" Inexact Rounded
+precision: 20
+powx1216 power "-21971575.0E+31454441" "-7" -> "-4.0454950249324891788E-220181139" Inexact Rounded
+
+-- overflow and underflow tests
+precision: 9
+powx1280 power 9 999999999 -> 3.05550054E+954242508 Inexact Rounded
+powx1281 power 10 999999999 -> 1.00000000E+999999999 Rounded
+powx1282 power 10.0001 999999999 -> Infinity Overflow Inexact Rounded
+powx1283 power 10.1 999999999 -> Infinity Overflow Inexact Rounded
+powx1284 power 11 999999999 -> Infinity Overflow Inexact Rounded
+powx1285 power 12 999999999 -> Infinity Overflow Inexact Rounded
+powx1286 power 999 999999999 -> Infinity Overflow Inexact Rounded
+powx1287 power 999999 999999999 -> Infinity Overflow Inexact Rounded
+powx1288 power 999999999 999999999 -> Infinity Overflow Inexact Rounded
+powx1289 power 9.9E999999999 999999999 -> Infinity Overflow Inexact Rounded
+
+powx1290 power 0.5 999999999 -> 4.33559594E-301029996 Inexact Rounded
+powx1291 power 0.1 999999999 -> 1E-999999999 -- unrounded
+powx1292 power 0.09 999999999 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+powx1293 power 0.05 999999999 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+powx1294 power 0.01 999999999 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+powx1295 power 0.0001 999999999 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+powx1297 power 0.0000001 999999999 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+powx1298 power 0.0000000001 999999999 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+powx1299 power 1E-999999999 999999999 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+
+powx1310 power -9 999999999 -> -3.05550054E+954242508 Inexact Rounded
+powx1311 power -10 999999999 -> -1.00000000E+999999999 Rounded
+powx1312 power -10.0001 999999999 -> -Infinity Overflow Inexact Rounded
+powx1313 power -10.1 999999999 -> -Infinity Overflow Inexact Rounded
+powx1314 power -11 999999999 -> -Infinity Overflow Inexact Rounded
+powx1315 power -12 999999999 -> -Infinity Overflow Inexact Rounded
+powx1316 power -999 999999999 -> -Infinity Overflow Inexact Rounded
+powx1317 power -999999 999999999 -> -Infinity Overflow Inexact Rounded
+powx1318 power -999999999 999999999 -> -Infinity Overflow Inexact Rounded
+powx1319 power -9.9E999999999 999999999 -> -Infinity Overflow Inexact Rounded
+
+powx1320 power -0.5 999999999 -> -4.33559594E-301029996 Inexact Rounded
+powx1321 power -0.1 999999999 -> -1E-999999999
+powx1322 power -0.09 999999999 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+powx1323 power -0.05 999999999 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+powx1324 power -0.01 999999999 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+powx1325 power -0.0001 999999999 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+powx1327 power -0.0000001 999999999 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+powx1328 power -0.0000000001 999999999 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+powx1329 power -1E-999999999 999999999 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+
+-- note no trim of next result
+powx1330 power -9 999999998 -> 3.39500060E+954242507 Inexact Rounded
+powx1331 power -10 999999998 -> 1.00000000E+999999998 Rounded
+powx1332 power -10.0001 999999998 -> Infinity Overflow Inexact Rounded
+powx1333 power -10.1 999999998 -> Infinity Overflow Inexact Rounded
+powx1334 power -11 999999998 -> Infinity Overflow Inexact Rounded
+powx1335 power -12 999999998 -> Infinity Overflow Inexact Rounded
+powx1336 power -999 999999998 -> Infinity Overflow Inexact Rounded
+powx1337 power -999999 999999998 -> Infinity Overflow Inexact Rounded
+powx1338 power -999999999 999999998 -> Infinity Overflow Inexact Rounded
+powx1339 power -9.9E999999999 999999998 -> Infinity Overflow Inexact Rounded
+
+powx1340 power -0.5 999999998 -> 8.67119187E-301029996 Inexact Rounded
+powx1341 power -0.1 999999998 -> 1E-999999998 -- NB exact unrounded
+powx1342 power -0.09 999999998 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+powx1343 power -0.05 999999998 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+powx1344 power -0.01 999999998 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+powx1345 power -0.0001 999999998 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+powx1347 power -0.0000001 999999998 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+powx1348 power -0.0000000001 999999998 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+powx1349 power -1E-999999999 999999998 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+
+-- some subnormals
+precision: 9
+-- [precision is 9, so smallest exponent is -1000000007
+powx1350 power 1e-1 500000000 -> 1E-500000000
+powx1351 power 1e-2 999999999 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+powx1352 power 1e-2 500000000 -> 1E-1000000000 Subnormal
+powx1353 power 1e-2 500000001 -> 1E-1000000002 Subnormal
+powx1354 power 1e-2 500000002 -> 1E-1000000004 Subnormal
+powx1355 power 1e-2 500000003 -> 1E-1000000006 Subnormal
+powx1356 power 1e-2 500000004 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+
+powx1360 power 0.010001 500000000 -> 4.34941988E-999978287 Inexact Rounded
+powx1361 power 0.010000001 500000000 -> 5.18469257E-999999979 Inexact Rounded
+powx1362 power 0.010000001 500000001 -> 5.18469309E-999999981 Inexact Rounded
+powx1363 power 0.0100000009 500000000 -> 3.49342003E-999999981 Inexact Rounded
+powx1364 power 0.0100000001 500000000 -> 1.48413155E-999999998 Inexact Rounded
+powx1365 power 0.01 500000000 -> 1E-1000000000 Subnormal
+powx1366 power 0.0099999999 500000000 -> 6.7379E-1000000003 Underflow Subnormal Inexact Rounded
+powx1367 power 0.0099999998 500000000 -> 4.54E-1000000005 Underflow Subnormal Inexact Rounded
+powx1368 power 0.0099999997 500000000 -> 3E-1000000007 Underflow Subnormal Inexact Rounded
+powx1369 power 0.0099999996 500000000 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+powx1370 power 0.009 500000000 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
+
+-- 1/subnormal -> overflow
+powx1371 power 1e-1 -500000000 -> 1E+500000000
+powx1372 power 1e-2 -999999999 -> Infinity Overflow Inexact Rounded
+powx1373 power 1e-2 -500000000 -> Infinity Overflow Inexact Rounded
+powx1374 power 1e-2 -500000001 -> Infinity Overflow Inexact Rounded
+powx1375 power 1e-2 -500000002 -> Infinity Overflow Inexact Rounded
+powx1376 power 1e-2 -500000003 -> Infinity Overflow Inexact Rounded
+powx1377 power 1e-2 -500000004 -> Infinity Overflow Inexact Rounded
+
+powx1381 power 0.010001 -500000000 -> 2.29915719E+999978286 Inexact Rounded
+powx1382 power 0.010000001 -500000000 -> 1.92875467E+999999978 Inexact Rounded
+powx1383 power 0.010000001 -500000001 -> 1.92875448E+999999980 Inexact Rounded
+powx1384 power 0.0100000009 -500000000 -> 2.86252438E+999999980 Inexact Rounded
+powx1385 power 0.0100000001 -500000000 -> 6.73794717E+999999997 Inexact Rounded
+powx1386 power 0.01 -500000000 -> Infinity Overflow Inexact Rounded
+powx1387 power 0.009999 -500000000 -> Infinity Overflow Inexact Rounded
+
+-- negative power giving subnormal
+powx1388 power 100.000001 -500000000 -> 6.7379E-1000000003 Underflow Subnormal Inexact Rounded
+
+----------------------------------------------------------------------
+-- Below here are the tests with a non-integer rhs, including the --
+-- tests that previously caused Invalid operation. An integer-only --
+-- (on rhs) implementation should handle all the tests above as --
+-- shown, and would flag most of the following tests as Invalid. --
+----------------------------------------------------------------------
+precision: 16
+rounding: half_even
+maxExponent: 384
+minExponent: -383
+
+powx2000 power 7 '10000000000' -> Infinity Overflow Inexact Rounded
+powx2001 power 2 '2.000001' -> 4.000002772589683 Inexact Rounded
+powx2002 power 2 '2.00000000' -> 4
+powx2003 power 2 '2.000000001' -> 4.000000002772589 Inexact Rounded
+powx2004 power 2 '2.0000000001' -> 4.000000000277259 Inexact Rounded
+powx2005 power 2 '2.00000000001' -> 4.000000000027726 Inexact Rounded
+powx2006 power 2 '2.000000000001' -> 4.000000000002773 Inexact Rounded
+powx2007 power 2 '2.0000000000001' -> 4.000000000000277 Inexact Rounded
+powx2008 power 2 '2.00000000000001' -> 4.000000000000028 Inexact Rounded
+powx2009 power 2 '2.000000000000001' -> 4.000000000000003 Inexact Rounded
+powx2010 power 2 '2.0000000000000001' -> 4.000000000000000 Inexact Rounded
+-- 1 234567890123456
+
+powx2011 power 1 1234 -> 1
+precision: 4
+powx2012 power 1 1234 -> 1
+precision: 3
+powx2013 power 1 1234 -> 1
+powx2014 power 1 12.34e+2 -> 1
+powx2015 power 1 12.3 -> 1.00 Inexact Rounded
+powx2016 power 1 12.0 -> 1
+powx2017 power 1 1.01 -> 1.00 Inexact Rounded
+powx2018 power 2 1.00 -> 2
+powx2019 power 2 2.00 -> 4
+precision: 9
+powx2030 power 1 1.0001 -> 1.00000000 Inexact Rounded
+powx2031 power 1 1.0000001 -> 1.00000000 Inexact Rounded
+powx2032 power 1 1.0000000001 -> 1.00000000 Inexact Rounded
+powx2033 power 1 1.0000000000001 -> 1.00000000 Inexact Rounded
+precision: 5
+powx2034 power 1 1.0001 -> 1.0000 Inexact Rounded
+powx2035 power 1 1.0000001 -> 1.0000 Inexact Rounded
+powx2036 power 1 1.0000000001 -> 1.0000 Inexact Rounded
+powx2037 power 1 1.0000000000001 -> 1.0000 Inexact Rounded
+powx2038 power 1 1.0000000000001 -> 1.0000 Inexact Rounded
+
+rounding: ceiling
+precision: 3
+powx2039 power 1 1.01 -> 1.00 Inexact Rounded
+powx2040 power 1 12.3 -> 1.00 Inexact Rounded
+rounding: half_even
+
+-- 1 ** any integer, including big ones, should be exact
+powx2041 power 1 1000000000 -> 1
+powx2042 power 1 9999999999 -> 1
+powx2043 power 1 12345678000 -> 1
+powx2044 power 1 1234567800 -> 1
+powx2045 power 1 1234567890 -> 1
+powx2046 power 1 11234567891 -> 1
+powx2047 power 1 12345678901 -> 1
+powx2048 power 1 1234567896 -> 1
+powx2049 power 1 -1234567896 -> 1
+powx2051 power 1 1000000000 -> 1
+powx2052 power 1 -1000000000 -> 1
+powx2053 power 1 12345678000 -> 1
+powx2054 power 1 -1234567896 -> 1
+powx2055 power 1 1000000000 -> 1
+powx2056 power 1 4300000000 -> 1
+powx2057 power 1 -1000000000 -> 1
+-- negatives ... but not out of range for decNumber
+powx2061 power -1 100000 -> 1
+powx2062 power -1 999999 -> -1
+powx2063 power -1 1278000 -> 1
+powx2064 power -1 127803 -> -1
+powx2065 power -1 127890 -> 1
+powx2066 power -1 1167891 -> -1
+powx2067 power -1 1278901 -> -1
+powx2068 power -1 127896 -> 1
+powx2069 power -1 -167897 -> -1
+powx2071 power -1 100000 -> 1
+powx2072 power -1 -100001 -> -1
+powx2073 power -1 1278000 -> 1
+powx2074 power -1 -167896 -> 1
+powx2075 power -1 100000 -> 1
+powx2076 power -1 -100009 -> -1
+
+-- The above were derived from the earlier version of power.decTest;
+-- now start new tests for power(x,y) for non-integer y
+precision: 9
+
+-- tests from specification
+powx2081 power 2 3 -> '8'
+powx2082 power -2 3 -> '-8'
+powx2083 power 2 -3 -> '0.125'
+powx2084 power 1.7 '8' -> '69.7575744' Inexact Rounded
+powx2085 power 10 0.301029996 -> 2.00000000 Inexact Rounded
+powx2086 power Infinity '-1' -> '0'
+powx2087 power Infinity '0' -> '1'
+powx2088 power Infinity '1' -> 'Infinity'
+powx2089 power -Infinity '-1' -> '-0'
+powx2090 power -Infinity '0' -> '1'
+powx2091 power -Infinity '1' -> '-Infinity'
+powx2092 power -Infinity '2' -> 'Infinity'
+powx2093 power 0 0 -> 'NaN' Invalid_operation
+
+precision: 16
+rounding: half_even
+maxExponent: 384
+minExponent: -383
+
+-- basics
+powx2100 power 1E-7 1E-7 -> 0.9999983881917339 Inexact Rounded
+powx2101 power 0.003 1E-7 -> 0.9999994190858697 Inexact Rounded
+powx2102 power 0.7 1E-7 -> 0.9999999643325062 Inexact Rounded
+powx2103 power 1.2 1E-7 -> 1.000000018232156 Inexact Rounded
+powx2104 power 71 1E-7 -> 1.000000426268079 Inexact Rounded
+powx2105 power 9E+9 1E-7 -> 1.000002292051668 Inexact Rounded
+
+powx2110 power 1E-7 0.003 -> 0.9527961640236519 Inexact Rounded
+powx2111 power 0.003 0.003 -> 0.9827235503366797 Inexact Rounded
+powx2112 power 0.7 0.003 -> 0.9989305474406207 Inexact Rounded
+powx2113 power 1.2 0.003 -> 1.000547114282834 Inexact Rounded
+powx2114 power 71 0.003 -> 1.012870156273545 Inexact Rounded
+powx2115 power 9E+9 0.003 -> 1.071180671278787 Inexact Rounded
+
+powx2120 power 1E-7 0.7 -> 0.00001258925411794167 Inexact Rounded
+powx2121 power 0.003 0.7 -> 0.01713897630281030 Inexact Rounded
+powx2122 power 0.7 0.7 -> 0.7790559126704491 Inexact Rounded
+powx2123 power 1.2 0.7 -> 1.136126977198889 Inexact Rounded
+powx2124 power 71 0.7 -> 19.76427300093870 Inexact Rounded
+powx2125 power 9E+9 0.7 -> 9289016.976853710 Inexact Rounded
+
+powx2130 power 1E-7 1.2 -> 3.981071705534973E-9 Inexact Rounded
+powx2131 power 0.003 1.2 -> 0.0009387403933595694 Inexact Rounded
+powx2132 power 0.7 1.2 -> 0.6518049405663864 Inexact Rounded
+powx2133 power 1.2 1.2 -> 1.244564747203978 Inexact Rounded
+powx2134 power 71 1.2 -> 166.5367244638552 Inexact Rounded
+powx2135 power 9E+9 1.2 -> 881233526124.8791 Inexact Rounded
+
+powx2140 power 1E-7 71 -> 0E-398 Inexact Rounded Underflow Subnormal Clamped
+powx2141 power 0.003 71 -> 7.509466514979725E-180 Inexact Rounded
+powx2142 power 0.7 71 -> 1.004525211269079E-11 Inexact Rounded
+powx2143 power 1.2 71 -> 418666.7483186515 Inexact Rounded
+powx2144 power 71 71 -> 2.750063734834616E+131 Inexact Rounded
+powx2145 power 9E+9 71 -> Infinity Inexact Rounded Overflow
+
+powx2150 power 1E-7 9E+9 -> 0E-398 Inexact Rounded Underflow Subnormal Clamped
+powx2151 power 0.003 9E+9 -> 0E-398 Inexact Rounded Underflow Subnormal Clamped
+powx2152 power 0.7 9E+9 -> 0E-398 Inexact Rounded Underflow Subnormal Clamped
+powx2153 power 1.2 9E+9 -> Infinity Inexact Rounded Overflow
+powx2154 power 71 9E+9 -> Infinity Inexact Rounded Overflow
+powx2155 power 9E+9 9E+9 -> Infinity Inexact Rounded Overflow
+
+-- number line milestones with lhs<1 and lhs>1
+
+-- Overflow boundary (Nmax)
+powx2202 power 71 207.966651583983200 -> Infinity Inexact Rounded Overflow
+powx2201 power 71 207.966651583983199 -> 9.999999999999994E+384 Inexact Rounded
+powx2204 power 0.003 -152.603449817093577 -> Infinity Inexact Rounded Overflow
+powx2203 power 0.003 -152.603449817093576 -> 9.999999999999994E+384 Inexact Rounded
+
+-- Nmin boundary
+powx2211 power 71 -206.886305341988480 -> 1.000000000000005E-383 Inexact Rounded
+powx2212 power 71 -206.886305341988481 -> 1.000000000000001E-383 Inexact Rounded
+powx2213 power 71 -206.886305341988482 -> 9.99999999999997E-384 Inexact Rounded Underflow Subnormal
+powx2214 power 71 -206.886305341988483 -> 9.99999999999992E-384 Inexact Rounded Underflow Subnormal
+-- 9.999999999999924565357019820
+
+powx2215 power 0.003 151.810704623238543 -> 1.000000000000009E-383 Inexact Rounded
+powx2216 power 0.003 151.810704623238544 -> 1.000000000000003E-383 Inexact Rounded
+powx2217 power 0.003 151.810704623238545 -> 9.99999999999997E-384 Inexact Rounded Underflow Subnormal
+powx2218 power 0.003 151.810704623238546 -> 9.99999999999991E-384 Inexact Rounded Underflow Subnormal
+
+-- Ntiny boundary, these edge cases determined using half_up rounding
+rounding: half_up
+powx2221 power 71 -215.151510469220498 -> 1E-398 Inexact Rounded Underflow Subnormal
+powx2222 power 71 -215.151510469220499 -> 1E-398 Inexact Rounded Underflow Subnormal
+powx2223 power 71 -215.151510469220500 -> 0E-398 Inexact Rounded Underflow Subnormal Clamped
+powx2224 power 71 -215.151510469220501 -> 0E-398 Inexact Rounded Underflow Subnormal Clamped
+
+powx2225 power 0.003 157.875613618285691 -> 1E-398 Inexact Rounded Underflow Subnormal
+powx2226 power 0.003 157.875613618285692 -> 1E-398 Inexact Rounded Underflow Subnormal
+powx2227 power 0.003 157.875613618285693 -> 0E-398 Inexact Rounded Underflow Subnormal Clamped
+powx2228 power 0.003 220 -> 0E-398 Inexact Rounded Underflow Subnormal Clamped
+rounding: half_even
+
+-- power(10, y) are important ...
+
+-- Integer powers are exact, unless over/underflow
+powx2301 power 10 385 -> Infinity Overflow Inexact Rounded
+powx2302 power 10 384 -> 1.000000000000000E+384 Rounded
+powx2303 power 10 17 -> 1.000000000000000E+17 Rounded
+powx2304 power 10 16 -> 1.000000000000000E+16 Rounded
+powx2305 power 10 15 -> 1000000000000000
+powx2306 power 10 10 -> 10000000000
+powx2307 power 10 5 -> 100000
+powx2308 power 10 1 -> 10
+powx2309 power 10 0 -> 1
+powx2310 power 10 -1 -> 0.1
+powx2311 power 10 -5 -> 0.00001
+powx2312 power 10 -6 -> 0.000001
+powx2313 power 10 -7 -> 1E-7
+powx2314 power 10 -8 -> 1E-8
+powx2315 power 10 -9 -> 1E-9
+powx2316 power 10 -10 -> 1E-10
+powx2317 power 10 -383 -> 1E-383
+powx2318 power 10 -384 -> 1E-384 Subnormal
+powx2319 power 10 -385 -> 1E-385 Subnormal
+powx2320 power 10 -397 -> 1E-397 Subnormal
+powx2321 power 10 -398 -> 1E-398 Subnormal
+powx2322 power 10 -399 -> 0E-398 Subnormal Underflow Inexact Rounded Clamped
+powx2323 power 10 -400 -> 0E-398 Subnormal Underflow Inexact Rounded Clamped
+
+-- Independent sanity check: 1961 Godfrey & Siddons four-figure logs
+powx2351 power 10 0.0000 -> 1
+powx2352 power 10 0.3010 -> 1.999861869632744 Inexact Rounded
+powx2353 power 10 0.4771 -> 2.999853181190793 Inexact Rounded
+powx2354 power 10 0.6021 -> 4.000368510461250 Inexact Rounded
+powx2355 power 10 0.6990 -> 5.000345349769785 Inexact Rounded
+powx2356 power 10 0.7782 -> 6.000673538641164 Inexact Rounded
+powx2357 power 10 0.8451 -> 7.000031591308969 Inexact Rounded
+powx2358 power 10 0.9031 -> 8.000184448550990 Inexact Rounded
+powx2359 power 10 0.9542 -> 8.999119108700520 Inexact Rounded
+powx2360 power 10 0.9956 -> 9.899197750805841 Inexact Rounded
+powx2361 power 10 0.9996 -> 9.990793899844618 Inexact Rounded
+precision: 4
+powx2371 power 10 0.0000 -> 1
+powx2372 power 10 0.3010 -> 2.000 Inexact Rounded
+powx2373 power 10 0.4771 -> 3.000 Inexact Rounded
+powx2374 power 10 0.6021 -> 4.000 Inexact Rounded
+powx2375 power 10 0.6990 -> 5.000 Inexact Rounded
+powx2376 power 10 0.7782 -> 6.001 Inexact Rounded
+powx2377 power 10 0.8451 -> 7.000 Inexact Rounded
+powx2378 power 10 0.9031 -> 8.000 Inexact Rounded
+powx2379 power 10 0.9542 -> 8.999 Inexact Rounded
+powx2380 power 10 0.9956 -> 9.899 Inexact Rounded
+powx2381 power 10 0.9996 -> 9.991 Inexact Rounded
+
+-- 10**x ~=2 (inverse of the test in log10.decTest)
+precision: 50
+powx2401 power 10 0.30102999566398119521373889472449302676818988146211 -> 2.0000000000000000000000000000000000000000000000000 Inexact Rounded
+precision: 49
+powx2402 power 10 0.3010299956639811952137388947244930267681898814621 -> 2.000000000000000000000000000000000000000000000000 Inexact Rounded
+precision: 48
+powx2403 power 10 0.301029995663981195213738894724493026768189881462 -> 2.00000000000000000000000000000000000000000000000 Inexact Rounded
+precision: 47
+powx2404 power 10 0.30102999566398119521373889472449302676818988146 -> 2.0000000000000000000000000000000000000000000000 Inexact Rounded
+precision: 46
+powx2405 power 10 0.3010299956639811952137388947244930267681898815 -> 2.000000000000000000000000000000000000000000000 Inexact Rounded
+precision: 45
+powx2406 power 10 0.301029995663981195213738894724493026768189881 -> 2.00000000000000000000000000000000000000000000 Inexact Rounded
+precision: 44
+powx2407 power 10 0.30102999566398119521373889472449302676818988 -> 2.0000000000000000000000000000000000000000000 Inexact Rounded
+precision: 43
+powx2408 power 10 0.3010299956639811952137388947244930267681899 -> 2.000000000000000000000000000000000000000000 Inexact Rounded
+precision: 42
+powx2409 power 10 0.301029995663981195213738894724493026768190 -> 2.00000000000000000000000000000000000000000 Inexact Rounded
+precision: 41
+powx2410 power 10 0.30102999566398119521373889472449302676819 -> 2.0000000000000000000000000000000000000000 Inexact Rounded
+precision: 40
+powx2411 power 10 0.3010299956639811952137388947244930267682 -> 2.000000000000000000000000000000000000000 Inexact Rounded
+precision: 39
+powx2412 power 10 0.301029995663981195213738894724493026768 -> 2.00000000000000000000000000000000000000 Inexact Rounded
+precision: 38
+powx2413 power 10 0.30102999566398119521373889472449302677 -> 2.0000000000000000000000000000000000000 Inexact Rounded
+precision: 37
+powx2414 power 10 0.3010299956639811952137388947244930268 -> 2.000000000000000000000000000000000000 Inexact Rounded
+precision: 36
+powx2415 power 10 0.301029995663981195213738894724493027 -> 2.00000000000000000000000000000000000 Inexact Rounded
+precision: 35
+powx2416 power 10 0.30102999566398119521373889472449303 -> 2.0000000000000000000000000000000000 Inexact Rounded
+precision: 34
+powx2417 power 10 0.3010299956639811952137388947244930 -> 2.000000000000000000000000000000000 Inexact Rounded
+precision: 33
+powx2418 power 10 0.301029995663981195213738894724493 -> 2.00000000000000000000000000000000 Inexact Rounded
+precision: 32
+powx2419 power 10 0.30102999566398119521373889472449 -> 2.0000000000000000000000000000000 Inexact Rounded
+precision: 31
+powx2420 power 10 0.3010299956639811952137388947245 -> 2.000000000000000000000000000000 Inexact Rounded
+precision: 30
+powx2421 power 10 0.301029995663981195213738894725 -> 2.00000000000000000000000000000 Inexact Rounded
+precision: 29
+powx2422 power 10 0.30102999566398119521373889472 -> 2.0000000000000000000000000000 Inexact Rounded
+precision: 28
+powx2423 power 10 0.3010299956639811952137388947 -> 2.000000000000000000000000000 Inexact Rounded
+precision: 27
+powx2424 power 10 0.301029995663981195213738895 -> 2.00000000000000000000000000 Inexact Rounded
+precision: 26
+powx2425 power 10 0.30102999566398119521373889 -> 2.0000000000000000000000000 Inexact Rounded
+precision: 25
+powx2426 power 10 0.3010299956639811952137389 -> 2.000000000000000000000000 Inexact Rounded
+precision: 24
+powx2427 power 10 0.301029995663981195213739 -> 2.00000000000000000000000 Inexact Rounded
+precision: 23
+powx2428 power 10 0.30102999566398119521374 -> 2.0000000000000000000000 Inexact Rounded
+precision: 22
+powx2429 power 10 0.3010299956639811952137 -> 2.000000000000000000000 Inexact Rounded
+precision: 21
+powx2430 power 10 0.301029995663981195214 -> 2.00000000000000000000 Inexact Rounded
+precision: 20
+powx2431 power 10 0.30102999566398119521 -> 2.0000000000000000000 Inexact Rounded
+precision: 19
+powx2432 power 10 0.3010299956639811952 -> 2.000000000000000000 Inexact Rounded
+precision: 18
+powx2433 power 10 0.301029995663981195 -> 2.00000000000000000 Inexact Rounded
+precision: 17
+powx2434 power 10 0.30102999566398120 -> 2.0000000000000000 Inexact Rounded
+precision: 16
+powx2435 power 10 0.3010299956639812 -> 2.000000000000000 Inexact Rounded
+precision: 15
+powx2436 power 10 0.301029995663981 -> 2.00000000000000 Inexact Rounded
+precision: 14
+powx2437 power 10 0.30102999566398 -> 2.0000000000000 Inexact Rounded
+precision: 13
+powx2438 power 10 0.3010299956640 -> 2.000000000000 Inexact Rounded
+precision: 12
+powx2439 power 10 0.301029995664 -> 2.00000000000 Inexact Rounded
+precision: 11
+powx2440 power 10 0.30102999566 -> 2.0000000000 Inexact Rounded
+precision: 10
+powx2441 power 10 0.3010299957 -> 2.000000000 Inexact Rounded
+precision: 9
+powx2442 power 10 0.301029996 -> 2.00000000 Inexact Rounded
+precision: 8
+powx2443 power 10 0.30103000 -> 2.0000000 Inexact Rounded
+precision: 7
+powx2444 power 10 0.3010300 -> 2.000000 Inexact Rounded
+precision: 6
+powx2445 power 10 0.301030 -> 2.00000 Inexact Rounded
+precision: 5
+powx2446 power 10 0.30103 -> 2.0000 Inexact Rounded
+precision: 4
+powx2447 power 10 0.3010 -> 2.000 Inexact Rounded
+precision: 3
+powx2448 power 10 0.301 -> 2.00 Inexact Rounded
+precision: 2
+powx2449 power 10 0.30 -> 2.0 Inexact Rounded
+precision: 1
+powx2450 power 10 0.3 -> 2 Inexact Rounded
+
+maxExponent: 384
+minExponent: -383
+precision: 16
+rounding: half_even
+
+-- Close-to-e tests
+precision: 34
+powx2500 power 10 0.4342944819032518276511289189166048 -> 2.718281828459045235360287471352661 Inexact Rounded
+powx2501 power 10 0.4342944819032518276511289189166049 -> 2.718281828459045235360287471352661 Inexact Rounded
+powx2502 power 10 0.4342944819032518276511289189166050 -> 2.718281828459045235360287471352662 Inexact Rounded
+powx2503 power 10 0.4342944819032518276511289189166051 -> 2.718281828459045235360287471352663 Inexact Rounded
+powx2504 power 10 0.4342944819032518276511289189166052 -> 2.718281828459045235360287471352663 Inexact Rounded
+
+-- e**e, 16->34
+powx2505 power 2.718281828459045 2.718281828459045 -> '15.15426224147925705633739513098219' Inexact Rounded
+
+-- Sequence around an integer
+powx2512 power 10 2.9999999999999999999999999999999997 -> 999.9999999999999999999999999999993 Inexact Rounded
+powx2513 power 10 2.9999999999999999999999999999999998 -> 999.9999999999999999999999999999995 Inexact Rounded
+powx2514 power 10 2.9999999999999999999999999999999999 -> 999.9999999999999999999999999999998 Inexact Rounded
+powx2515 power 10 3.0000000000000000000000000000000000 -> 1000
+powx2516 power 10 3.0000000000000000000000000000000001 -> 1000.000000000000000000000000000000 Inexact Rounded
+powx2517 power 10 3.0000000000000000000000000000000002 -> 1000.000000000000000000000000000000 Inexact Rounded
+powx2518 power 10 3.0000000000000000000000000000000003 -> 1000.000000000000000000000000000001 Inexact Rounded
+
+-- randomly generated tests
+maxExponent: 384
+minExponent: -383
+
+-- P=34, within 0-999 -- positive arg2
+Precision: 34
+powx3201 power 5.301557744131969249145904611290735 369.3175647984435534243813466380579 -> 3.427165676345688240023113326603960E+267 Inexact Rounded
+powx3202 power 0.0000000000506875655819165973738225 21.93514102704466434121826965196878 -> 1.498169860033487321566659495340789E-226 Inexact Rounded
+powx3203 power 97.88877680721519917858007810494043 5.159898445242793470476673109899554 -> 18705942904.43290467281449559427982 Inexact Rounded
+powx3204 power 7.380441015594399747973924380493799 17.93614173904818313507525109033288 -> 3715757985820076.273336082702577274 Inexact Rounded
+powx3205 power 2.045623627647350918819219169855040 1082.999652407430697958175966996254 -> 4.208806435006704867447150904279854E+336 Inexact Rounded
+powx3206 power 0.0000000762582873112118926142955423 20.30534237055073996975203864170432 -> 2.967574278677013090697130349198877E-145 Inexact Rounded
+powx3207 power 0.0000000000194091470907814855660535 14.71164213947722238856835440242911 -> 2.564391397469554735037158345963280E-158 Inexact Rounded
+powx3208 power 0.0000000000509434185382818596853504 20.97051498204188277347203735421595 -> 1.420157372748083000927138678417272E-216 Inexact Rounded
+powx3209 power 0.0005389217212073307301395750745119 43.96798225485747315858678755538971 -> 1.957850185781292007977898626137240E-144 Inexact Rounded
+powx3210 power 498.5690105989136050444077447411198 128.1038813807243375878831104745803 -> 3.882212970903893127009102293596268E+345 Inexact Rounded
+powx3211 power 0.0000000935428918637303954281938975 5.736933454863278597460091596496099 -> 4.733219644540496152403967823635195E-41 Inexact Rounded
+powx3212 power 8.581586784734161309180363110126352 252.0229459968869784643374981477208 -> 1.907464842458674622356177850049873E+235 Inexact Rounded
+powx3213 power 294.1005302951621709143320795278305 155.5466374141708615975111014663722 -> 9.251717033292072959166737280729728E+383 Inexact Rounded
+powx3214 power 0.0000000041253343654396865855722090 19.00170974760425576247662125110472 -> 4.779566288553864405790921353593512E-160 Inexact Rounded
+powx3215 power 0.0000000000046912257352141395184092 24.66089523148729269098773236636878 -> 4.205126874048597849476723538057527E-280 Inexact Rounded
+powx3216 power 0.0000000000036796674296520639450494 22.09713956900694689234335912523078 -> 2.173081843837539818472071316420405E-253 Inexact Rounded
+powx3217 power 9.659887100303037657934372148567685 277.3765665424320875993026404492216 -> 1.614974043145519382749740616665041E+273 Inexact Rounded
+powx3218 power 0.0000083231310642229204398943076403 29.33123211782131466471359128190372 -> 1.013330439786660210757226597785328E-149 Inexact Rounded
+powx3219 power 0.0938084859086450954956863725653664 262.6091918199905272837286784975012 -> 1.262802485286301066967555821509344E-270 Inexact Rounded
+powx3220 power 8.194926977580900145696305910223304 184.3705133945546202012995485297248 -> 2.696353910907824016690021495828584E+168 Inexact Rounded
+powx3221 power 72.39594594653085161522285114566120 168.7721909489321402152033939836725 -> 7.379858293630460043361584410795031E+313 Inexact Rounded
+powx3222 power 0.0000000000003436856010144185445537 26.34329868961274988994452526178983 -> 4.585379573595865689605567720192768E-329 Inexact Rounded
+powx3223 power 20.18365633762226550254542489492623 127.2099705237021350103678072707790 -> 1.020919629336979353690271762206060E+166 Inexact Rounded
+powx3224 power 0.0000000553723990761530290129268131 8.157597566134754638015199501162405 -> 6.349030513396147480954474615067145E-60 Inexact Rounded
+powx3225 power 0.0001028742674265840656614682618035 93.99842317306603797965470281716482 -> 1.455871110222736531854990397769940E-375 Inexact Rounded
+powx3226 power 95.90195152775543876489746343266050 143.5992850002211509777720799352475 -> 3.881540015848530405189834366588567E+284 Inexact Rounded
+powx3227 power 0.0000000000041783747057233878360333 12.14591167764993506821334760954430 -> 6.190998557456885985124592807383163E-139 Inexact Rounded
+powx3228 power 0.5572830497086740798434917090018768 1001.921811263919522230330241349166 -> 3.871145158537170450093833881625838E-255 Inexact Rounded
+powx3229 power 516.4754759779093954790813881333232 29.23812463126309057800793645336343 -> 2.110986192408878294012450052929185E+79 Inexact Rounded
+powx3230 power 0.0000835892099464584776847299020706 27.64279992884843877453592659341588 -> 1.891535098905506689512376224943293E-113 Inexact Rounded
+powx3231 power 72.45836577748571838139900165184955 166.2562890735032545091688015160084 -> 1.784091549041561516923092542939141E+309 Inexact Rounded
+powx3232 power 305.1823317643335924007629563009032 83.01065159508472884219290136319623 -> 1.757493136164395229602456782779110E+206 Inexact Rounded
+powx3233 power 7.108527102951713603542835791733786 145.7057852766236365450463428821948 -> 1.285934774113104362663619896550528E+124 Inexact Rounded
+powx3234 power 6.471393503175464828149365697049824 64.11741937262455725284754171995720 -> 9.978990355881803195280027533011699E+51 Inexact Rounded
+powx3235 power 39.72898094138459885662380866268385 239.9677288017447400786672779735168 -> 5.422218208517098335832848487375086E+383 Inexact Rounded
+powx3236 power 0.0002865592332736973000183287329933 90.34733869590583787065642532641096 -> 8.293733126976212033209243257136796E-321 Inexact Rounded
+powx3237 power 0.0000011343384394864811195077357936 1.926568285528399656789140809399396 -> 3.516055639378350146874261077470142E-12 Inexact Rounded
+powx3238 power 0.0000000035321610295065299384889224 7.583861778824284092434085265265582 -> 7.970899823817369764381976286536230E-65 Inexact Rounded
+powx3239 power 657.5028301569352677543770758346683 90.55778453811965116200206020172758 -> 1.522530898581564200655160665723268E+255 Inexact Rounded
+powx3240 power 8.484756398325748879450577520251447 389.7468292476262478578280531222417 -> 8.595142803587368093392510310811218E+361 Inexact Rounded
+
+-- P=16, within 0-99 -- positive arg2
+Precision: 16
+powx3101 power 0.0000215524639223 48.37532522355252 -> 1.804663257287277E-226 Inexact Rounded
+powx3102 power 00.80705856227999 2706.777535121391 -> 1.029625065876157E-252 Inexact Rounded
+powx3103 power 3.445441676383689 428.5185892455830 -> 1.657401683096454E+230 Inexact Rounded
+powx3104 power 0.0040158689495826 159.5725558816240 -> 4.255743665762492E-383 Inexact Rounded
+powx3105 power 0.0000841553281215 38.32504413453944 -> 6.738653902512052E-157 Inexact Rounded
+powx3106 power 0.7322610252571353 502.1254457674118 -> 1.109978126985943E-68 Inexact Rounded
+powx3107 power 10.75052532144880 67.34180604734781 -> 2.873015019470189E+69 Inexact Rounded
+powx3108 power 26.20425952945617 104.6002671186488 -> 2.301859355777030E+148 Inexact Rounded
+powx3109 power 0.0000055737473850 31.16285859005424 -> 1.883348470100446E-164 Inexact Rounded
+powx3110 power 61.06096011360700 10.93608439088726 -> 3.382686473028249E+19 Inexact Rounded
+powx3111 power 9.340880853257137 179.9094938131726 -> 3.819299795937696E+174 Inexact Rounded
+powx3112 power 0.0000050767371756 72.03346394186741 -> 4.216236691569869E-382 Inexact Rounded
+powx3113 power 6.838478807860596 47.49665590602285 -> 4.547621630099203E+39 Inexact Rounded
+powx3114 power 0.1299324346439081 397.7440523576938 -> 3.065047705553981E-353 Inexact Rounded
+powx3115 power 0.0003418047034264 20.00516791512018 -> 4.546189665380487E-70 Inexact Rounded
+powx3116 power 0.0001276899611715 78.12968287355703 -> 5.960217405063995E-305 Inexact Rounded
+powx3117 power 25.93160588180509 252.6245071004620 -> 1.472171597589146E+357 Inexact Rounded
+powx3118 power 35.47516857763178 86.14723037360925 -> 3.324299908481125E+133 Inexact Rounded
+powx3119 power 0.0000048171086721 43.31965603038666 -> 4.572331516616228E-231 Inexact Rounded
+powx3120 power 17.97652681097851 144.4684576550292 -> 1.842509906097860E+181 Inexact Rounded
+powx3121 power 3.622765141518729 305.1948680344950 -> 4.132320967578704E+170 Inexact Rounded
+powx3122 power 0.0080959002453519 143.9899444945627 -> 6.474627812947047E-302 Inexact Rounded
+powx3123 power 9.841699927276571 299.2466668837188 -> 1.489097656208736E+297 Inexact Rounded
+powx3124 power 0.0786659206232355 347.4750796962570 -> 2.05764809646925E-384 Inexact Rounded Underflow Subnormal
+powx3125 power 0.0000084459792645 52.47348690745487 -> 6.076251876516942E-267 Inexact Rounded
+powx3126 power 27.86589909967504 191.7296537102283 -> 1.157064112989386E+277 Inexact Rounded
+powx3127 power 0.0000419907937234 58.44957702730767 -> 1.496950672075162E-256 Inexact Rounded
+powx3128 power 0.0000664977739382 80.06749213261876 -> 3.488517620107875E-335 Inexact Rounded
+powx3129 power 58.49554484886656 125.8480768373499 -> 2.449089862146640E+222 Inexact Rounded
+powx3130 power 15.02820060024449 212.3527988973338 -> 8.307913932682067E+249 Inexact Rounded
+powx3131 power 0.0002650089942992 30.92173123678761 -> 2.517827664836147E-111 Inexact Rounded
+powx3132 power 0.0007342977426578 69.49168880741123 -> 1.600168665674440E-218 Inexact Rounded
+powx3133 power 0.0063816068650629 150.1400094183812 -> 2.705057295799001E-330 Inexact Rounded
+powx3134 power 9.912921122728791 297.8274013633411 -> 4.967624993438900E+296 Inexact Rounded
+powx3135 power 1.988603563989245 768.4862967922182 -> 2.692842474899596E+229 Inexact Rounded
+powx3136 power 8.418014519517691 164.2431359980725 -> 9.106211585888836E+151 Inexact Rounded
+powx3137 power 6.068823604450686 120.2955212365837 -> 1.599431918105982E+94 Inexact Rounded
+powx3138 power 56.90062738303850 54.90468294683645 -> 2.312839177902428E+96 Inexact Rounded
+powx3139 power 5.710905139750871 73.44608752962156 -> 3.775876053709929E+55 Inexact Rounded
+powx3140 power 0.0000017446761203 1.223981492228899 -> 8.952936595465635E-8 Inexact Rounded
+
+-- P=7, within 0-9 -- positive arg2
+Precision: 7
+powx3001 power 8.738689 55.96523 -> 4.878180E+52 Inexact Rounded
+powx3002 power 0.0404763 147.4965 -> 3.689722E-206 Inexact Rounded
+powx3003 power 0.0604232 76.69778 -> 3.319183E-94 Inexact Rounded
+powx3004 power 0.0058855 107.5018 -> 1.768875E-240 Inexact Rounded
+powx3005 power 2.058302 1173.050 -> 5.778899E+367 Inexact Rounded
+powx3006 power 0.0056998 85.70157 -> 4.716783E-193 Inexact Rounded
+powx3007 power 0.8169297 3693.537 -> 4.475962E-325 Inexact Rounded
+powx3008 power 0.2810153 659.9568 -> 1.533177E-364 Inexact Rounded
+powx3009 power 4.617478 15.68308 -> 2.629748E+10 Inexact Rounded
+powx3010 power 0.0296418 244.2302 -> 6.207949E-374 Inexact Rounded
+powx3011 power 0.0036456 127.9987 -> 8.120891E-313 Inexact Rounded
+powx3012 power 0.5012813 577.5418 -> 6.088802E-174 Inexact Rounded
+powx3013 power 0.0033275 119.9800 -> 5.055049E-298 Inexact Rounded
+powx3014 power 0.0037652 111.7092 -> 1.560351E-271 Inexact Rounded
+powx3015 power 0.6463252 239.0568 -> 4.864564E-46 Inexact Rounded
+powx3016 power 4.784378 475.0521 -> 8.964460E+322 Inexact Rounded
+powx3017 power 4.610305 563.1791 -> 6.290298E+373 Inexact Rounded
+powx3018 power 0.0175167 80.52208 -> 3.623472E-142 Inexact Rounded
+powx3019 power 5.238307 356.7944 -> 4.011461E+256 Inexact Rounded
+powx3020 power 0.0003527 96.26347 -> 4.377932E-333 Inexact Rounded
+powx3021 power 0.0015155 136.0516 -> 2.57113E-384 Inexact Rounded Underflow Subnormal
+powx3022 power 5.753573 273.2340 -> 4.373184E+207 Inexact Rounded
+powx3023 power 7.778665 332.7917 -> 3.060640E+296 Inexact Rounded
+powx3024 power 1.432479 2046.064 -> 2.325829E+319 Inexact Rounded
+powx3025 power 5.610516 136.4563 -> 1.607502E+102 Inexact Rounded
+powx3026 power 0.0050697 137.4513 -> 3.522315E-316 Inexact Rounded
+powx3027 power 5.678737 85.16253 -> 1.713909E+64 Inexact Rounded
+powx3028 power 0.0816167 236.1973 -> 9.228802E-258 Inexact Rounded
+powx3029 power 0.2602805 562.0157 -> 2.944556E-329 Inexact Rounded
+powx3030 power 0.0080936 24.25367 -> 1.839755E-51 Inexact Rounded
+powx3031 power 4.092016 82.94603 -> 5.724948E+50 Inexact Rounded
+powx3032 power 0.0078255 7.204184 -> 6.675342E-16 Inexact Rounded
+powx3033 power 0.9917693 29846.44 -> 7.430177E-108 Inexact Rounded
+powx3034 power 1.610380 301.2467 -> 2.170142E+62 Inexact Rounded
+powx3035 power 0.0588236 212.1097 -> 1.023196E-261 Inexact Rounded
+powx3036 power 2.498069 531.4647 -> 2.054561E+211 Inexact Rounded
+powx3037 power 9.964342 326.5438 -> 1.089452E+326 Inexact Rounded
+powx3038 power 0.0820626 268.8718 -> 1.107350E-292 Inexact Rounded
+powx3039 power 6.176486 360.7779 -> 1.914449E+285 Inexact Rounded
+powx3040 power 4.206363 16.17288 -> 1.231314E+10 Inexact Rounded
+
+-- P=34, within 0-999 -- negative arg2
+Precision: 34
+powx3701 power 376.0915270000109486633402827007902 -35.69822349904102131649243701958463 -> 1.165722831225506457828653413200143E-92 Inexact Rounded
+powx3702 power 0.0000000503747440074613191665845314 -9.520308341497979093021813571450575 -> 3.000432478861883953977971226770410E+69 Inexact Rounded
+powx3703 power 290.6858731495339778337953407938308 -118.5459048597789693292455673428367 -> 9.357969047113989238392527565200302E-293 Inexact Rounded
+powx3704 power 4.598864607620052062908700928454182 -299.8323667698931125720218537483753 -> 2.069641269855413539579128114448478E-199 Inexact Rounded
+powx3705 power 2.556952676986830645708349254938903 -425.1755373251941383147998924703593 -> 4.428799777833598654260883861514638E-174 Inexact Rounded
+powx3706 power 0.0000005656198763404221986640610118 -32.83361380678301321230028730075315 -> 1.340270622401829145968477601029251E+205 Inexact Rounded
+powx3707 power 012.4841978642452960750801410372125 -214.3734291828712962809866663321921 -> 9.319857751170603140459057535971202E-236 Inexact Rounded
+powx3708 power 0.0000000056041586148066919174315551 -37.21129049213858341528033343116533 -> 1.118345010652454313186702341873169E+307 Inexact Rounded
+powx3709 power 0.0694569218941833767199998804202152 -8.697509072368973932501239815677732 -> 11862866995.51026489032838174290271 Inexact Rounded
+powx3710 power 6.380984024259450398729243522354144 -451.0635696889193561457985486366827 -> 8.800353109387322474809325670314330E-364 Inexact Rounded
+powx3711 power 786.0264840756809048288007204917801 -43.09935384678762773057342161718540 -> 1.616324183365644133979585419925934E-125 Inexact Rounded
+powx3712 power 96.07836427113204744101287948445130 -185.1414572546330024388914720271876 -> 8.586320815218383004023264980018610E-368 Inexact Rounded
+powx3713 power 0.0000000002332189796855870659792406 -5.779561613164628076880609893753327 -> 4.678450775876385793618570483345066E+55 Inexact Rounded
+powx3714 power 0.7254146672024602242369943237968857 -2115.512891397828615710130092245691 -> 8.539080958041689288202111403102495E+294 Inexact Rounded
+powx3715 power 0.0017380543649702864796144008592137 -6.307668017761022788220578633538713 -> 256309141459075651.2275798017695017 Inexact Rounded
+powx3716 power 05.29498758952276908267649116142379 -287.3233896734103442991981056134167 -> 1.039130027847489364009368608104291E-208 Inexact Rounded
+powx3717 power 15.64403593865932622003462779104178 -110.5296633358063267478609032002475 -> 9.750540276026524527375125980296142E-133 Inexact Rounded
+powx3718 power 89.69639006761571087634945077373508 -181.3209914139357665609268339422627 -> 8.335034232277762924539395632025281E-355 Inexact Rounded
+powx3719 power 6.974087483731006359914914110135058 -174.6815625746710345173615508179842 -> 4.553072265122011176641590109568031E-148 Inexact Rounded
+powx3720 power 0.0034393024010554821130553772681993 -93.60931598413919272595497100497364 -> 4.067468855817145539589988349449394E+230 Inexact Rounded
+powx3721 power 63.32834072300379155053737260965633 -168.3926799435088324825751446957616 -> 4.207907835462640471617519501741094E-304 Inexact Rounded
+powx3722 power 00.00216088174206276369011255907785 -70.12279562855442784757874508991013 -> 8.000657143378187029609343435067057E+186 Inexact Rounded
+powx3723 power 934.5957982703545893572134393004375 -102.2287735565878252484031426026726 -> 2.073813769209257617246544424827240E-304 Inexact Rounded
+powx3724 power 107.9116792558793921873995885441177 -44.11941092260869786313838181499158 -> 2.005476533631183268912552168759595E-90 Inexact Rounded
+powx3725 power 0.0000000000188049827381428191769262 -19.32118917192242027966847501724073 -> 1.713174297100918857053338286389034E+207 Inexact Rounded
+powx3726 power 614.9820907366248142166636259027728 -4.069913257030791586645250035698123 -> 4.462432572576935752713876293746717E-12 Inexact Rounded
+powx3727 power 752.0655175769182096165651274049422 -22.59292060348797472013598378334370 -> 1.039881526694635205040192531504131E-65 Inexact Rounded
+powx3728 power 72.20446632047659449616175456059013 -175.4705356401853924020842356605072 -> 7.529540175791582421966947814549028E-327 Inexact Rounded
+powx3729 power 518.8346486600403405764055847937416 -65.87320268592761588756963215588232 -> 1.420189426992170936958891180073151E-179 Inexact Rounded
+powx3730 power 3.457164372003960576453458502270716 -440.3201118177861273814529713443698 -> 6.176418595751201287186292664257369E-238 Inexact Rounded
+powx3731 power 7.908352793344189720739467675503991 -298.6646112894719680394152664740255 -> 5.935857120229147638104675057695125E-269 Inexact Rounded
+powx3732 power 0.0000004297399403788595027926075086 -22.66504617185071293588817501468339 -> 2.012270405520600820469665145636204E+144 Inexact Rounded
+powx3733 power 0.0000008592124097322966354868716443 -9.913109586558030204789520190180906 -> 1.354958763843310237046818832755215E+60 Inexact Rounded
+powx3734 power 161.4806080561258105880907470989925 -70.72907837434814261716311990271578 -> 6.632555003698945544941329872901929E-157 Inexact Rounded
+powx3735 power 0.0000000090669568624173832705631918 -36.53759624613665940127058439106640 -> 7.161808401023414735428130112941559E+293 Inexact Rounded
+powx3736 power 0.0000000000029440295978365709342752 -1.297354238738921988884421117731562 -> 911731060579291.7661267358872917380 Inexact Rounded
+powx3737 power 21.37477220144832172175460425143692 -76.95949933640539226475686997477889 -> 4.481741242418091914011962399912885E-103 Inexact Rounded
+powx3738 power 0.0000000000186657798201636342150903 -20.18296240350678245567049161730909 -> 3.483954007114900406906338526575672E+216 Inexact Rounded
+powx3739 power 0.0006522464792960191985996959126792 -80.03762491483514679886504099194414 -> 9.266548513614215557228467517053035E+254 Inexact Rounded
+powx3740 power 0.0000000032851343694200568966168055 -21.53462116926375512242403160008026 -> 4.873201679668455240861376213601189E+182 Inexact Rounded
+
+-- P=16, within 0-99 -- negative arg2
+Precision: 16
+powx3601 power 0.0000151338748474 -40.84655618364688 -> 7.628470824137755E+196 Inexact Rounded
+powx3602 power 0.1542771848654862 -435.8830009466800 -> 6.389817177800744E+353 Inexact Rounded
+powx3603 power 48.28477749367364 -218.5929209902050 -> 8.531049532576154E-369 Inexact Rounded
+powx3604 power 7.960775891584911 -12.78113732182505 -> 3.053270889769488E-12 Inexact Rounded
+powx3605 power 0.9430340651863058 -9010.470056913748 -> 3.313374654923807E+229 Inexact Rounded
+powx3606 power 0.0000202661501602 -65.57915207383306 -> 5.997379176536464E+307 Inexact Rounded
+powx3607 power 04.33007440798390 -232.0476834666588 -> 2.007827183010456E-148 Inexact Rounded
+powx3608 power 0.0000141944643914 -11.32407921958717 -> 7.902934485074846E+54 Inexact Rounded
+powx3609 power 0.0000021977758261 -53.53706138253307 -> 8.195631772317815E+302 Inexact Rounded
+powx3610 power 39.51297655474188 -19.40370976012326 -> 1.040699608072659E-31 Inexact Rounded
+powx3611 power 38.71210232488775 -66.58341618227921 -> 1.886855066146495E-106 Inexact Rounded
+powx3612 power 0.0000804235229062 -6.715207948992859 -> 3.134757864389333E+27 Inexact Rounded
+powx3613 power 0.0000073547092399 -11.27725685719934 -> 7.781428390953695E+57 Inexact Rounded
+powx3614 power 52.72181272599316 -186.1422311607435 -> 2.916601998744177E-321 Inexact Rounded
+powx3615 power 0.0969519963083306 -280.8220862151369 -> 3.955906885970987E+284 Inexact Rounded
+powx3616 power 94.07263302150081 -148.2031146071230 -> 3.361958990752490E-293 Inexact Rounded
+powx3617 power 85.80286965053704 -90.21453695813759 -> 3.715602429645798E-175 Inexact Rounded
+powx3618 power 03.52699858152259 -492.0414362539196 -> 4.507309220081092E-270 Inexact Rounded
+powx3619 power 0.0508278086396068 -181.0871731572167 -> 2.034428013017949E+234 Inexact Rounded
+powx3620 power 0.395576740303172 -915.5524507432392 -> 5.706585187437578E+368 Inexact Rounded
+powx3621 power 38.06105826789202 -49.75913753435335 -> 2.273188991431738E-79 Inexact Rounded
+powx3622 power 0.0003656748910646 -73.28988491310354 -> 7.768936940568763E+251 Inexact Rounded
+powx3623 power 0.0000006373551809 -51.30825234200690 -> 7.697618167701985E+317 Inexact Rounded
+powx3624 power 82.41729920673856 -35.73319631625699 -> 3.424042354585529E-69 Inexact Rounded
+powx3625 power 0.7845821453127670 -971.4982028897663 -> 2.283415527661089E+102 Inexact Rounded
+powx3626 power 4.840983673433497 -182.3730452370515 -> 1.220591407927770E-125 Inexact Rounded
+powx3627 power 0.0000006137592139 -2.122139474431484 -> 15231217034839.29 Inexact Rounded
+powx3628 power 0.0003657962862984 -35.97993782448099 -> 4.512701319250839E+123 Inexact Rounded
+powx3629 power 40.93693004443150 -165.1362408792997 -> 6.044276411057239E-267 Inexact Rounded
+powx3630 power 0.2941552583028898 -17.41046264945892 -> 1787833103.503346 Inexact Rounded
+powx3631 power 63.99335135369977 -69.92417205168579 -> 5.099359804872509E-127 Inexact Rounded
+powx3632 power 0.0000657924467388 -89.14497293588313 -> 6.145878266688521E+372 Inexact Rounded
+powx3633 power 11.35071250339147 -323.3705865614542 -> 6.863626248766775E-342 Inexact Rounded
+powx3634 power 23.88024718470895 -277.7117513329510 -> 2.006441422612815E-383 Inexact Rounded
+powx3635 power 0.0000009111939914 -58.51782946929182 -> 2.954352883996773E+353 Inexact Rounded
+powx3636 power 0.0000878179048782 -75.81060420238669 -> 3.306878455207585E+307 Inexact Rounded
+powx3637 power 07.39190564273779 -287.5047307244636 -> 1.692080354659805E-250 Inexact Rounded
+powx3638 power 0.0000298310819799 -1.844740377759355 -> 222874718.7238888 Inexact Rounded
+powx3639 power 0.0000006412929384 -28.24850078229290 -> 8.737164230666529E+174 Inexact Rounded
+powx3640 power 0.0000010202965998 -47.17573701956498 -> 4.392845306049341E+282 Inexact Rounded
+
+-- P=7, within 0-9 -- negative arg2
+Precision: 7
+powx3501 power 0.326324 -71.96509 -> 1.000673E+35 Inexact Rounded
+powx3502 power 0.0017635 -0.7186967 -> 95.28419 Inexact Rounded
+powx3503 power 8.564155 -253.0899 -> 8.850512E-237 Inexact Rounded
+powx3504 power 8.987272 -2.155789 -> 0.008793859 Inexact Rounded
+powx3505 power 9.604856 -139.9630 -> 3.073492E-138 Inexact Rounded
+powx3506 power 0.8472919 -2539.085 -> 5.372686E+182 Inexact Rounded
+powx3507 power 5.312329 -60.32965 -> 1.753121E-44 Inexact Rounded
+powx3508 power 0.0338294 -100.5440 -> 7.423939E+147 Inexact Rounded
+powx3509 power 0.0017777 -130.8583 -> 7.565629E+359 Inexact Rounded
+powx3510 power 8.016154 -405.5689 -> 2.395977E-367 Inexact Rounded
+powx3511 power 5.016570 -327.8906 -> 2.203784E-230 Inexact Rounded
+powx3512 power 0.8161743 -744.5276 -> 4.786899E+65 Inexact Rounded
+powx3513 power 0.0666343 -164.7320 -> 5.951240E+193 Inexact Rounded
+powx3514 power 0.0803966 -202.2666 -> 2.715512E+221 Inexact Rounded
+powx3515 power 0.0014752 -12.55547 -> 3.518905E+35 Inexact Rounded
+powx3516 power 9.737565 -14.69615 -> 2.975672E-15 Inexact Rounded
+powx3517 power 0.6634172 -152.7308 -> 1.654458E+27 Inexact Rounded
+powx3518 power 0.0009337 -33.32939 -> 9.575039E+100 Inexact Rounded
+powx3519 power 8.679922 -224.4194 -> 2.392446E-211 Inexact Rounded
+powx3520 power 7.390494 -161.9483 -> 2.088375E-141 Inexact Rounded
+powx3521 power 0.4631489 -417.1673 -> 2.821106E+139 Inexact Rounded
+powx3522 power 0.0095471 -7.677458 -> 3.231855E+15 Inexact Rounded
+powx3523 power 6.566339 -176.1867 -> 9.965633E-145 Inexact Rounded
+powx3524 power 2.696128 -26.15501 -> 5.419731E-12 Inexact Rounded
+powx3525 power 0.4464366 -852.1893 -> 2.957725E+298 Inexact Rounded
+powx3526 power 0.4772006 -921.4111 -> 1.118105E+296 Inexact Rounded
+powx3527 power 8.923696 -359.2211 -> 3.501573E-342 Inexact Rounded
+powx3528 power 0.0018008 -66.91252 -> 4.402718E+183 Inexact Rounded
+powx3529 power 0.0811964 -92.83278 -> 1.701111E+101 Inexact Rounded
+powx3530 power 0.0711219 -58.94347 -> 4.644148E+67 Inexact Rounded
+powx3531 power 7.958121 -50.66123 -> 2.311161E-46 Inexact Rounded
+powx3532 power 6.106466 -81.83610 -> 4.943285E-65 Inexact Rounded
+powx3533 power 4.557634 -129.5268 -> 4.737917E-86 Inexact Rounded
+powx3534 power 0.0027348 -9.180135 -> 3.383524E+23 Inexact Rounded
+powx3535 power 0.0083924 -46.24016 -> 9.996212E+95 Inexact Rounded
+powx3536 power 2.138523 -47.25897 -> 2.507009E-16 Inexact Rounded
+powx3537 power 1.626728 -1573.830 -> 2.668117E-333 Inexact Rounded
+powx3538 power 0.082615 -164.5842 -> 1.717882E+178 Inexact Rounded
+powx3539 power 7.636003 -363.6763 -> 8.366174E-322 Inexact Rounded
+powx3540 power 0.0021481 -138.0065 -> 1.562505E+368 Inexact Rounded
+
+
+-- Invalid operations due to restrictions
+-- [next two probably skipped by most test harnesses]
+precision: 100000000
+powx4001 power 1 1.1 -> NaN Invalid_context
+precision: 99999999
+powx4002 power 1 1.1 -> NaN Invalid_context
+
+precision: 9
+maxExponent: 1000000
+minExponent: -999999
+powx4003 power 1 1.1 -> NaN Invalid_context
+maxExponent: 999999
+minExponent: -999999
+powx4004 power 1 1.1 -> 1.00000000 Inexact Rounded
+maxExponent: 999999
+minExponent: -1000000
+powx4005 power 1 1.1 -> NaN Invalid_context
+maxExponent: 999999
+minExponent: -999998
+powx4006 power 1 1.1 -> 1.00000000 Inexact Rounded
+
+-- operand range violations
+powx4007 power 1 1.1E+999999 -> 1
+powx4008 power 1 1.1E+1000000 -> NaN Invalid_operation
+powx4009 power 1.1E+999999 1.1 -> Infinity Overflow Inexact Rounded
+powx4010 power 1.1E+1000000 1.1 -> NaN Invalid_operation
+powx4011 power 1 1.1E-1999997 -> 1.00000000 Inexact Rounded
+powx4012 power 1 1.1E-1999998 -> NaN Invalid_operation
+powx4013 power 1.1E-1999997 1.1 -> 0E-1000006 Underflow Inexact Rounded Clamped Subnormal
+powx4014 power 1.1E-1999998 1.1 -> NaN Invalid_operation
+
+-- rounding modes -- power is sensitive
+precision: 7
+maxExponent: 99
+minExponent: -99
+
+-- 0.7 ** 3.3 => 0.30819354053418943822
+-- 0.7 ** 3.4 => 0.29739477638272533854
+-- -1.2 ** 17 => -22.18611106740436992
+-- -1.3 ** 17 => -86.50415919381337933
+-- 0.5 ** 11 => 0.00048828125
+-- 3.15 ** 3 => 31.255875
+
+rounding: up
+powx4100 power 0.7 3.3 -> 0.3081936 Inexact Rounded
+powx4101 power 0.7 3.4 -> 0.2973948 Inexact Rounded
+powx4102 power -1.2 17 -> -22.18612 Inexact Rounded
+powx4103 power -1.3 17 -> -86.50416 Inexact Rounded
+powx4104 power 17 81.27115 -> 9.999974E+99 Inexact Rounded
+powx4105 power 17 81.27116 -> Infinity Overflow Inexact Rounded
+
+rounding: down
+powx4120 power 0.7 3.3 -> 0.3081935 Inexact Rounded
+powx4121 power 0.7 3.4 -> 0.2973947 Inexact Rounded
+powx4122 power -1.2 17 -> -22.18611 Inexact Rounded
+powx4123 power -1.3 17 -> -86.50415 Inexact Rounded
+powx4124 power 17 81.27115 -> 9.999973E+99 Inexact Rounded
+powx4125 power 17 81.27116 -> 9.999999E+99 Overflow Inexact Rounded
+
+rounding: floor
+powx4140 power 0.7 3.3 -> 0.3081935 Inexact Rounded
+powx4141 power 0.7 3.4 -> 0.2973947 Inexact Rounded
+powx4142 power -1.2 17 -> -22.18612 Inexact Rounded
+powx4143 power -1.3 17 -> -86.50416 Inexact Rounded
+powx4144 power 17 81.27115 -> 9.999973E+99 Inexact Rounded
+powx4145 power 17 81.27116 -> 9.999999E+99 Overflow Inexact Rounded
+
+rounding: ceiling
+powx4160 power 0.7 3.3 -> 0.3081936 Inexact Rounded
+powx4161 power 0.7 3.4 -> 0.2973948 Inexact Rounded
+powx4162 power -1.2 17 -> -22.18611 Inexact Rounded
+powx4163 power -1.3 17 -> -86.50415 Inexact Rounded
+powx4164 power 17 81.27115 -> 9.999974E+99 Inexact Rounded
+powx4165 power 17 81.27116 -> Infinity Overflow Inexact Rounded
+
+rounding: half_up
+powx4180 power 0.7 3.3 -> 0.3081935 Inexact Rounded
+powx4181 power 0.7 3.4 -> 0.2973948 Inexact Rounded
+powx4182 power -1.2 17 -> -22.18611 Inexact Rounded
+powx4183 power -1.3 17 -> -86.50416 Inexact Rounded
+powx4184 power 0.5 11 -> 0.0004882813 Inexact Rounded
+powx4185 power 3.15 3 -> 31.25588 Inexact Rounded
+powx4186 power 17 81.27115 -> 9.999974E+99 Inexact Rounded
+powx4187 power 17 81.27116 -> Infinity Overflow Inexact Rounded
+
+rounding: half_even
+powx4200 power 0.7 3.3 -> 0.3081935 Inexact Rounded
+powx4201 power 0.7 3.4 -> 0.2973948 Inexact Rounded
+powx4202 power -1.2 17 -> -22.18611 Inexact Rounded
+powx4203 power -1.3 17 -> -86.50416 Inexact Rounded
+powx4204 power 0.5 11 -> 0.0004882812 Inexact Rounded
+powx4205 power 3.15 3 -> 31.25588 Inexact Rounded
+powx4206 power 17 81.27115 -> 9.999974E+99 Inexact Rounded
+powx4207 power 17 81.27116 -> Infinity Overflow Inexact Rounded
+
+rounding: half_down
+powx4220 power 0.7 3.3 -> 0.3081935 Inexact Rounded
+powx4221 power 0.7 3.4 -> 0.2973948 Inexact Rounded
+powx4222 power -1.2 17 -> -22.18611 Inexact Rounded
+powx4223 power -1.3 17 -> -86.50416 Inexact Rounded
+powx4224 power 0.5 11 -> 0.0004882812 Inexact Rounded
+powx4225 power 3.15 3 -> 31.25587 Inexact Rounded
+powx4226 power -3.15 3 -> -31.25587 Inexact Rounded
+powx4227 power 17 81.27115 -> 9.999974E+99 Inexact Rounded
+powx4228 power 17 81.27116 -> Infinity Overflow Inexact Rounded
+
+
+-- more rounding tests as per Ilan Nehama's suggestions & analysis
+-- these are likely to show > 0.5 ulp error for very small powers
+precision: 7
+maxExponent: 96
+minExponent: -95
+
+-- For x=nextfp(1)=1.00..001 (where the number of 0s is precision-2)
+-- power(x,y)=x when the rounding is up (e.g., toward_pos_inf or
+-- ceil) for any y in (0,1].
+rounding: ceiling
+powx4301 power 1.000001 0 -> 1
+-- The next test should be skipped for decNumber
+powx4302 power 1.000001 1e-101 -> 1.000001 Inexact Rounded
+-- The next test should be skipped for decNumber
+powx4303 power 1.000001 1e-95 -> 1.000001 Inexact Rounded
+powx4304 power 1.000001 1e-10 -> 1.000001 Inexact Rounded
+powx4305 power 1.000001 0.1 -> 1.000001 Inexact Rounded
+powx4306 power 1.000001 0.1234567 -> 1.000001 Inexact Rounded
+powx4307 power 1.000001 0.7 -> 1.000001 Inexact Rounded
+powx4308 power 1.000001 0.9999999 -> 1.000001 Inexact Rounded
+powx4309 power 1.000001 1.000000 -> 1.000001
+-- power(x,y)=1 when the rounding is down (e.g. toward_zero or
+-- floor) for any y in [0,1).
+rounding: floor
+powx4321 power 1.000001 0 -> 1
+powx4322 power 1.000001 1e-101 -> 1.000000 Inexact Rounded
+powx4323 power 1.000001 1e-95 -> 1.000000 Inexact Rounded
+powx4324 power 1.000001 1e-10 -> 1.000000 Inexact Rounded
+powx4325 power 1.000001 0.1 -> 1.000000 Inexact Rounded
+powx4326 power 1.000001 0.1234567 -> 1.000000 Inexact Rounded
+powx4327 power 1.000001 0.7 -> 1.000000 Inexact Rounded
+powx4328 power 1.000001 0.9999999 -> 1.000000 Inexact Rounded
+powx4329 power 1.000001 1.000000 -> 1.000001
+
+-- For x=prevfp(1)=0.99..99 (where the number of 9s is precision)
+-- power(x,y)=x when the rounding is down for any y in (0,1].
+rounding: floor
+powx4341 power 0.9999999 0 -> 1
+-- The next test should be skipped for decNumber
+powx4342 power 0.9999999 1e-101 -> 0.9999999 Inexact Rounded
+-- The next test should be skipped for decNumber
+powx4343 power 0.9999999 1e-95 -> 0.9999999 Inexact Rounded
+powx4344 power 0.9999999 1e-10 -> 0.9999999 Inexact Rounded
+powx4345 power 0.9999999 0.1 -> 0.9999999 Inexact Rounded
+powx4346 power 0.9999999 0.1234567 -> 0.9999999 Inexact Rounded
+powx4347 power 0.9999999 0.7 -> 0.9999999 Inexact Rounded
+powx4348 power 0.9999999 0.9999999 -> 0.9999999 Inexact Rounded
+powx4349 power 0.9999999 1.000000 -> 0.9999999
+-- power(x,y)=1 when the rounding is up for any y in (0,1].
+rounding: ceiling
+powx4361 power 0.9999999 0 -> 1
+powx4362 power 0.9999999 1e-101 -> 1.000000 Inexact Rounded
+powx4363 power 0.9999999 1e-95 -> 1.000000 Inexact Rounded
+powx4364 power 0.9999999 1e-10 -> 1.000000 Inexact Rounded
+powx4365 power 0.9999999 0.1 -> 1.000000 Inexact Rounded
+powx4366 power 0.9999999 0.1234567 -> 1.000000 Inexact Rounded
+powx4367 power 0.9999999 0.7 -> 1.000000 Inexact Rounded
+powx4368 power 0.9999999 0.9999999 -> 1.000000 Inexact Rounded
+powx4369 power 0.9999999 1.000000 -> 0.9999999
+
+-- For x=nextfp(0)
+-- power(x,y)=0 when the rounding is down for any y larger than 1.
+rounding: floor
+powx4382 power 1e-101 0 -> 1
+powx4383 power 1e-101 0.9999999 -> 1E-101 Underflow Subnormal Inexact Rounded
+powx4384 power 1e-101 1.000000 -> 1E-101 Subnormal
+powx4385 power 1e-101 1.000001 -> 0E-101 Underflow Subnormal Inexact Rounded Clamped
+powx4386 power 1e-101 2.000000 -> 0E-101 Underflow Subnormal Inexact Rounded Clamped
Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/quantize.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/quantize.decTest (original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/quantize.decTest Fri Sep 21 03:17:09 2007
@@ -1,6 +1,6 @@
------------------------------------------------------------------------
-- quantize.decTest -- decimal quantize operation --
--- Copyright (c) IBM Corporation, 1981, 2004. All rights reserved. --
+-- Copyright (c) IBM Corporation, 1981, 2007. All rights reserved. --
------------------------------------------------------------------------
-- Please see the document "General Decimal Arithmetic Testcases" --
-- at http://www2.hursley.ibm.com/decimal for the description of --
@@ -17,11 +17,12 @@
-- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
-- mfc at uk.ibm.com --
------------------------------------------------------------------------
-version: 2.39
+version: 2.56
-- Most of the tests here assume a "regular pattern", where the
-- sign and coefficient are +1.
-- 2004.03.15 Underflow for quantize is suppressed
+-- 2005.06.08 More extensive tests for 'does not fit'
extended: 1
precision: 9
@@ -123,10 +124,6 @@
quax124 quantize 1.05 1e-3 -> 1.050
quax125 quantize 1.05 1e-2 -> 1.05
quax126 quantize 1.05 1e-1 -> 1.1 Inexact Rounded
-quax127 quantize 1.05 1e0 -> 1 Inexact Rounded
-quax128 quantize 1.05 1e-3 -> 1.050
-quax129 quantize 1.05 1e-2 -> 1.05
-quax130 quantize 1.05 1e-1 -> 1.1 Inexact Rounded
quax131 quantize 1.05 1e0 -> 1 Inexact Rounded
quax132 quantize 1.06 1e-3 -> 1.060
quax133 quantize 1.06 1e-2 -> 1.06
@@ -435,6 +432,102 @@
quax472 quantize 9.999E-15 1e0 -> 0 Inexact Rounded
quax473 quantize 9.999E-15 1e1 -> 0E+1 Inexact Rounded
+precision: 7
+quax900 quantize 9.999E-15 1e-22 -> NaN Invalid_operation
+quax901 quantize 9.999E-15 1e-21 -> 9.999000E-15
+quax902 quantize 9.999E-15 1e-20 -> 9.99900E-15
+quax903 quantize 9.999E-15 1e-19 -> 9.9990E-15
+quax904 quantize 9.999E-15 1e-18 -> 9.999E-15
+quax905 quantize 9.999E-15 1e-17 -> 1.000E-14 Inexact Rounded
+quax906 quantize 9.999E-15 1e-16 -> 1.00E-14 Inexact Rounded
+quax907 quantize 9.999E-15 1e-15 -> 1.0E-14 Inexact Rounded
+quax908 quantize 9.999E-15 1e-14 -> 1E-14 Inexact Rounded
+quax909 quantize 9.999E-15 1e-13 -> 0E-13 Inexact Rounded
+quax910 quantize 9.999E-15 1e-12 -> 0E-12 Inexact Rounded
+quax911 quantize 9.999E-15 1e-11 -> 0E-11 Inexact Rounded
+quax912 quantize 9.999E-15 1e-10 -> 0E-10 Inexact Rounded
+quax913 quantize 9.999E-15 1e-9 -> 0E-9 Inexact Rounded
+quax914 quantize 9.999E-15 1e-8 -> 0E-8 Inexact Rounded
+quax915 quantize 9.999E-15 1e-7 -> 0E-7 Inexact Rounded
+quax916 quantize 9.999E-15 1e-6 -> 0.000000 Inexact Rounded
+quax917 quantize 9.999E-15 1e-5 -> 0.00000 Inexact Rounded
+quax918 quantize 9.999E-15 1e-4 -> 0.0000 Inexact Rounded
+quax919 quantize 9.999E-15 1e-3 -> 0.000 Inexact Rounded
+quax920 quantize 9.999E-15 1e-2 -> 0.00 Inexact Rounded
+quax921 quantize 9.999E-15 1e-1 -> 0.0 Inexact Rounded
+quax922 quantize 9.999E-15 1e0 -> 0 Inexact Rounded
+quax923 quantize 9.999E-15 1e1 -> 0E+1 Inexact Rounded
+
+precision: 6
+quax930 quantize 9.999E-15 1e-22 -> NaN Invalid_operation
+quax931 quantize 9.999E-15 1e-21 -> NaN Invalid_operation
+quax932 quantize 9.999E-15 1e-20 -> 9.99900E-15
+quax933 quantize 9.999E-15 1e-19 -> 9.9990E-15
+quax934 quantize 9.999E-15 1e-18 -> 9.999E-15
+quax935 quantize 9.999E-15 1e-17 -> 1.000E-14 Inexact Rounded
+quax936 quantize 9.999E-15 1e-16 -> 1.00E-14 Inexact Rounded
+quax937 quantize 9.999E-15 1e-15 -> 1.0E-14 Inexact Rounded
+quax938 quantize 9.999E-15 1e-14 -> 1E-14 Inexact Rounded
+quax939 quantize 9.999E-15 1e-13 -> 0E-13 Inexact Rounded
+quax940 quantize 9.999E-15 1e-12 -> 0E-12 Inexact Rounded
+quax941 quantize 9.999E-15 1e-11 -> 0E-11 Inexact Rounded
+quax942 quantize 9.999E-15 1e-10 -> 0E-10 Inexact Rounded
+quax943 quantize 9.999E-15 1e-9 -> 0E-9 Inexact Rounded
+quax944 quantize 9.999E-15 1e-8 -> 0E-8 Inexact Rounded
+quax945 quantize 9.999E-15 1e-7 -> 0E-7 Inexact Rounded
+quax946 quantize 9.999E-15 1e-6 -> 0.000000 Inexact Rounded
+quax947 quantize 9.999E-15 1e-5 -> 0.00000 Inexact Rounded
+quax948 quantize 9.999E-15 1e-4 -> 0.0000 Inexact Rounded
+quax949 quantize 9.999E-15 1e-3 -> 0.000 Inexact Rounded
+quax950 quantize 9.999E-15 1e-2 -> 0.00 Inexact Rounded
+quax951 quantize 9.999E-15 1e-1 -> 0.0 Inexact Rounded
+quax952 quantize 9.999E-15 1e0 -> 0 Inexact Rounded
+quax953 quantize 9.999E-15 1e1 -> 0E+1 Inexact Rounded
+
+precision: 3
+quax960 quantize 9.999E-15 1e-22 -> NaN Invalid_operation
+quax961 quantize 9.999E-15 1e-21 -> NaN Invalid_operation
+quax962 quantize 9.999E-15 1e-20 -> NaN Invalid_operation
+quax963 quantize 9.999E-15 1e-19 -> NaN Invalid_operation
+quax964 quantize 9.999E-15 1e-18 -> NaN Invalid_operation
+quax965 quantize 9.999E-15 1e-17 -> NaN Invalid_operation
+quax966 quantize 9.999E-15 1e-16 -> 1.00E-14 Inexact Rounded
+quax967 quantize 9.999E-15 1e-15 -> 1.0E-14 Inexact Rounded
+quax968 quantize 9.999E-15 1e-14 -> 1E-14 Inexact Rounded
+quax969 quantize 9.999E-15 1e-13 -> 0E-13 Inexact Rounded
+quax970 quantize 9.999E-15 1e-12 -> 0E-12 Inexact Rounded
+quax971 quantize 9.999E-15 1e-11 -> 0E-11 Inexact Rounded
+quax972 quantize 9.999E-15 1e-10 -> 0E-10 Inexact Rounded
+quax973 quantize 9.999E-15 1e-9 -> 0E-9 Inexact Rounded
+quax974 quantize 9.999E-15 1e-8 -> 0E-8 Inexact Rounded
+quax975 quantize 9.999E-15 1e-7 -> 0E-7 Inexact Rounded
+quax976 quantize 9.999E-15 1e-6 -> 0.000000 Inexact Rounded
+quax977 quantize 9.999E-15 1e-5 -> 0.00000 Inexact Rounded
+quax978 quantize 9.999E-15 1e-4 -> 0.0000 Inexact Rounded
+quax979 quantize 9.999E-15 1e-3 -> 0.000 Inexact Rounded
+quax980 quantize 9.999E-15 1e-2 -> 0.00 Inexact Rounded
+quax981 quantize 9.999E-15 1e-1 -> 0.0 Inexact Rounded
+quax982 quantize 9.999E-15 1e0 -> 0 Inexact Rounded
+quax983 quantize 9.999E-15 1e1 -> 0E+1 Inexact Rounded
+
+-- Fung Lee's case & similar
+precision: 3
+quax1001 quantize 0.000 0.001 -> 0.000
+quax1002 quantize 0.001 0.001 -> 0.001
+quax1003 quantize 0.0012 0.001 -> 0.001 Inexact Rounded
+quax1004 quantize 0.0018 0.001 -> 0.002 Inexact Rounded
+quax1005 quantize 0.501 0.001 -> 0.501
+quax1006 quantize 0.5012 0.001 -> 0.501 Inexact Rounded
+quax1007 quantize 0.5018 0.001 -> 0.502 Inexact Rounded
+quax1008 quantize 0.999 0.001 -> 0.999
+quax1009 quantize 0.9992 0.001 -> 0.999 Inexact Rounded
+quax1010 quantize 0.9998 0.001 -> NaN Invalid_operation
+quax1011 quantize 1.0001 0.001 -> NaN Invalid_operation
+quax1012 quantize 1.0051 0.001 -> NaN Invalid_operation
+quax1013 quantize 1.0551 0.001 -> NaN Invalid_operation
+quax1014 quantize 1.5551 0.001 -> NaN Invalid_operation
+quax1015 quantize 1.9999 0.001 -> NaN Invalid_operation
+
-- long operand checks [rhs checks removed]
maxexponent: 999
minexponent: -999
@@ -775,6 +868,81 @@
quax865 quantize 1 1e-2147483648 -> NaN Invalid_operation
quax866 quantize 1 1e-2147483649 -> NaN Invalid_operation
+-- More from Fung Lee
+precision: 16
+rounding: half_up
+maxExponent: 384
+minExponent: -383
+quax1021 quantize 8.666666666666000E+384 1.000000000000000E+384 -> 8.666666666666000E+384
+quax1022 quantize 64#8.666666666666000E+384 64#1.000000000000000E+384 -> 8.666666666666000E+384
+quax1023 quantize 64#8.666666666666000E+384 128#1.000000000000000E+384 -> 8.666666666666000E+384
+quax1024 quantize 64#8.666666666666000E+384 64#1E+384 -> 8.666666666666000E+384
+quax1025 quantize 64#8.666666666666000E+384 64#1E+384 -> 64#8.666666666666000E+384
+quax1026 quantize 64#8.666666666666000E+384 128#1E+384 -> 64#9E+384 Inexact Rounded Clamped
+quax1027 quantize 64#8.666666666666000E+323 64#1E+31 -> NaN Invalid_operation
+quax1028 quantize 64#8.666666666666000E+323 128#1E+31 -> NaN Invalid_operation
+quax1029 quantize 64#8.66666666E+3 128#1E+10 -> 64#0E10 Inexact Rounded
+quax1030 quantize 8.66666666E+3 1E+3 -> 9E+3 Inexact Rounded
+
+-- Int and uInt32 edge values for testing conversions
+quax1040 quantize -2147483646 0 -> -2147483646
+quax1041 quantize -2147483647 0 -> -2147483647
+quax1042 quantize -2147483648 0 -> -2147483648
+quax1043 quantize -2147483649 0 -> -2147483649
+quax1044 quantize 2147483646 0 -> 2147483646
+quax1045 quantize 2147483647 0 -> 2147483647
+quax1046 quantize 2147483648 0 -> 2147483648
+quax1047 quantize 2147483649 0 -> 2147483649
+quax1048 quantize 4294967294 0 -> 4294967294
+quax1049 quantize 4294967295 0 -> 4294967295
+quax1050 quantize 4294967296 0 -> 4294967296
+quax1051 quantize 4294967297 0 -> 4294967297
+-- and powers of ten for same
+quax1101 quantize 5000000000 0 -> 5000000000
+quax1102 quantize 4000000000 0 -> 4000000000
+quax1103 quantize 2000000000 0 -> 2000000000
+quax1104 quantize 1000000000 0 -> 1000000000
+quax1105 quantize 0100000000 0 -> 100000000
+quax1106 quantize 0010000000 0 -> 10000000
+quax1107 quantize 0001000000 0 -> 1000000
+quax1108 quantize 0000100000 0 -> 100000
+quax1109 quantize 0000010000 0 -> 10000
+quax1110 quantize 0000001000 0 -> 1000
+quax1111 quantize 0000000100 0 -> 100
+quax1112 quantize 0000000010 0 -> 10
+quax1113 quantize 0000000001 0 -> 1
+quax1114 quantize 0000000000 0 -> 0
+-- and powers of ten for same
+quax1121 quantize -5000000000 0 -> -5000000000
+quax1122 quantize -4000000000 0 -> -4000000000
+quax1123 quantize -2000000000 0 -> -2000000000
+quax1124 quantize -1000000000 0 -> -1000000000
+quax1125 quantize -0100000000 0 -> -100000000
+quax1126 quantize -0010000000 0 -> -10000000
+quax1127 quantize -0001000000 0 -> -1000000
+quax1128 quantize -0000100000 0 -> -100000
+quax1129 quantize -0000010000 0 -> -10000
+quax1130 quantize -0000001000 0 -> -1000
+quax1131 quantize -0000000100 0 -> -100
+quax1132 quantize -0000000010 0 -> -10
+quax1133 quantize -0000000001 0 -> -1
+quax1134 quantize -0000000000 0 -> -0
+
+-- Some miscellany
+precision: 34
+rounding: half_up
+maxExponent: 6144
+minExponent: -6143
+-- 1 2 3
+-- 1 234567890123456789012345678901234
+quax0a1 quantize 8.555555555555555555555555555555555E+6143 1E+6143 -> 9E+6143 Inexact Rounded
+quax0a2 quantize 128#8.555555555555555555555555555555555E+6143 128#1E+6143 -> 8.55555555555555555555555555555556E+6143 Rounded Inexact
+quax0a3 quantize 128#8.555555555555555555555555555555555E+6144 128#1E+6144 -> 8.555555555555555555555555555555555E+6144
+
+-- payload decapitate
+precision: 5
+quax62100 quantize 11 -sNaN1234567890 -> -NaN67890 Invalid_operation
+
-- Null tests
-quax900 quantize 10 # -> NaN Invalid_operation
-quax901 quantize # 1e10 -> NaN Invalid_operation
+quax998 quantize 10 # -> NaN Invalid_operation
+quax999 quantize # 1e10 -> NaN Invalid_operation
Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/randomBound32.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/randomBound32.decTest (original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/randomBound32.decTest Fri Sep 21 03:17:09 2007
@@ -1,6 +1,6 @@
------------------------------------------------------------------------
-- randomBound32.decTest -- decimal testcases -- boundaries near 32 --
--- Copyright (c) IBM Corporation, 1981, 2003. All rights reserved. --
+-- Copyright (c) IBM Corporation, 1981, 2007. All rights reserved. --
------------------------------------------------------------------------
-- Please see the document "General Decimal Arithmetic Testcases" --
-- at http://www2.hursley.ibm.com/decimal for the description of --
@@ -17,7 +17,7 @@
-- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
-- mfc at uk.ibm.com --
------------------------------------------------------------------------
-version: 2.39
+version: 2.55
-- These testcases test calculations at precisions 31, 32, and 33, to
-- exercise the boundaries around 2**5
@@ -90,7 +90,7 @@
divx3008 divide 75353574493.84484153484918212042 -8684111695095849922263044191221 -> -8.677177026223536475531592432118E-21 Inexact Rounded
dvix3008 divideint 75353574493.84484153484918212042 -8684111695095849922263044191221 -> -0
mulx3008 multiply 75353574493.84484153484918212042 -8684111695095849922263044191221 -> -6.543788575292743281456830701127E+41 Inexact Rounded
-powx3008 power 75353574493.84484153484918212042 -9 -> 1.276630670287906925570645490708E-98 Inexact Rounded
+powx3008 power 75353574493.84484153484918212042 -9 -> 1.276630670287906925570645490707E-98 Inexact Rounded
remx3008 remainder 75353574493.84484153484918212042 -8684111695095849922263044191221 -> 75353574493.84484153484918212042
subx3008 subtract 75353574493.84484153484918212042 -8684111695095849922263044191221 -> 8684111695095849922338397765715 Inexact Rounded
addx3009 add 6907058.216435355874729592373011 2.857005446917670515662398741545 -> 6907061.073440802792400108035410 Inexact Rounded
@@ -1040,7 +1040,7 @@
divx3226 divide 47.525676459351505682005359699680E+704 -58631943508436657383369760970210 -> -8.1057651538555854520994438038537E+673 Inexact Rounded
dvix3226 divideint 47.525676459351505682005359699680E+704 -58631943508436657383369760970210 -> NaN Division_impossible
mulx3226 multiply 47.525676459351505682005359699680E+704 -58631943508436657383369760970210 -> -2.7865227773649353769876975366506E+737 Inexact Rounded
-powx3226 power 47.525676459351505682005359699680E+704 -6 -> 8.6782100393941226535150385475463E-4235 Inexact Rounded
+powx3226 power 47.525676459351505682005359699680E+704 -6 -> 8.6782100393941226535150385475464E-4235 Inexact Rounded
remx3226 remainder 47.525676459351505682005359699680E+704 -58631943508436657383369760970210 -> NaN Division_impossible
subx3226 subtract 47.525676459351505682005359699680E+704 -58631943508436657383369760970210 -> 4.7525676459351505682005359699680E+705 Inexact Rounded
addx3227 add -74396862273800.625679130772935550 -115616605.52826981284183992013157 -> -74396977890406.153948943614775470 Inexact Rounded
Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/randoms.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/randoms.decTest (original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/randoms.decTest Fri Sep 21 03:17:09 2007
@@ -1,6 +1,6 @@
------------------------------------------------------------------------
-- randoms.decTest -- decimal random testcases --
--- Copyright (c) IBM Corporation, 1981, 2003. All rights reserved. --
+-- Copyright (c) IBM Corporation, 1981, 2007. All rights reserved. --
------------------------------------------------------------------------
-- Please see the document "General Decimal Arithmetic Testcases" --
-- at http://www2.hursley.ibm.com/decimal for the description of --
@@ -17,7 +17,7 @@
-- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
-- mfc at uk.ibm.com --
------------------------------------------------------------------------
-version: 2.39
+version: 2.56
extended: 1
maxexponent: 999999999
@@ -264,7 +264,7 @@
xdiv030 divide -225094.28 -88.7723542 -> 2535.63491 Inexact Rounded
xdvi030 divideint -225094.28 -88.7723542 -> 2535
xmul030 multiply -225094.28 -88.7723542 -> 19982149.2 Inexact Rounded
-xpow030 power -225094.28 -89 -> -4.36076964E-477 Inexact Rounded
+xpow030 power -225094.28 -89 -> -4.36076965E-477 Inexact Rounded
xrem030 remainder -225094.28 -88.7723542 -> -56.3621030
xsub030 subtract -225094.28 -88.7723542 -> -225005.508 Inexact Rounded
xadd031 add 50.4442340 82.7952169E+880120759 -> 8.27952169E+880120760 Inexact Rounded
@@ -295,7 +295,7 @@
xcom034 compare 592.142173E-419941416 -3.46079109E-844011845 -> 1
xdiv034 divide 592.142173E-419941416 -3.46079109E-844011845 -> -1.71100236E+424070431 Inexact Rounded
xdvi034 divideint 592.142173E-419941416 -3.46079109E-844011845 -> NaN Division_impossible
-xmul034 multiply 592.142173E-419941416 -3.46079109E-844011845 -> -0E-1000000007 Underflow Subnormal Inexact Rounded
+xmul034 multiply 592.142173E-419941416 -3.46079109E-844011845 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
xpow034 power 592.142173E-419941416 -3 -> Infinity Overflow Inexact Rounded
xrem034 remainder 592.142173E-419941416 -3.46079109E-844011845 -> NaN Division_impossible
xsub034 subtract 592.142173E-419941416 -3.46079109E-844011845 -> 5.92142173E-419941414 Inexact Rounded
@@ -487,7 +487,7 @@
xcom058 compare 151795163E-371727182 -488.09788E-738852245 -> 1
xdiv058 divide 151795163E-371727182 -488.09788E-738852245 -> -3.10993285E+367125068 Inexact Rounded
xdvi058 divideint 151795163E-371727182 -488.09788E-738852245 -> NaN Division_impossible
-xmul058 multiply 151795163E-371727182 -488.09788E-738852245 -> -0E-1000000007 Underflow Subnormal Inexact Rounded
+xmul058 multiply 151795163E-371727182 -488.09788E-738852245 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
xpow058 power 151795163E-371727182 -5 -> Infinity Overflow Inexact Rounded
xrem058 remainder 151795163E-371727182 -488.09788E-738852245 -> NaN Division_impossible
xsub058 subtract 151795163E-371727182 -488.09788E-738852245 -> 1.51795163E-371727174 Inexact Rounded
@@ -568,7 +568,7 @@
xdiv068 divide -12393257.2 76803689E+949125770 -> -1.61362786E-949125771 Inexact Rounded
xdvi068 divideint -12393257.2 76803689E+949125770 -> -0
xmul068 multiply -12393257.2 76803689E+949125770 -> -9.51847872E+949125784 Inexact Rounded
-xpow068 power -12393257.2 8 -> 5.56523750E+56 Inexact Rounded
+xpow068 power -12393257.2 8 -> 5.56523749E+56 Inexact Rounded
xrem068 remainder -12393257.2 76803689E+949125770 -> -12393257.2
xsub068 subtract -12393257.2 76803689E+949125770 -> -7.68036890E+949125777 Inexact Rounded
xadd069 add -754771634.E+716555026 -292336.311 -> -7.54771634E+716555034 Inexact Rounded
@@ -775,7 +775,7 @@
xcom094 compare -671.507198E-908587890 3057429.32E-555230623 -> -1
xdiv094 divide -671.507198E-908587890 3057429.32E-555230623 -> -2.19631307E-353357271 Inexact Rounded
xdvi094 divideint -671.507198E-908587890 3057429.32E-555230623 -> -0
-xmul094 multiply -671.507198E-908587890 3057429.32E-555230623 -> -0E-1000000007 Underflow Subnormal Inexact Rounded
+xmul094 multiply -671.507198E-908587890 3057429.32E-555230623 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
xpow094 power -671.507198E-908587890 3 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
xrem094 remainder -671.507198E-908587890 3057429.32E-555230623 -> -6.71507198E-908587888
xsub094 subtract -671.507198E-908587890 3057429.32E-555230623 -> -3.05742932E-555230617 Inexact Rounded
@@ -856,7 +856,7 @@
xdiv104 divide 553527296. -7924.40185 -> -69850.9877 Inexact Rounded
xdvi104 divideint 553527296. -7924.40185 -> -69850
xmul104 multiply 553527296. -7924.40185 -> -4.38637273E+12 Inexact Rounded
-xpow104 power 553527296. -7924 -> 2.32397213E-69281 Inexact Rounded
+xpow104 power 553527296. -7924 -> 2.32397214E-69281 Inexact Rounded
xrem104 remainder 553527296. -7924.40185 -> 7826.77750
xsub104 subtract 553527296. -7924.40185 -> 553535220 Inexact Rounded
xadd105 add -38.7465207 64936.2942 -> 64897.5477 Inexact Rounded
@@ -919,7 +919,7 @@
xcom112 compare -51.1632090E-753968082 8.96207471E-585797887 -> -1
xdiv112 divide -51.1632090E-753968082 8.96207471E-585797887 -> -5.70885768E-168170195 Inexact Rounded
xdvi112 divideint -51.1632090E-753968082 8.96207471E-585797887 -> -0
-xmul112 multiply -51.1632090E-753968082 8.96207471E-585797887 -> -0E-1000000007 Underflow Subnormal Inexact Rounded
+xmul112 multiply -51.1632090E-753968082 8.96207471E-585797887 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
xpow112 power -51.1632090E-753968082 9 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
xrem112 remainder -51.1632090E-753968082 8.96207471E-585797887 -> -5.11632090E-753968081
xsub112 subtract -51.1632090E-753968082 8.96207471E-585797887 -> -8.96207471E-585797887 Inexact Rounded
@@ -989,7 +989,7 @@
xsub120 subtract 14239029. -36527.2221 -> 14275556.2 Inexact Rounded
xadd121 add 72333.2654E-544425548 -690.664836E+662155120 -> -6.90664836E+662155122 Inexact Rounded
xcom121 compare 72333.2654E-544425548 -690.664836E+662155120 -> 1
-xdiv121 divide 72333.2654E-544425548 -690.664836E+662155120 -> -0E-1000000007 Inexact Rounded Underflow Subnormal
+xdiv121 divide 72333.2654E-544425548 -690.664836E+662155120 -> -0E-1000000007 Inexact Rounded Underflow Subnormal Clamped
xdvi121 divideint 72333.2654E-544425548 -690.664836E+662155120 -> -0
xmul121 multiply 72333.2654E-544425548 -690.664836E+662155120 -> -4.99580429E+117729579 Inexact Rounded
xpow121 power 72333.2654E-544425548 -7 -> Infinity Overflow Inexact Rounded
@@ -1005,7 +1005,7 @@
xsub122 subtract -37721.1567E-115787341 -828949864E-76251747 -> 8.28949864E-76251739 Inexact Rounded
xadd123 add -2078852.83E-647080089 -119779858.E+734665461 -> -1.19779858E+734665469 Inexact Rounded
xcom123 compare -2078852.83E-647080089 -119779858.E+734665461 -> 1
-xdiv123 divide -2078852.83E-647080089 -119779858.E+734665461 -> 0E-1000000007 Inexact Rounded Underflow Subnormal
+xdiv123 divide -2078852.83E-647080089 -119779858.E+734665461 -> 0E-1000000007 Inexact Rounded Underflow Subnormal Clamped
xdvi123 divideint -2078852.83E-647080089 -119779858.E+734665461 -> 0
xmul123 multiply -2078852.83E-647080089 -119779858.E+734665461 -> 2.49004697E+87585386 Inexact Rounded
xpow123 power -2078852.83E-647080089 -1 -> -4.81034533E+647080082 Inexact Rounded
@@ -1183,7 +1183,7 @@
xcom145 compare -477067757.E-961684940 7.70122608E-741072245 -> -1
xdiv145 divide -477067757.E-961684940 7.70122608E-741072245 -> -6.19469877E-220612688 Inexact Rounded
xdvi145 divideint -477067757.E-961684940 7.70122608E-741072245 -> -0
-xmul145 multiply -477067757.E-961684940 7.70122608E-741072245 -> -0E-1000000007 Underflow Subnormal Inexact Rounded
+xmul145 multiply -477067757.E-961684940 7.70122608E-741072245 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
xpow145 power -477067757.E-961684940 8 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
xrem145 remainder -477067757.E-961684940 7.70122608E-741072245 -> -4.77067757E-961684932
xsub145 subtract -477067757.E-961684940 7.70122608E-741072245 -> -7.70122608E-741072245 Inexact Rounded
@@ -1296,7 +1296,7 @@
xdiv159 divide -18861647. 99794586.7 -> -0.189004711 Inexact Rounded
xdvi159 divideint -18861647. 99794586.7 -> -0
xmul159 multiply -18861647. 99794586.7 -> -1.88229027E+15 Inexact Rounded
-xpow159 power -18861647. 99794587 -> -4.28957460E+726063462 Inexact Rounded
+xpow159 power -18861647. 99794587 -> -4.28957459E+726063462 Inexact Rounded
xrem159 remainder -18861647. 99794586.7 -> -18861647.0
xsub159 subtract -18861647. 99794586.7 -> -118656234 Inexact Rounded
xadd160 add 322192.407 461.67044 -> 322654.077 Inexact Rounded
@@ -1519,7 +1519,7 @@
xcom187 compare -29.356551E-282816139 37141748E-903397821 -> -1
xdiv187 divide -29.356551E-282816139 37141748E-903397821 -> -7.90392283E+620581675 Inexact Rounded
xdvi187 divideint -29.356551E-282816139 37141748E-903397821 -> NaN Division_impossible
-xmul187 multiply -29.356551E-282816139 37141748E-903397821 -> -0E-1000000007 Underflow Subnormal Inexact Rounded
+xmul187 multiply -29.356551E-282816139 37141748E-903397821 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
xpow187 power -29.356551E-282816139 4 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
xrem187 remainder -29.356551E-282816139 37141748E-903397821 -> NaN Division_impossible
xsub187 subtract -29.356551E-282816139 37141748E-903397821 -> -2.93565510E-282816138 Inexact Rounded
@@ -1760,7 +1760,7 @@
xdiv217 divide 7428219.97 667.326760 -> 11131.3084 Inexact Rounded
xdvi217 divideint 7428219.97 667.326760 -> 11131
xmul217 multiply 7428219.97 667.326760 -> 4.95704997E+9 Inexact Rounded
-xpow217 power 7428219.97 667 -> 7.58808510E+4582 Inexact Rounded
+xpow217 power 7428219.97 667 -> 7.58808509E+4582 Inexact Rounded
xrem217 remainder 7428219.97 667.326760 -> 205.804440
xsub217 subtract 7428219.97 667.326760 -> 7427552.64 Inexact Rounded
xadd218 add -7291.19212 209.64966E-588526476 -> -7291.19212 Inexact Rounded
@@ -2200,7 +2200,7 @@
xdiv272 divide 513115529. 27775075.6E+217133352 -> 1.84739562E-217133351 Inexact Rounded
xdvi272 divideint 513115529. 27775075.6E+217133352 -> 0
xmul272 multiply 513115529. 27775075.6E+217133352 -> 1.42518226E+217133368 Inexact Rounded
-xpow272 power 513115529. 3 -> 1.35096929E+26 Inexact Rounded
+xpow272 power 513115529. 3 -> 1.35096928E+26 Inexact Rounded
xrem272 remainder 513115529. 27775075.6E+217133352 -> 513115529
xsub272 subtract 513115529. 27775075.6E+217133352 -> -2.77750756E+217133359 Inexact Rounded
xadd273 add -247157.208 -532990.453 -> -780147.661
@@ -2327,7 +2327,7 @@
xcom288 compare -4.18074650E-858746879 571035.277E-279409165 -> -1
xdiv288 divide -4.18074650E-858746879 571035.277E-279409165 -> -7.32134540E-579337720 Inexact Rounded
xdvi288 divideint -4.18074650E-858746879 571035.277E-279409165 -> -0
-xmul288 multiply -4.18074650E-858746879 571035.277E-279409165 -> -0E-1000000007 Underflow Subnormal Inexact Rounded
+xmul288 multiply -4.18074650E-858746879 571035.277E-279409165 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
xpow288 power -4.18074650E-858746879 6 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
xrem288 remainder -4.18074650E-858746879 571035.277E-279409165 -> -4.18074650E-858746879
xsub288 subtract -4.18074650E-858746879 571035.277E-279409165 -> -5.71035277E-279409160 Inexact Rounded
@@ -2599,7 +2599,7 @@
xcom322 compare 82.4185291E-321919303 -215747737.E-995147400 -> 1
xdiv322 divide 82.4185291E-321919303 -215747737.E-995147400 -> -3.82013412E+673228090 Inexact Rounded
xdvi322 divideint 82.4185291E-321919303 -215747737.E-995147400 -> NaN Division_impossible
-xmul322 multiply 82.4185291E-321919303 -215747737.E-995147400 -> -0E-1000000007 Underflow Subnormal Inexact Rounded
+xmul322 multiply 82.4185291E-321919303 -215747737.E-995147400 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
xpow322 power 82.4185291E-321919303 -2 -> 1.47214396E+643838602 Inexact Rounded
xrem322 remainder 82.4185291E-321919303 -215747737.E-995147400 -> NaN Division_impossible
xsub322 subtract 82.4185291E-321919303 -215747737.E-995147400 -> 8.24185291E-321919302 Inexact Rounded
@@ -2640,7 +2640,7 @@
xdiv327 divide 2512953.3 -3769170.35E-993621645 -> -6.66712583E+993621644 Inexact Rounded
xdvi327 divideint 2512953.3 -3769170.35E-993621645 -> NaN Division_impossible
xmul327 multiply 2512953.3 -3769170.35E-993621645 -> -9.47174907E-993621633 Inexact Rounded
-xpow327 power 2512953.3 -4 -> 2.50762349E-26 Inexact Rounded
+xpow327 power 2512953.3 -4 -> 2.50762348E-26 Inexact Rounded
xrem327 remainder 2512953.3 -3769170.35E-993621645 -> NaN Division_impossible
xsub327 subtract 2512953.3 -3769170.35E-993621645 -> 2512953.30 Inexact Rounded
xadd328 add -682.796370 71131.0224 -> 70448.2260 Inexact Rounded
@@ -2656,7 +2656,7 @@
xdiv329 divide 89.9997490 -4993.69831 -> -0.0180226644 Inexact Rounded
xdvi329 divideint 89.9997490 -4993.69831 -> -0
xmul329 multiply 89.9997490 -4993.69831 -> -449431.594 Inexact Rounded
-xpow329 power 89.9997490 -4994 -> 3.30336526E-9760 Inexact Rounded
+xpow329 power 89.9997490 -4994 -> 3.30336525E-9760 Inexact Rounded
xrem329 remainder 89.9997490 -4993.69831 -> 89.9997490
xsub329 subtract 89.9997490 -4993.69831 -> 5083.69806 Inexact Rounded
xadd330 add 76563354.6E-112338836 278271.585E-511481095 -> 7.65633546E-112338829 Inexact Rounded
@@ -2821,7 +2821,7 @@
xsub349 subtract -4037911.02E+641367645 29.5713010 -> -4.03791102E+641367651 Inexact Rounded
xadd350 add -688755561.E-95301699 978.275312E+913812609 -> 9.78275312E+913812611 Inexact Rounded
xcom350 compare -688755561.E-95301699 978.275312E+913812609 -> -1
-xdiv350 divide -688755561.E-95301699 978.275312E+913812609 -> -0E-1000000007 Inexact Rounded Underflow Subnormal
+xdiv350 divide -688755561.E-95301699 978.275312E+913812609 -> -0E-1000000007 Inexact Rounded Underflow Subnormal Clamped
xdvi350 divideint -688755561.E-95301699 978.275312E+913812609 -> -0
xmul350 multiply -688755561.E-95301699 978.275312E+913812609 -> -6.73792561E+818510921 Inexact Rounded
xpow350 power -688755561.E-95301699 10 -> 2.40243244E-953016902 Inexact Rounded
@@ -3024,7 +3024,7 @@
xdiv375 divide -5549320.1 -93580684.1 -> 0.0592998454 Inexact Rounded
xdvi375 divideint -5549320.1 -93580684.1 -> 0
xmul375 multiply -5549320.1 -93580684.1 -> 5.19309171E+14 Inexact Rounded
-xpow375 power -5549320.1 -93580684 -> 4.20662080E-631130572 Inexact Rounded
+xpow375 power -5549320.1 -93580684 -> 4.20662079E-631130572 Inexact Rounded
xrem375 remainder -5549320.1 -93580684.1 -> -5549320.1
xsub375 subtract -5549320.1 -93580684.1 -> 88031364.0
xadd376 add -14677053.1 -25784.7358 -> -14702837.8 Inexact Rounded
@@ -3191,7 +3191,7 @@
xcom396 compare 4880.06442E-382222621 -115627239E-912834031 -> 1
xdiv396 divide 4880.06442E-382222621 -115627239E-912834031 -> -4.22051453E+530611405 Inexact Rounded
xdvi396 divideint 4880.06442E-382222621 -115627239E-912834031 -> NaN Division_impossible
-xmul396 multiply 4880.06442E-382222621 -115627239E-912834031 -> -0E-1000000007 Underflow Subnormal Inexact Rounded
+xmul396 multiply 4880.06442E-382222621 -115627239E-912834031 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
xpow396 power 4880.06442E-382222621 -1 -> 2.04915328E+382222617 Inexact Rounded
xrem396 remainder 4880.06442E-382222621 -115627239E-912834031 -> NaN Division_impossible
xsub396 subtract 4880.06442E-382222621 -115627239E-912834031 -> 4.88006442E-382222618 Inexact Rounded
@@ -3295,7 +3295,7 @@
xcom409 compare -54.3684171E-807210192 1.04592973E-984041807 -> -1
xdiv409 divide -54.3684171E-807210192 1.04592973E-984041807 -> -5.19809463E+176831616 Inexact Rounded
xdvi409 divideint -54.3684171E-807210192 1.04592973E-984041807 -> NaN Division_impossible
-xmul409 multiply -54.3684171E-807210192 1.04592973E-984041807 -> -0E-1000000007 Underflow Subnormal Inexact Rounded
+xmul409 multiply -54.3684171E-807210192 1.04592973E-984041807 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
xpow409 power -54.3684171E-807210192 1 -> -5.43684171E-807210191
xrem409 remainder -54.3684171E-807210192 1.04592973E-984041807 -> NaN Division_impossible
xsub409 subtract -54.3684171E-807210192 1.04592973E-984041807 -> -5.43684171E-807210191 Inexact Rounded
@@ -3391,7 +3391,7 @@
xcom421 compare -4.09492571E-301749490 434.20199E-749390952 -> -1
xdiv421 divide -4.09492571E-301749490 434.20199E-749390952 -> -9.43092341E+447641459 Inexact Rounded
xdvi421 divideint -4.09492571E-301749490 434.20199E-749390952 -> NaN Division_impossible
-xmul421 multiply -4.09492571E-301749490 434.20199E-749390952 -> -0E-1000000007 Underflow Subnormal Inexact Rounded
+xmul421 multiply -4.09492571E-301749490 434.20199E-749390952 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
xpow421 power -4.09492571E-301749490 4 -> 0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
xrem421 remainder -4.09492571E-301749490 434.20199E-749390952 -> NaN Division_impossible
xsub421 subtract -4.09492571E-301749490 434.20199E-749390952 -> -4.09492571E-301749490 Inexact Rounded
@@ -3423,7 +3423,7 @@
xcom425 compare 6.88891136E-935467395 -785049.562E-741671442 -> 1
xdiv425 divide 6.88891136E-935467395 -785049.562E-741671442 -> -8.77512923E-193795959 Inexact Rounded
xdvi425 divideint 6.88891136E-935467395 -785049.562E-741671442 -> -0
-xmul425 multiply 6.88891136E-935467395 -785049.562E-741671442 -> -0E-1000000007 Underflow Subnormal Inexact Rounded
+xmul425 multiply 6.88891136E-935467395 -785049.562E-741671442 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
xpow425 power 6.88891136E-935467395 -8 -> Infinity Overflow Inexact Rounded
xrem425 remainder 6.88891136E-935467395 -785049.562E-741671442 -> 6.88891136E-935467395
xsub425 subtract 6.88891136E-935467395 -785049.562E-741671442 -> 7.85049562E-741671437 Inexact Rounded
@@ -3535,7 +3535,7 @@
xcom439 compare 971113.655E-695540249 -419351120E-977743823 -> 1
xdiv439 divide 971113.655E-695540249 -419351120E-977743823 -> -2.31575310E+282203571 Inexact Rounded
xdvi439 divideint 971113.655E-695540249 -419351120E-977743823 -> NaN Division_impossible
-xmul439 multiply 971113.655E-695540249 -419351120E-977743823 -> -0E-1000000007 Underflow Subnormal Inexact Rounded
+xmul439 multiply 971113.655E-695540249 -419351120E-977743823 -> -0E-1000000007 Underflow Subnormal Inexact Rounded Clamped
xpow439 power 971113.655E-695540249 -4 -> Infinity Overflow Inexact Rounded
xrem439 remainder 971113.655E-695540249 -419351120E-977743823 -> NaN Division_impossible
xsub439 subtract 971113.655E-695540249 -419351120E-977743823 -> 9.71113655E-695540244 Inexact Rounded
@@ -3600,7 +3600,7 @@
xdiv447 divide -9.95836312 -866466703 -> 1.14930707E-8 Inexact Rounded
xdvi447 divideint -9.95836312 -866466703 -> 0
xmul447 multiply -9.95836312 -866466703 -> 8.62859006E+9 Inexact Rounded
-xpow447 power -9.95836312 -866466703 -> -6.71744368E-864896630 Inexact Rounded
+xpow447 power -9.95836312 -866466703 -> -6.71744369E-864896630 Inexact Rounded
xrem447 remainder -9.95836312 -866466703 -> -9.95836312
xsub447 subtract -9.95836312 -866466703 -> 866466693 Inexact Rounded
xadd448 add 80919339.2E-967231586 219.824266 -> 219.824266 Inexact Rounded
@@ -3616,7 +3616,7 @@
xdiv449 divide 159579.444 -89827.5229 -> -1.77650946 Inexact Rounded
xdvi449 divideint 159579.444 -89827.5229 -> -1
xmul449 multiply 159579.444 -89827.5229 -> -1.43346262E+10 Inexact Rounded
-xpow449 power 159579.444 -89828 -> 9.69955849E-467374 Inexact Rounded
+xpow449 power 159579.444 -89828 -> 9.69955850E-467374 Inexact Rounded
xrem449 remainder 159579.444 -89827.5229 -> 69751.9211
xsub449 subtract 159579.444 -89827.5229 -> 249406.967 Inexact Rounded
xadd450 add -4.54000153 6966333.74 -> 6966329.20 Inexact Rounded
@@ -3640,7 +3640,7 @@
xdiv452 divide -361382575. -7976.15286E+898491169 -> 4.53078798E-898491165 Inexact Rounded
xdvi452 divideint -361382575. -7976.15286E+898491169 -> 0
xmul452 multiply -361382575. -7976.15286E+898491169 -> 2.88244266E+898491181 Inexact Rounded
-xpow452 power -361382575. -8 -> 3.43765536E-69 Inexact Rounded
+xpow452 power -361382575. -8 -> 3.43765537E-69 Inexact Rounded
xrem452 remainder -361382575. -7976.15286E+898491169 -> -361382575
xsub452 subtract -361382575. -7976.15286E+898491169 -> 7.97615286E+898491172 Inexact Rounded
xadd453 add 7021805.61 1222952.83 -> 8244758.44
@@ -3720,7 +3720,7 @@
xdiv462 divide -51592.2698 -713885.741 -> 0.0722696460 Inexact Rounded
xdvi462 divideint -51592.2698 -713885.741 -> 0
xmul462 multiply -51592.2698 -713885.741 -> 3.68309858E+10 Inexact Rounded
-xpow462 power -51592.2698 -713886 -> 6.38576921E-3364249 Inexact Rounded
+xpow462 power -51592.2698 -713886 -> 6.38576920E-3364249 Inexact Rounded
xrem462 remainder -51592.2698 -713885.741 -> -51592.2698
xsub462 subtract -51592.2698 -713885.741 -> 662293.471 Inexact Rounded
xadd463 add 51.2279848E+80439745 207.55925E+865165070 -> 2.07559250E+865165072 Inexact Rounded
@@ -3768,7 +3768,7 @@
xdiv468 divide -5.32711606 -8447286.21 -> 6.30630468E-7 Inexact Rounded
xdvi468 divideint -5.32711606 -8447286.21 -> 0
xmul468 multiply -5.32711606 -8447286.21 -> 44999674.0 Inexact Rounded
-xpow468 power -5.32711606 -8447286 -> 9.09138729E-6136888 Inexact Rounded
+xpow468 power -5.32711606 -8447286 -> 9.09138728E-6136888 Inexact Rounded
xrem468 remainder -5.32711606 -8447286.21 -> -5.32711606
xsub468 subtract -5.32711606 -8447286.21 -> 8447280.88 Inexact Rounded
xadd469 add -82272171.8 -776.238587E-372690416 -> -82272171.8 Inexact Rounded
@@ -4027,3 +4027,4 @@
xpow500 power -525445087.E+231529167 188227460 -> Infinity Overflow Inexact Rounded
xrem500 remainder -525445087.E+231529167 188227460 -> NaN Division_impossible
xsub500 subtract -525445087.E+231529167 188227460 -> -5.25445087E+231529175 Inexact Rounded
+
Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/remainder.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/remainder.decTest (original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/remainder.decTest Fri Sep 21 03:17:09 2007
@@ -1,6 +1,6 @@
------------------------------------------------------------------------
-- remainder.decTest -- decimal remainder --
--- Copyright (c) IBM Corporation, 1981, 2004. All rights reserved. --
+-- Copyright (c) IBM Corporation, 1981, 2007. All rights reserved. --
------------------------------------------------------------------------
-- Please see the document "General Decimal Arithmetic Testcases" --
-- at http://www2.hursley.ibm.com/decimal for the description of --
@@ -17,7 +17,7 @@
-- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
-- mfc at uk.ibm.com --
------------------------------------------------------------------------
-version: 2.39
+version: 2.56
extended: 1
precision: 9
@@ -351,6 +351,17 @@
remx408 remainder 0.55555555 1 -> 0.55555555
remx409 remainder 0.555555555 1 -> 0.555555555
+-- zero signs
+remx650 remainder 1 1 -> 0
+remx651 remainder -1 1 -> -0
+remx652 remainder 1 -1 -> 0
+remx653 remainder -1 -1 -> -0
+remx654 remainder 0 1 -> 0
+remx655 remainder -0 1 -> -0
+remx656 remainder 0 -1 -> 0
+remx657 remainder -0 -1 -> -0
+remx658 remainder 0.00 1 -> 0.00
+remx659 remainder -0.00 1 -> -0.00
-- Specials
remx680 remainder Inf -Inf -> NaN Invalid_operation
Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/remainderNear.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/remainderNear.decTest (original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/remainderNear.decTest Fri Sep 21 03:17:09 2007
@@ -1,6 +1,6 @@
------------------------------------------------------------------------
-- remainderNear.decTest -- decimal remainder-near (IEEE remainder) --
--- Copyright (c) IBM Corporation, 1981, 2004. All rights reserved. --
+-- Copyright (c) IBM Corporation, 1981, 2007. All rights reserved. --
------------------------------------------------------------------------
-- Please see the document "General Decimal Arithmetic Testcases" --
-- at http://www2.hursley.ibm.com/decimal for the description of --
@@ -17,7 +17,7 @@
-- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
-- mfc at uk.ibm.com --
------------------------------------------------------------------------
-version: 2.39
+version: 2.55
extended: 1
precision: 9
Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/rescale.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/rescale.decTest (original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/rescale.decTest Fri Sep 21 03:17:09 2007
@@ -1,6 +1,6 @@
------------------------------------------------------------------------
-- rescale.decTest -- decimal rescale operation --
--- Copyright (c) IBM Corporation, 1981, 2004. All rights reserved. --
+-- Copyright (c) IBM Corporation, 1981, 2007. All rights reserved. --
------------------------------------------------------------------------
-- Please see the document "General Decimal Arithmetic Testcases" --
-- at http://www2.hursley.ibm.com/decimal for the description of --
@@ -17,7 +17,7 @@
-- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
-- mfc at uk.ibm.com --
------------------------------------------------------------------------
-version: 2.39
+version: 2.56
-- [obsolete] Quantize.decTest has the improved version
@@ -379,7 +379,7 @@
resx446 rescale 0.000999 1 -> 0E+1 Inexact Rounded
precision: 8
-resx449 rescale 9.999E-15 -23 -> NaN Invalid_operation
+resx449 rescale 9.999E-15 -23 -> NaN Invalid_operation
resx450 rescale 9.999E-15 -22 -> 9.9990000E-15
resx451 rescale 9.999E-15 -21 -> 9.999000E-15
resx452 rescale 9.999E-15 -20 -> 9.99900E-15
@@ -405,6 +405,12 @@
resx472 rescale 9.999E-15 0 -> 0 Inexact Rounded
resx473 rescale 9.999E-15 1 -> 0E+1 Inexact Rounded
+-- [additional tests for "don't fit" edge cases are in
+-- quantize.decTest. Here's a critical one.]
+precision: 3
+resx480 rescale 0.9999 -3 -> NaN Invalid_operation
+
+
-- long operand checks [rhs checks removed]
maxexponent: 999
minexponent: -999
Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/rounding.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/rounding.decTest (original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/rounding.decTest Fri Sep 21 03:17:09 2007
@@ -1,6 +1,6 @@
------------------------------------------------------------------------
-- rounding.decTest -- decimal rounding modes testcases --
--- Copyright (c) IBM Corporation, 1981, 2003. All rights reserved. --
+-- Copyright (c) IBM Corporation, 1981, 2007. All rights reserved. --
------------------------------------------------------------------------
-- Please see the document "General Decimal Arithmetic Testcases" --
-- at http://www2.hursley.ibm.com/decimal for the description of --
@@ -17,7 +17,7 @@
-- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
-- mfc at uk.ibm.com --
------------------------------------------------------------------------
-version: 2.39
+version: 2.56
-- These tests require that implementations take account of residues in
-- order to get correct results for some rounding modes. Rather than
@@ -26,8 +26,11 @@
-- is rounding of negatives (if the latter works for addition, assume it
-- works for the others, too).]
--
--- Underflow Subnormal and overflow behaviours are tested under the individual
--- operators.
+-- Round-for-reround (05UP) is tested as a separate block, mostly for
+-- 'historical' reasons.
+--
+-- Underflow Subnormal and overflow behaviours are tested under the
+-- individual operators.
extended: 1
precision: 5 -- for easier visual inspection
@@ -980,8 +983,8 @@
rounding: down
rovx100 multiply 10 9E+999999999 -> 9.9999E+999999999 Overflow Inexact Rounded
rovx101 multiply -10 9E+999999999 -> -9.9999E+999999999 Overflow Inexact Rounded
-rovx102 divide 1E-9 9E+999999999 -> 0E-1000000003 Underflow Subnormal Inexact Rounded
-rovx104 divide -1E-9 9E+999999999 -> -0E-1000000003 Underflow Subnormal Inexact Rounded
+rovx102 divide 1E-9 9E+999999999 -> 0E-1000000003 Underflow Subnormal Inexact Rounded Clamped
+rovx104 divide -1E-9 9E+999999999 -> -0E-1000000003 Underflow Subnormal Inexact Rounded Clamped
rounding: up
rovx110 multiply 10 9E+999999999 -> Infinity Overflow Inexact Rounded
@@ -993,31 +996,31 @@
rovx120 multiply 10 9E+999999999 -> Infinity Overflow Inexact Rounded
rovx121 multiply -10 9E+999999999 -> -9.9999E+999999999 Overflow Inexact Rounded
rovx122 divide 1E-9 9E+999999999 -> 1E-1000000003 Underflow Subnormal Inexact Rounded
-rovx124 divide -1E-9 9E+999999999 -> -0E-1000000003 Underflow Subnormal Inexact Rounded
+rovx124 divide -1E-9 9E+999999999 -> -0E-1000000003 Underflow Subnormal Inexact Rounded Clamped
rounding: floor
rovx130 multiply 10 9E+999999999 -> 9.9999E+999999999 Overflow Inexact Rounded
rovx131 multiply -10 9E+999999999 -> -Infinity Overflow Inexact Rounded
-rovx132 divide 1E-9 9E+999999999 -> 0E-1000000003 Underflow Subnormal Inexact Rounded
+rovx132 divide 1E-9 9E+999999999 -> 0E-1000000003 Underflow Subnormal Inexact Rounded Clamped
rovx134 divide -1E-9 9E+999999999 -> -1E-1000000003 Underflow Subnormal Inexact Rounded
rounding: half_up
rovx140 multiply 10 9E+999999999 -> Infinity Overflow Inexact Rounded
rovx141 multiply -10 9E+999999999 -> -Infinity Overflow Inexact Rounded
-rovx142 divide 1E-9 9E+999999999 -> 0E-1000000003 Underflow Subnormal Inexact Rounded
-rovx144 divide -1E-9 9E+999999999 -> -0E-1000000003 Underflow Subnormal Inexact Rounded
+rovx142 divide 1E-9 9E+999999999 -> 0E-1000000003 Underflow Subnormal Inexact Rounded Clamped
+rovx144 divide -1E-9 9E+999999999 -> -0E-1000000003 Underflow Subnormal Inexact Rounded Clamped
rounding: half_even
rovx150 multiply 10 9E+999999999 -> Infinity Overflow Inexact Rounded
rovx151 multiply -10 9E+999999999 -> -Infinity Overflow Inexact Rounded
-rovx152 divide 1E-9 9E+999999999 -> 0E-1000000003 Underflow Subnormal Inexact Rounded
-rovx154 divide -1E-9 9E+999999999 -> -0E-1000000003 Underflow Subnormal Inexact Rounded
+rovx152 divide 1E-9 9E+999999999 -> 0E-1000000003 Underflow Subnormal Inexact Rounded Clamped
+rovx154 divide -1E-9 9E+999999999 -> -0E-1000000003 Underflow Subnormal Inexact Rounded Clamped
rounding: half_down
rovx160 multiply 10 9E+999999999 -> Infinity Overflow Inexact Rounded
rovx161 multiply -10 9E+999999999 -> -Infinity Overflow Inexact Rounded
-rovx162 divide 1E-9 9E+999999999 -> 0E-1000000003 Underflow Subnormal Inexact Rounded
-rovx164 divide -1E-9 9E+999999999 -> -0E-1000000003 Underflow Subnormal Inexact Rounded
+rovx162 divide 1E-9 9E+999999999 -> 0E-1000000003 Underflow Subnormal Inexact Rounded Clamped
+rovx164 divide -1E-9 9E+999999999 -> -0E-1000000003 Underflow Subnormal Inexact Rounded Clamped
-- check maximum finite value over a range of precisions
rounding: down
@@ -1077,3 +1080,224 @@
rmex412 multiply -9.999E+999999999 10 -> -9.99999999E+999999999 Overflow Inexact Rounded
rmex413 multiply 9.999E+999999999 10 -> 9.99999999E+999999999 Overflow Inexact Rounded
+----- Round-for-reround -----
+rounding: 05up
+precision: 5 -- for easier visual inspection
+maxExponent: 999
+minexponent: -999
+
+-- basic rounding; really is just 0 and 5 up
+r05up001 add 12340 0.001 -> 12341 Inexact Rounded
+r05up002 add 12341 0.001 -> 12341 Inexact Rounded
+r05up003 add 12342 0.001 -> 12342 Inexact Rounded
+r05up004 add 12343 0.001 -> 12343 Inexact Rounded
+r05up005 add 12344 0.001 -> 12344 Inexact Rounded
+r05up006 add 12345 0.001 -> 12346 Inexact Rounded
+r05up007 add 12346 0.001 -> 12346 Inexact Rounded
+r05up008 add 12347 0.001 -> 12347 Inexact Rounded
+r05up009 add 12348 0.001 -> 12348 Inexact Rounded
+r05up010 add 12349 0.001 -> 12349 Inexact Rounded
+
+r05up011 add 12340 0.000 -> 12340 Rounded
+r05up012 add 12341 0.000 -> 12341 Rounded
+r05up013 add 12342 0.000 -> 12342 Rounded
+r05up014 add 12343 0.000 -> 12343 Rounded
+r05up015 add 12344 0.000 -> 12344 Rounded
+r05up016 add 12345 0.000 -> 12345 Rounded
+r05up017 add 12346 0.000 -> 12346 Rounded
+r05up018 add 12347 0.000 -> 12347 Rounded
+r05up019 add 12348 0.000 -> 12348 Rounded
+r05up020 add 12349 0.000 -> 12349 Rounded
+
+r05up021 add 12340 0.901 -> 12341 Inexact Rounded
+r05up022 add 12341 0.901 -> 12341 Inexact Rounded
+r05up023 add 12342 0.901 -> 12342 Inexact Rounded
+r05up024 add 12343 0.901 -> 12343 Inexact Rounded
+r05up025 add 12344 0.901 -> 12344 Inexact Rounded
+r05up026 add 12345 0.901 -> 12346 Inexact Rounded
+r05up027 add 12346 0.901 -> 12346 Inexact Rounded
+r05up028 add 12347 0.901 -> 12347 Inexact Rounded
+r05up029 add 12348 0.901 -> 12348 Inexact Rounded
+r05up030 add 12349 0.901 -> 12349 Inexact Rounded
+
+r05up031 add -12340 -0.001 -> -12341 Inexact Rounded
+r05up032 add -12341 -0.001 -> -12341 Inexact Rounded
+r05up033 add -12342 -0.001 -> -12342 Inexact Rounded
+r05up034 add -12343 -0.001 -> -12343 Inexact Rounded
+r05up035 add -12344 -0.001 -> -12344 Inexact Rounded
+r05up036 add -12345 -0.001 -> -12346 Inexact Rounded
+r05up037 add -12346 -0.001 -> -12346 Inexact Rounded
+r05up038 add -12347 -0.001 -> -12347 Inexact Rounded
+r05up039 add -12348 -0.001 -> -12348 Inexact Rounded
+r05up040 add -12349 -0.001 -> -12349 Inexact Rounded
+
+r05up041 add -12340 0.001 -> -12339 Inexact Rounded
+r05up042 add -12341 0.001 -> -12341 Inexact Rounded
+r05up043 add -12342 0.001 -> -12341 Inexact Rounded
+r05up044 add -12343 0.001 -> -12342 Inexact Rounded
+r05up045 add -12344 0.001 -> -12343 Inexact Rounded
+r05up046 add -12345 0.001 -> -12344 Inexact Rounded
+r05up047 add -12346 0.001 -> -12346 Inexact Rounded
+r05up048 add -12347 0.001 -> -12346 Inexact Rounded
+r05up049 add -12348 0.001 -> -12347 Inexact Rounded
+r05up050 add -12349 0.001 -> -12348 Inexact Rounded
+
+-- Addition operators -------------------------------------------------
+-- [The first few of these check negative residue possibilities; these
+-- cases may be implemented as a negative residue in fastpaths]
+
+r0adx100 add 12345 -0.1 -> 12344 Inexact Rounded
+r0adx101 add 12345 -0.01 -> 12344 Inexact Rounded
+r0adx102 add 12345 -0.001 -> 12344 Inexact Rounded
+r0adx103 add 12345 -0.00001 -> 12344 Inexact Rounded
+r0adx104 add 12345 -0.000001 -> 12344 Inexact Rounded
+r0adx105 add 12345 -0.0000001 -> 12344 Inexact Rounded
+r0adx106 add 12345 0 -> 12345
+r0adx107 add 12345 0.0000001 -> 12346 Inexact Rounded
+r0adx108 add 12345 0.000001 -> 12346 Inexact Rounded
+r0adx109 add 12345 0.00001 -> 12346 Inexact Rounded
+r0adx110 add 12345 0.0001 -> 12346 Inexact Rounded
+r0adx111 add 12345 0.001 -> 12346 Inexact Rounded
+r0adx112 add 12345 0.01 -> 12346 Inexact Rounded
+r0adx113 add 12345 0.1 -> 12346 Inexact Rounded
+
+r0adx115 add 12346 0.49999 -> 12346 Inexact Rounded
+r0adx116 add 12346 0.5 -> 12346 Inexact Rounded
+r0adx117 add 12346 0.50001 -> 12346 Inexact Rounded
+
+r0adx120 add 12345 0.4 -> 12346 Inexact Rounded
+r0adx121 add 12345 0.49 -> 12346 Inexact Rounded
+r0adx122 add 12345 0.499 -> 12346 Inexact Rounded
+r0adx123 add 12345 0.49999 -> 12346 Inexact Rounded
+r0adx124 add 12345 0.5 -> 12346 Inexact Rounded
+r0adx125 add 12345 0.50001 -> 12346 Inexact Rounded
+r0adx126 add 12345 0.5001 -> 12346 Inexact Rounded
+r0adx127 add 12345 0.501 -> 12346 Inexact Rounded
+r0adx128 add 12345 0.51 -> 12346 Inexact Rounded
+r0adx129 add 12345 0.6 -> 12346 Inexact Rounded
+
+-- negatives...
+
+r0sux100 add -12345 -0.1 -> -12346 Inexact Rounded
+r0sux101 add -12345 -0.01 -> -12346 Inexact Rounded
+r0sux102 add -12345 -0.001 -> -12346 Inexact Rounded
+r0sux103 add -12345 -0.00001 -> -12346 Inexact Rounded
+r0sux104 add -12345 -0.000001 -> -12346 Inexact Rounded
+r0sux105 add -12345 -0.0000001 -> -12346 Inexact Rounded
+r0sux106 add -12345 0 -> -12345
+r0sux107 add -12345 0.0000001 -> -12344 Inexact Rounded
+r0sux108 add -12345 0.000001 -> -12344 Inexact Rounded
+r0sux109 add -12345 0.00001 -> -12344 Inexact Rounded
+r0sux110 add -12345 0.0001 -> -12344 Inexact Rounded
+r0sux111 add -12345 0.001 -> -12344 Inexact Rounded
+r0sux112 add -12345 0.01 -> -12344 Inexact Rounded
+r0sux113 add -12345 0.1 -> -12344 Inexact Rounded
+
+r0sux115 add -12346 0.49999 -> -12346 Inexact Rounded
+r0sux116 add -12346 0.5 -> -12346 Inexact Rounded
+r0sux117 add -12346 0.50001 -> -12346 Inexact Rounded
+
+r0sux120 add -12345 0.4 -> -12344 Inexact Rounded
+r0sux121 add -12345 0.49 -> -12344 Inexact Rounded
+r0sux122 add -12345 0.499 -> -12344 Inexact Rounded
+r0sux123 add -12345 0.49999 -> -12344 Inexact Rounded
+r0sux124 add -12345 0.5 -> -12344 Inexact Rounded
+r0sux125 add -12345 0.50001 -> -12344 Inexact Rounded
+r0sux126 add -12345 0.5001 -> -12344 Inexact Rounded
+r0sux127 add -12345 0.501 -> -12344 Inexact Rounded
+r0sux128 add -12345 0.51 -> -12344 Inexact Rounded
+r0sux129 add -12345 0.6 -> -12344 Inexact Rounded
+
+-- Check cancellation subtractions
+-- (The IEEE 854 'curious rule' in $6.3)
+
+r0zex001 add 0 0 -> 0
+r0zex002 add 0 -0 -> 0
+r0zex003 add -0 0 -> 0
+r0zex004 add -0 -0 -> -0
+r0zex005 add 1 -1 -> 0
+r0zex006 add -1 1 -> 0
+r0zex007 add 1.5 -1.5 -> 0.0
+r0zex008 add -1.5 1.5 -> 0.0
+r0zex009 add 2 -2 -> 0
+r0zex010 add -2 2 -> 0
+
+
+-- Division operators -------------------------------------------------
+
+r0dvx101 divide 12345 1 -> 12345
+r0dvx102 divide 12345 1.0001 -> 12343 Inexact Rounded
+r0dvx103 divide 12345 1.001 -> 12332 Inexact Rounded
+r0dvx104 divide 12345 1.01 -> 12222 Inexact Rounded
+r0dvx105 divide 12345 1.1 -> 11222 Inexact Rounded
+r0dvx106 divide 12355 4 -> 3088.7 Inexact Rounded
+r0dvx107 divide 12345 4 -> 3086.2 Inexact Rounded
+r0dvx108 divide 12355 4.0001 -> 3088.6 Inexact Rounded
+r0dvx109 divide 12345 4.0001 -> 3086.1 Inexact Rounded
+r0dvx110 divide 12345 4.9 -> 2519.3 Inexact Rounded
+r0dvx111 divide 12345 4.99 -> 2473.9 Inexact Rounded
+r0dvx112 divide 12345 4.999 -> 2469.4 Inexact Rounded
+r0dvx113 divide 12345 4.9999 -> 2469.1 Inexact Rounded
+r0dvx114 divide 12345 5 -> 2469
+r0dvx115 divide 12345 5.0001 -> 2468.9 Inexact Rounded
+r0dvx116 divide 12345 5.001 -> 2468.6 Inexact Rounded
+r0dvx117 divide 12345 5.01 -> 2464.1 Inexact Rounded
+r0dvx118 divide 12345 5.1 -> 2420.6 Inexact Rounded
+
+-- [divideInteger and remainder unaffected]
+
+-- Multiplication operator --------------------------------------------
+
+r0mux101 multiply 12345 1 -> 12345
+r0mux102 multiply 12345 1.0001 -> 12346 Inexact Rounded
+r0mux103 multiply 12345 1.001 -> 12357 Inexact Rounded
+r0mux104 multiply 12345 1.01 -> 12468 Inexact Rounded
+r0mux105 multiply 12345 1.1 -> 13579 Inexact Rounded
+r0mux106 multiply 12345 4 -> 49380
+r0mux107 multiply 12345 4.0001 -> 49381 Inexact Rounded
+r0mux108 multiply 12345 4.9 -> 60491 Inexact Rounded
+r0mux109 multiply 12345 4.99 -> 61601 Inexact Rounded
+r0mux110 multiply 12345 4.999 -> 61712 Inexact Rounded
+r0mux111 multiply 12345 4.9999 -> 61723 Inexact Rounded
+r0mux112 multiply 12345 5 -> 61725
+r0mux113 multiply 12345 5.0001 -> 61726 Inexact Rounded
+r0mux114 multiply 12345 5.001 -> 61737 Inexact Rounded
+r0mux115 multiply 12345 5.01 -> 61848 Inexact Rounded
+r0mux116 multiply 12345 12 -> 1.4814E+5 Rounded
+r0mux117 multiply 12345 13 -> 1.6048E+5 Inexact Rounded
+r0mux118 multiply 12355 12 -> 1.4826E+5 Rounded
+r0mux119 multiply 12355 13 -> 1.6061E+5 Inexact Rounded
+
+
+-- Power operator -----------------------------------------------------
+
+r0pox101 power 12345 -5 -> 3.4877E-21 Inexact Rounded
+r0pox102 power 12345 -4 -> 4.3056E-17 Inexact Rounded
+r0pox103 power 12345 -3 -> 5.3152E-13 Inexact Rounded
+r0pox104 power 12345 -2 -> 6.5617E-9 Inexact Rounded
+r0pox105 power 12345 -1 -> 0.000081004 Inexact Rounded
+r0pox106 power 12345 0 -> 1
+r0pox107 power 12345 1 -> 12345
+r0pox108 power 12345 2 -> 1.5239E+8 Inexact Rounded
+r0pox109 power 12345 3 -> 1.8813E+12 Inexact Rounded
+r0pox110 power 12345 4 -> 2.3226E+16 Inexact Rounded
+r0pox111 power 12345 5 -> 2.8671E+20 Inexact Rounded
+r0pox112 power 415 2 -> 1.7222E+5 Inexact Rounded
+r0pox113 power 75 3 -> 4.2187E+5 Inexact Rounded
+
+
+-- Underflow Subnormal and overflow values vary with rounding mode and sign
+maxexponent: 999999999
+minexponent: -999999999
+-- [round down gives Nmax on first two and .0E... on the next two]
+r0ovx100 multiply 10 9E+999999999 -> 9.9999E+999999999 Overflow Inexact Rounded
+r0ovx101 multiply -10 9E+999999999 -> -9.9999E+999999999 Overflow Inexact Rounded
+r0ovx102 divide 1E-9 9E+999999999 -> 1E-1000000003 Underflow Subnormal Inexact Rounded
+r0ovx104 divide -1E-9 9E+999999999 -> -1E-1000000003 Underflow Subnormal Inexact Rounded
+
+-- reprise rounding mode effect (using multiplies so precision directive used)
+precision: 9
+maxexponent: 999999999
+r0mex412 multiply -9.999E+999999999 10 -> -9.99999999E+999999999 Overflow Inexact Rounded
+r0mex413 multiply 9.999E+999999999 10 -> 9.99999999E+999999999 Overflow Inexact Rounded
+
Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/samequantum.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/samequantum.decTest (original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/samequantum.decTest Fri Sep 21 03:17:09 2007
@@ -1,6 +1,6 @@
------------------------------------------------------------------------
-- samequantum.decTest -- check quantums match --
--- Copyright (c) IBM Corporation, 2001, 2003. All rights reserved. --
+-- Copyright (c) IBM Corporation, 2001, 2007. All rights reserved. --
------------------------------------------------------------------------
-- Please see the document "General Decimal Arithmetic Testcases" --
-- at http://www2.hursley.ibm.com/decimal for the description of --
@@ -17,7 +17,7 @@
-- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
-- mfc at uk.ibm.com --
------------------------------------------------------------------------
-version: 2.39
+version: 2.56
extended: 1
precision: 9
@@ -64,8 +64,44 @@
samq048 samequantum -0E-17 -0.0E-16 -> 1
samq049 samequantum -0E-17 -0.0E-17 -> 0
--- specials & combinations
+-- Nmax, Nmin, Ntiny
+samq051 samequantum 9.99999999E+999 9.99999999E+999 -> 1
+samq052 samequantum 1E-999 1E-999 -> 1
+samq053 samequantum 1.00000000E-999 1.00000000E-999 -> 1
+samq054 samequantum 1E-1007 1E-1007 -> 1
+samq055 samequantum 9.99999999E+999 9.99999999E+999 -> 1
+samq056 samequantum 1E-999 1E-999 -> 1
+samq057 samequantum 1.00000000E-999 1.00000000E-999 -> 1
+samq058 samequantum 1E-1007 1E-1007 -> 1
+
+samq061 samequantum -1E-1007 -1E-1007 -> 1
+samq062 samequantum -1.00000000E-999 -1.00000000E-999 -> 1
+samq063 samequantum -1E-999 -1E-999 -> 1
+samq064 samequantum -9.99999999E+999 -9.99999999E+999 -> 1
+samq065 samequantum -1E-1007 -1E-1007 -> 1
+samq066 samequantum -1.00000000E-999 -1.00000000E-999 -> 1
+samq067 samequantum -1E-999 -1E-999 -> 1
+samq068 samequantum -9.99999999E+999 -9.99999999E+999 -> 1
+
+samq071 samequantum -4E-1007 -1E-1007 -> 1
+samq072 samequantum -4.00000000E-999 -1.00004000E-999 -> 1
+samq073 samequantum -4E-999 -1E-999 -> 1
+samq074 samequantum -4.99999999E+999 -9.99949999E+999 -> 1
+samq075 samequantum -4E-1007 -1E-1007 -> 1
+samq076 samequantum -4.00000000E-999 -1.00400000E-999 -> 1
+samq077 samequantum -4E-999 -1E-999 -> 1
+samq078 samequantum -4.99999999E+999 -9.94999999E+999 -> 1
+
+samq081 samequantum -4E-1006 -1E-1007 -> 0
+samq082 samequantum -4.00000000E-999 -1.00004000E-996 -> 0
+samq083 samequantum -4E-996 -1E-999 -> 0
+samq084 samequantum -4.99999999E+999 -9.99949999E+996 -> 0
+samq085 samequantum -4E-1006 -1E-1007 -> 0
+samq086 samequantum -4.00000000E-999 -1.00400000E-996 -> 0
+samq087 samequantum -4E-996 -1E-999 -> 0
+samq088 samequantum -4.99999999E+999 -9.94999999E+996 -> 0
+-- specials & combinations
samq0110 samequantum -Inf -Inf -> 1
samq0111 samequantum -Inf Inf -> 1
samq0112 samequantum -Inf NaN -> 0
Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/squareroot.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/squareroot.decTest (original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/squareroot.decTest Fri Sep 21 03:17:09 2007
@@ -1,6 +1,6 @@
------------------------------------------------------------------------
-- squareroot.decTest -- decimal square root --
--- Copyright (c) IBM Corporation, 2004. All rights reserved. --
+-- Copyright (c) IBM Corporation, 2003, 2007. All rights reserved. --
------------------------------------------------------------------------
-- Please see the document "General Decimal Arithmetic Testcases" --
-- at http://www2.hursley.ibm.com/decimal for the description of --
@@ -17,7 +17,7 @@
-- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
-- mfc at uk.ibm.com --
------------------------------------------------------------------------
-version: 2.39
+version: 2.56
extended: 1
precision: 9
@@ -102,6 +102,8 @@
sqtx075 squareroot -100.00 -> NaN Invalid_operation
sqtx076 squareroot -1.1000E+3 -> NaN Invalid_operation
sqtx077 squareroot -1.10000E+3 -> NaN Invalid_operation
+sqtx078 squareroot 1.000 -> 1.00
+sqtx079 squareroot 1.0000 -> 1.00
-- famous squares
sqtx080 squareroot 1 -> 1
@@ -2926,19 +2928,26 @@
precision: 11 -- Etiny=-19
sqtx804 squareroot 1E-19 -> 3.162277660E-10 Underflow Subnormal Inexact Rounded
-sqtx805 squareroot 10E-19 -> 1.0E-9
+sqtx805 squareroot 10E-19 -> 1.0E-9 -- exact
precision: 12 -- Etiny=-20
sqtx806 squareroot 10E-20 -> 3.1622776602E-10 Underflow Subnormal Inexact Rounded
-sqtx807 squareroot 1E-20 -> 1E-10 Subnormal -- Exact Subnormal case
+sqtx807 squareroot 1E-20 -> 1E-10 Subnormal -- exact Subnormal case
precision: 13 -- Etiny=-21
sqtx808 squareroot 1E-21 -> 3.1622776602E-11 Underflow Subnormal Inexact Rounded
-sqtx809 squareroot 10E-21 -> 1.0E-10 Subnormal
+sqtx809 squareroot 10E-21 -> 1.0E-10 Subnormal -- exact Subnormal case
precision: 14 -- Etiny=-22
sqtx810 squareroot 1E-21 -> 3.16227766017E-11 Underflow Subnormal Inexact Rounded
sqtx811 squareroot 10E-22 -> 3.16227766017E-11 Underflow Subnormal Inexact Rounded
-sqtx812 squareroot 1E-22 -> 1E-11 Subnormal -- Exact Subnormal case
+sqtx812 squareroot 1E-22 -> 1E-11 Subnormal -- exact Subnormal case
+-- Not enough digits?
+precision: 16
+maxExponent: 384
+minExponent: -383
+rounding: half_even
+sqtx815 squareroot 1.0000000001000000E-78 -> 1.000000000050000E-39 Inexact Rounded
+-- 1 234567890123456
-- special values
maxexponent: 999
@@ -2954,5 +2963,842 @@
sqtx827 squareroot -NaN654 -> -NaN654
sqtx828 squareroot NaN1 -> NaN1
+-- payload decapitate
+precision: 5
+sqtx840 squareroot -sNaN1234567890 -> -NaN67890 Invalid_operation
+
+------------------------------------------------------------------------
+--
+-- Special thanks to Mark Dickinson for tests in the range 8000-8999.
+--
+-- Extra tests for the square root function, dealing with a variety of
+-- corner cases. In particular, these tests concentrate on
+-- (1) cases where the input precision exceeds the context precision, and
+-- (2) cases where the input exponent is outside the current context,
+-- and in particular when the result is subnormal
+--
+-- maxexponent and minexponent are set to 9 and -9 for most of these
+-- cases; only the precision changes. The rounding also does not
+-- change, because it is ignored for this operation.
+maxexponent: 9
+minexponent: -9
+
+-- exact results, input precision > context precision
+precision: 1
+sqtx8000 squareroot 0 -> 0
+sqtx8001 squareroot 1 -> 1
+sqtx8002 squareroot 4 -> 2
+sqtx8003 squareroot 9 -> 3
+sqtx8004 squareroot 16 -> 4
+sqtx8005 squareroot 25 -> 5
+sqtx8006 squareroot 36 -> 6
+sqtx8007 squareroot 49 -> 7
+sqtx8008 squareroot 64 -> 8
+sqtx8009 squareroot 81 -> 9
+sqtx8010 squareroot 100 -> 1E+1 Rounded
+sqtx8011 squareroot 121 -> 1E+1 Inexact Rounded
+
+precision: 2
+sqtx8012 squareroot 0 -> 0
+sqtx8013 squareroot 1 -> 1
+sqtx8014 squareroot 4 -> 2
+sqtx8015 squareroot 9 -> 3
+sqtx8016 squareroot 16 -> 4
+sqtx8017 squareroot 25 -> 5
+sqtx8018 squareroot 36 -> 6
+sqtx8019 squareroot 49 -> 7
+sqtx8020 squareroot 64 -> 8
+sqtx8021 squareroot 81 -> 9
+sqtx8022 squareroot 100 -> 10
+sqtx8023 squareroot 121 -> 11
+sqtx8024 squareroot 144 -> 12
+sqtx8025 squareroot 169 -> 13
+sqtx8026 squareroot 196 -> 14
+sqtx8027 squareroot 225 -> 15
+sqtx8028 squareroot 256 -> 16
+sqtx8029 squareroot 289 -> 17
+sqtx8030 squareroot 324 -> 18
+sqtx8031 squareroot 361 -> 19
+sqtx8032 squareroot 400 -> 20
+sqtx8033 squareroot 441 -> 21
+sqtx8034 squareroot 484 -> 22
+sqtx8035 squareroot 529 -> 23
+sqtx8036 squareroot 576 -> 24
+sqtx8037 squareroot 625 -> 25
+sqtx8038 squareroot 676 -> 26
+sqtx8039 squareroot 729 -> 27
+sqtx8040 squareroot 784 -> 28
+sqtx8041 squareroot 841 -> 29
+sqtx8042 squareroot 900 -> 30
+sqtx8043 squareroot 961 -> 31
+sqtx8044 squareroot 1024 -> 32
+sqtx8045 squareroot 1089 -> 33
+sqtx8046 squareroot 1156 -> 34
+sqtx8047 squareroot 1225 -> 35
+sqtx8048 squareroot 1296 -> 36
+sqtx8049 squareroot 1369 -> 37
+sqtx8050 squareroot 1444 -> 38
+sqtx8051 squareroot 1521 -> 39
+sqtx8052 squareroot 1600 -> 40
+sqtx8053 squareroot 1681 -> 41
+sqtx8054 squareroot 1764 -> 42
+sqtx8055 squareroot 1849 -> 43
+sqtx8056 squareroot 1936 -> 44
+sqtx8057 squareroot 2025 -> 45
+sqtx8058 squareroot 2116 -> 46
+sqtx8059 squareroot 2209 -> 47
+sqtx8060 squareroot 2304 -> 48
+sqtx8061 squareroot 2401 -> 49
+sqtx8062 squareroot 2500 -> 50
+sqtx8063 squareroot 2601 -> 51
+sqtx8064 squareroot 2704 -> 52
+sqtx8065 squareroot 2809 -> 53
+sqtx8066 squareroot 2916 -> 54
+sqtx8067 squareroot 3025 -> 55
+sqtx8068 squareroot 3136 -> 56
+sqtx8069 squareroot 3249 -> 57
+sqtx8070 squareroot 3364 -> 58
+sqtx8071 squareroot 3481 -> 59
+sqtx8072 squareroot 3600 -> 60
+sqtx8073 squareroot 3721 -> 61
+sqtx8074 squareroot 3844 -> 62
+sqtx8075 squareroot 3969 -> 63
+sqtx8076 squareroot 4096 -> 64
+sqtx8077 squareroot 4225 -> 65
+sqtx8078 squareroot 4356 -> 66
+sqtx8079 squareroot 4489 -> 67
+sqtx8080 squareroot 4624 -> 68
+sqtx8081 squareroot 4761 -> 69
+sqtx8082 squareroot 4900 -> 70
+sqtx8083 squareroot 5041 -> 71
+sqtx8084 squareroot 5184 -> 72
+sqtx8085 squareroot 5329 -> 73
+sqtx8086 squareroot 5476 -> 74
+sqtx8087 squareroot 5625 -> 75
+sqtx8088 squareroot 5776 -> 76
+sqtx8089 squareroot 5929 -> 77
+sqtx8090 squareroot 6084 -> 78
+sqtx8091 squareroot 6241 -> 79
+sqtx8092 squareroot 6400 -> 80
+sqtx8093 squareroot 6561 -> 81
+sqtx8094 squareroot 6724 -> 82
+sqtx8095 squareroot 6889 -> 83
+sqtx8096 squareroot 7056 -> 84
+sqtx8097 squareroot 7225 -> 85
+sqtx8098 squareroot 7396 -> 86
+sqtx8099 squareroot 7569 -> 87
+sqtx8100 squareroot 7744 -> 88
+sqtx8101 squareroot 7921 -> 89
+sqtx8102 squareroot 8100 -> 90
+sqtx8103 squareroot 8281 -> 91
+sqtx8104 squareroot 8464 -> 92
+sqtx8105 squareroot 8649 -> 93
+sqtx8106 squareroot 8836 -> 94
+sqtx8107 squareroot 9025 -> 95
+sqtx8108 squareroot 9216 -> 96
+sqtx8109 squareroot 9409 -> 97
+sqtx8110 squareroot 9604 -> 98
+sqtx8111 squareroot 9801 -> 99
+sqtx8112 squareroot 10000 -> 1.0E+2 Rounded
+sqtx8113 squareroot 10201 -> 1.0E+2 Inexact Rounded
+
+precision: 3
+sqtx8114 squareroot 841 -> 29
+sqtx8115 squareroot 1600 -> 40
+sqtx8116 squareroot 2209 -> 47
+sqtx8117 squareroot 9604 -> 98
+sqtx8118 squareroot 21316 -> 146
+sqtx8119 squareroot 52441 -> 229
+sqtx8120 squareroot 68644 -> 262
+sqtx8121 squareroot 69696 -> 264
+sqtx8122 squareroot 70225 -> 265
+sqtx8123 squareroot 76729 -> 277
+sqtx8124 squareroot 130321 -> 361
+sqtx8125 squareroot 171396 -> 414
+sqtx8126 squareroot 270400 -> 520
+sqtx8127 squareroot 279841 -> 529
+sqtx8128 squareroot 407044 -> 638
+sqtx8129 squareroot 408321 -> 639
+sqtx8130 squareroot 480249 -> 693
+sqtx8131 squareroot 516961 -> 719
+sqtx8132 squareroot 692224 -> 832
+sqtx8133 squareroot 829921 -> 911
+
+-- selection of random exact results
+precision: 6
+sqtx8134 squareroot 2.25E-12 -> 0.0000015
+sqtx8135 squareroot 8.41E-14 -> 2.9E-7
+sqtx8136 squareroot 6.241E-15 -> 7.9E-8
+sqtx8137 squareroot 5.041E+13 -> 7.1E+6
+sqtx8138 squareroot 4761 -> 69
+sqtx8139 squareroot 1.369E+17 -> 3.7E+8
+sqtx8140 squareroot 0.00002116 -> 0.0046
+sqtx8141 squareroot 7.29E+4 -> 2.7E+2
+sqtx8142 squareroot 4.624E-13 -> 6.8E-7
+sqtx8143 squareroot 3.969E+5 -> 6.3E+2
+sqtx8144 squareroot 3.73321E-11 -> 0.00000611
+sqtx8145 squareroot 5.61001E+17 -> 7.49E+8
+sqtx8146 squareroot 2.30400E-11 -> 0.00000480
+sqtx8147 squareroot 4.30336E+17 -> 6.56E+8
+sqtx8148 squareroot 0.057121 -> 0.239
+sqtx8149 squareroot 7.225E+17 -> 8.5E+8
+sqtx8150 squareroot 3.14721E+13 -> 5.61E+6
+sqtx8151 squareroot 4.61041E+17 -> 6.79E+8
+sqtx8152 squareroot 1.39876E-15 -> 3.74E-8
+sqtx8153 squareroot 6.19369E-9 -> 0.0000787
+sqtx8154 squareroot 1.620529E-10 -> 0.00001273
+sqtx8155 squareroot 1177.1761 -> 34.31
+sqtx8156 squareroot 67043344 -> 8188
+sqtx8157 squareroot 4.84E+6 -> 2.2E+3
+sqtx8158 squareroot 1.23904E+11 -> 3.52E+5
+sqtx8159 squareroot 32604100 -> 5710
+sqtx8160 squareroot 2.9757025E-11 -> 0.000005455
+sqtx8161 squareroot 6.3760225E-9 -> 0.00007985
+sqtx8162 squareroot 4.5198729E-11 -> 0.000006723
+sqtx8163 squareroot 1.4745600E-11 -> 0.000003840
+sqtx8164 squareroot 18964283.04 -> 4354.8
+sqtx8165 squareroot 3.308895529E+13 -> 5.7523E+6
+sqtx8166 squareroot 0.0028590409 -> 0.05347
+sqtx8167 squareroot 3572.213824 -> 59.768
+sqtx8168 squareroot 4.274021376E+15 -> 6.5376E+7
+sqtx8169 squareroot 4455476.64 -> 2110.8
+sqtx8170 squareroot 38.44 -> 6.2
+sqtx8171 squareroot 68.558400 -> 8.280
+sqtx8172 squareroot 715402009 -> 26747
+sqtx8173 squareroot 93.373569 -> 9.663
+sqtx8174 squareroot 2.62144000000E+15 -> 5.12000E+7
+sqtx8175 squareroot 7.48225000000E+15 -> 8.65000E+7
+sqtx8176 squareroot 3.38724000000E-9 -> 0.0000582000
+sqtx8177 squareroot 5.64001000000E-13 -> 7.51000E-7
+sqtx8178 squareroot 5.06944000000E-15 -> 7.12000E-8
+sqtx8179 squareroot 4.95616000000E+17 -> 7.04000E+8
+sqtx8180 squareroot 0.0000242064000000 -> 0.00492000
+sqtx8181 squareroot 1.48996000000E-15 -> 3.86000E-8
+sqtx8182 squareroot 9.37024000000E+17 -> 9.68000E+8
+sqtx8183 squareroot 7128900.0000 -> 2670.00
+sqtx8184 squareroot 8.2311610000E-10 -> 0.0000286900
+sqtx8185 squareroot 482747040000 -> 694800
+sqtx8186 squareroot 4.14478440000E+17 -> 6.43800E+8
+sqtx8187 squareroot 5.10510250000E-7 -> 0.000714500
+sqtx8188 squareroot 355096.810000 -> 595.900
+sqtx8189 squareroot 14288400.0000 -> 3780.00
+sqtx8190 squareroot 3.36168040000E-15 -> 5.79800E-8
+sqtx8191 squareroot 1.70899560000E-13 -> 4.13400E-7
+sqtx8192 squareroot 0.0000378348010000 -> 0.00615100
+sqtx8193 squareroot 2.00972890000E-13 -> 4.48300E-7
+sqtx8194 squareroot 4.07222659600E-13 -> 6.38140E-7
+sqtx8195 squareroot 131486012100 -> 362610
+sqtx8196 squareroot 818192611600 -> 904540
+sqtx8197 squareroot 9.8558323600E+16 -> 3.13940E+8
+sqtx8198 squareroot 5641.06144900 -> 75.1070
+sqtx8199 squareroot 4.58789475600E+17 -> 6.77340E+8
+sqtx8200 squareroot 3.21386948100E-9 -> 0.0000566910
+sqtx8201 squareroot 3.9441960000E-8 -> 0.000198600
+sqtx8202 squareroot 242723.728900 -> 492.670
+sqtx8203 squareroot 1874.89000000 -> 43.3000
+sqtx8204 squareroot 2.56722595684E+15 -> 5.06678E+7
+sqtx8205 squareroot 3.96437714689E-17 -> 6.29633E-9
+sqtx8206 squareroot 3.80106774784E-17 -> 6.16528E-9
+sqtx8207 squareroot 1.42403588496E-13 -> 3.77364E-7
+sqtx8208 squareroot 4604.84388100 -> 67.8590
+sqtx8209 squareroot 2157100869.16 -> 46444.6
+sqtx8210 squareroot 355288570.81 -> 18849.1
+sqtx8211 squareroot 4.69775901604E-11 -> 0.00000685402
+sqtx8212 squareroot 8.22115770436E+17 -> 9.06706E+8
+sqtx8213 squareroot 7.16443744900E+15 -> 8.46430E+7
+sqtx8214 squareroot 9.48995498896E+15 -> 9.74164E+7
+sqtx8215 squareroot 0.0000419091801129 -> 0.00647373
+sqtx8216 squareroot 5862627996.84 -> 76567.8
+sqtx8217 squareroot 9369537.3409 -> 3060.97
+sqtx8218 squareroot 7.74792529729E+17 -> 8.80223E+8
+sqtx8219 squareroot 1.08626931396E+17 -> 3.29586E+8
+sqtx8220 squareroot 8.89584739684E-7 -> 0.000943178
+sqtx8221 squareroot 4.0266040896E-18 -> 2.00664E-9
+sqtx8222 squareroot 9.27669480336E-7 -> 0.000963156
+sqtx8223 squareroot 0.00225497717956 -> 0.0474866
+
+-- test use of round-half-even for ties
+precision: 1
+sqtx8224 squareroot 225 -> 2E+1 Inexact Rounded
+sqtx8225 squareroot 625 -> 2E+1 Inexact Rounded
+sqtx8226 squareroot 1225 -> 4E+1 Inexact Rounded
+sqtx8227 squareroot 2025 -> 4E+1 Inexact Rounded
+sqtx8228 squareroot 3025 -> 6E+1 Inexact Rounded
+sqtx8229 squareroot 4225 -> 6E+1 Inexact Rounded
+sqtx8230 squareroot 5625 -> 8E+1 Inexact Rounded
+sqtx8231 squareroot 7225 -> 8E+1 Inexact Rounded
+sqtx8232 squareroot 9025 -> 1E+2 Inexact Rounded
+
+precision: 2
+sqtx8233 squareroot 11025 -> 1.0E+2 Inexact Rounded
+sqtx8234 squareroot 13225 -> 1.2E+2 Inexact Rounded
+sqtx8235 squareroot 15625 -> 1.2E+2 Inexact Rounded
+sqtx8236 squareroot 18225 -> 1.4E+2 Inexact Rounded
+sqtx8237 squareroot 21025 -> 1.4E+2 Inexact Rounded
+sqtx8238 squareroot 24025 -> 1.6E+2 Inexact Rounded
+sqtx8239 squareroot 27225 -> 1.6E+2 Inexact Rounded
+sqtx8240 squareroot 30625 -> 1.8E+2 Inexact Rounded
+sqtx8241 squareroot 34225 -> 1.8E+2 Inexact Rounded
+sqtx8242 squareroot 38025 -> 2.0E+2 Inexact Rounded
+sqtx8243 squareroot 42025 -> 2.0E+2 Inexact Rounded
+sqtx8244 squareroot 46225 -> 2.2E+2 Inexact Rounded
+sqtx8245 squareroot 50625 -> 2.2E+2 Inexact Rounded
+sqtx8246 squareroot 55225 -> 2.4E+2 Inexact Rounded
+sqtx8247 squareroot 60025 -> 2.4E+2 Inexact Rounded
+sqtx8248 squareroot 65025 -> 2.6E+2 Inexact Rounded
+sqtx8249 squareroot 70225 -> 2.6E+2 Inexact Rounded
+sqtx8250 squareroot 75625 -> 2.8E+2 Inexact Rounded
+sqtx8251 squareroot 81225 -> 2.8E+2 Inexact Rounded
+sqtx8252 squareroot 87025 -> 3.0E+2 Inexact Rounded
+sqtx8253 squareroot 93025 -> 3.0E+2 Inexact Rounded
+sqtx8254 squareroot 99225 -> 3.2E+2 Inexact Rounded
+sqtx8255 squareroot 105625 -> 3.2E+2 Inexact Rounded
+sqtx8256 squareroot 112225 -> 3.4E+2 Inexact Rounded
+sqtx8257 squareroot 119025 -> 3.4E+2 Inexact Rounded
+sqtx8258 squareroot 126025 -> 3.6E+2 Inexact Rounded
+sqtx8259 squareroot 133225 -> 3.6E+2 Inexact Rounded
+sqtx8260 squareroot 140625 -> 3.8E+2 Inexact Rounded
+sqtx8261 squareroot 148225 -> 3.8E+2 Inexact Rounded
+sqtx8262 squareroot 156025 -> 4.0E+2 Inexact Rounded
+sqtx8263 squareroot 164025 -> 4.0E+2 Inexact Rounded
+sqtx8264 squareroot 172225 -> 4.2E+2 Inexact Rounded
+sqtx8265 squareroot 180625 -> 4.2E+2 Inexact Rounded
+sqtx8266 squareroot 189225 -> 4.4E+2 Inexact Rounded
+sqtx8267 squareroot 198025 -> 4.4E+2 Inexact Rounded
+sqtx8268 squareroot 207025 -> 4.6E+2 Inexact Rounded
+sqtx8269 squareroot 216225 -> 4.6E+2 Inexact Rounded
+sqtx8270 squareroot 225625 -> 4.8E+2 Inexact Rounded
+sqtx8271 squareroot 235225 -> 4.8E+2 Inexact Rounded
+sqtx8272 squareroot 245025 -> 5.0E+2 Inexact Rounded
+sqtx8273 squareroot 255025 -> 5.0E+2 Inexact Rounded
+sqtx8274 squareroot 265225 -> 5.2E+2 Inexact Rounded
+sqtx8275 squareroot 275625 -> 5.2E+2 Inexact Rounded
+sqtx8276 squareroot 286225 -> 5.4E+2 Inexact Rounded
+sqtx8277 squareroot 297025 -> 5.4E+2 Inexact Rounded
+sqtx8278 squareroot 308025 -> 5.6E+2 Inexact Rounded
+sqtx8279 squareroot 319225 -> 5.6E+2 Inexact Rounded
+sqtx8280 squareroot 330625 -> 5.8E+2 Inexact Rounded
+sqtx8281 squareroot 342225 -> 5.8E+2 Inexact Rounded
+sqtx8282 squareroot 354025 -> 6.0E+2 Inexact Rounded
+sqtx8283 squareroot 366025 -> 6.0E+2 Inexact Rounded
+sqtx8284 squareroot 378225 -> 6.2E+2 Inexact Rounded
+sqtx8285 squareroot 390625 -> 6.2E+2 Inexact Rounded
+sqtx8286 squareroot 403225 -> 6.4E+2 Inexact Rounded
+sqtx8287 squareroot 416025 -> 6.4E+2 Inexact Rounded
+sqtx8288 squareroot 429025 -> 6.6E+2 Inexact Rounded
+sqtx8289 squareroot 442225 -> 6.6E+2 Inexact Rounded
+sqtx8290 squareroot 455625 -> 6.8E+2 Inexact Rounded
+sqtx8291 squareroot 469225 -> 6.8E+2 Inexact Rounded
+sqtx8292 squareroot 483025 -> 7.0E+2 Inexact Rounded
+sqtx8293 squareroot 497025 -> 7.0E+2 Inexact Rounded
+sqtx8294 squareroot 511225 -> 7.2E+2 Inexact Rounded
+sqtx8295 squareroot 525625 -> 7.2E+2 Inexact Rounded
+sqtx8296 squareroot 540225 -> 7.4E+2 Inexact Rounded
+sqtx8297 squareroot 555025 -> 7.4E+2 Inexact Rounded
+sqtx8298 squareroot 570025 -> 7.6E+2 Inexact Rounded
+sqtx8299 squareroot 585225 -> 7.6E+2 Inexact Rounded
+sqtx8300 squareroot 600625 -> 7.8E+2 Inexact Rounded
+sqtx8301 squareroot 616225 -> 7.8E+2 Inexact Rounded
+sqtx8302 squareroot 632025 -> 8.0E+2 Inexact Rounded
+sqtx8303 squareroot 648025 -> 8.0E+2 Inexact Rounded
+sqtx8304 squareroot 664225 -> 8.2E+2 Inexact Rounded
+sqtx8305 squareroot 680625 -> 8.2E+2 Inexact Rounded
+sqtx8306 squareroot 697225 -> 8.4E+2 Inexact Rounded
+sqtx8307 squareroot 714025 -> 8.4E+2 Inexact Rounded
+sqtx8308 squareroot 731025 -> 8.6E+2 Inexact Rounded
+sqtx8309 squareroot 748225 -> 8.6E+2 Inexact Rounded
+sqtx8310 squareroot 765625 -> 8.8E+2 Inexact Rounded
+sqtx8311 squareroot 783225 -> 8.8E+2 Inexact Rounded
+sqtx8312 squareroot 801025 -> 9.0E+2 Inexact Rounded
+sqtx8313 squareroot 819025 -> 9.0E+2 Inexact Rounded
+sqtx8314 squareroot 837225 -> 9.2E+2 Inexact Rounded
+sqtx8315 squareroot 855625 -> 9.2E+2 Inexact Rounded
+sqtx8316 squareroot 874225 -> 9.4E+2 Inexact Rounded
+sqtx8317 squareroot 893025 -> 9.4E+2 Inexact Rounded
+sqtx8318 squareroot 912025 -> 9.6E+2 Inexact Rounded
+sqtx8319 squareroot 931225 -> 9.6E+2 Inexact Rounded
+sqtx8320 squareroot 950625 -> 9.8E+2 Inexact Rounded
+sqtx8321 squareroot 970225 -> 9.8E+2 Inexact Rounded
+sqtx8322 squareroot 990025 -> 1.0E+3 Inexact Rounded
+
+precision: 6
+sqtx8323 squareroot 88975734963025 -> 9.43270E+6 Inexact Rounded
+sqtx8324 squareroot 71085555000625 -> 8.43122E+6 Inexact Rounded
+sqtx8325 squareroot 39994304.051025 -> 6324.10 Inexact Rounded
+sqtx8326 squareroot 0.000007327172265625 -> 0.00270688 Inexact Rounded
+sqtx8327 squareroot 1.0258600439025E-13 -> 3.20290E-7 Inexact Rounded
+sqtx8328 squareroot 0.0034580574275625 -> 0.0588052 Inexact Rounded
+sqtx8329 squareroot 7.6842317700625E-7 -> 0.000876598 Inexact Rounded
+sqtx8330 squareroot 1263834495.2025 -> 35550.4 Inexact Rounded
+sqtx8331 squareroot 433970666460.25 -> 658764 Inexact Rounded
+sqtx8332 squareroot 4.5879286230625E-7 -> 0.000677342 Inexact Rounded
+sqtx8333 squareroot 0.0029305603306225 -> 0.0541346 Inexact Rounded
+sqtx8334 squareroot 70218282.733225 -> 8379.64 Inexact Rounded
+sqtx8335 squareroot 11942519.082025 -> 3455.80 Inexact Rounded
+sqtx8336 squareroot 0.0021230668905625 -> 0.0460768 Inexact Rounded
+sqtx8337 squareroot 0.90081833411025 -> 0.949114 Inexact Rounded
+sqtx8338 squareroot 5.5104120936225E-17 -> 7.42322E-9 Inexact Rounded
+sqtx8339 squareroot 0.10530446854225 -> 0.324506 Inexact Rounded
+sqtx8340 squareroot 8.706069866025E-14 -> 2.95060E-7 Inexact Rounded
+sqtx8341 squareroot 23838.58800625 -> 154.398 Inexact Rounded
+sqtx8342 squareroot 0.0013426911275625 -> 0.0366428 Inexact Rounded
+
+-- test use of round-half-even in underflow situations
+
+-- precisions 2; all cases where result is both subnormal and a tie
+precision: 2
+sqtx8343 squareroot 2.5E-21 -> 0E-10 Underflow Subnormal Inexact Rounded Clamped
+sqtx8344 squareroot 2.25E-20 -> 2E-10 Underflow Subnormal Inexact Rounded
+sqtx8345 squareroot 6.25E-20 -> 2E-10 Underflow Subnormal Inexact Rounded
+sqtx8346 squareroot 1.225E-19 -> 4E-10 Underflow Subnormal Inexact Rounded
+sqtx8347 squareroot 2.025E-19 -> 4E-10 Underflow Subnormal Inexact Rounded
+sqtx8348 squareroot 3.025E-19 -> 6E-10 Underflow Subnormal Inexact Rounded
+sqtx8349 squareroot 4.225E-19 -> 6E-10 Underflow Subnormal Inexact Rounded
+sqtx8350 squareroot 5.625E-19 -> 8E-10 Underflow Subnormal Inexact Rounded
+sqtx8351 squareroot 7.225E-19 -> 8E-10 Underflow Subnormal Inexact Rounded
+sqtx8352 squareroot 9.025E-19 -> 1.0E-9 Underflow Subnormal Inexact Rounded
+
+-- precision 3, input precision <= 5
+precision: 3
+sqtx8353 squareroot 2.5E-23 -> 0E-11 Underflow Subnormal Inexact Rounded Clamped
+sqtx8354 squareroot 2.25E-22 -> 2E-11 Underflow Subnormal Inexact Rounded
+sqtx8355 squareroot 6.25E-22 -> 2E-11 Underflow Subnormal Inexact Rounded
+sqtx8356 squareroot 1.225E-21 -> 4E-11 Underflow Subnormal Inexact Rounded
+sqtx8357 squareroot 2.025E-21 -> 4E-11 Underflow Subnormal Inexact Rounded
+sqtx8358 squareroot 3.025E-21 -> 6E-11 Underflow Subnormal Inexact Rounded
+sqtx8359 squareroot 4.225E-21 -> 6E-11 Underflow Subnormal Inexact Rounded
+sqtx8360 squareroot 5.625E-21 -> 8E-11 Underflow Subnormal Inexact Rounded
+sqtx8361 squareroot 7.225E-21 -> 8E-11 Underflow Subnormal Inexact Rounded
+sqtx8362 squareroot 9.025E-21 -> 1.0E-10 Underflow Subnormal Inexact Rounded
+sqtx8363 squareroot 1.1025E-20 -> 1.0E-10 Underflow Subnormal Inexact Rounded
+sqtx8364 squareroot 1.3225E-20 -> 1.2E-10 Underflow Subnormal Inexact Rounded
+sqtx8365 squareroot 1.5625E-20 -> 1.2E-10 Underflow Subnormal Inexact Rounded
+sqtx8366 squareroot 1.8225E-20 -> 1.4E-10 Underflow Subnormal Inexact Rounded
+sqtx8367 squareroot 2.1025E-20 -> 1.4E-10 Underflow Subnormal Inexact Rounded
+sqtx8368 squareroot 2.4025E-20 -> 1.6E-10 Underflow Subnormal Inexact Rounded
+sqtx8369 squareroot 2.7225E-20 -> 1.6E-10 Underflow Subnormal Inexact Rounded
+sqtx8370 squareroot 3.0625E-20 -> 1.8E-10 Underflow Subnormal Inexact Rounded
+sqtx8371 squareroot 3.4225E-20 -> 1.8E-10 Underflow Subnormal Inexact Rounded
+sqtx8372 squareroot 3.8025E-20 -> 2.0E-10 Underflow Subnormal Inexact Rounded
+sqtx8373 squareroot 4.2025E-20 -> 2.0E-10 Underflow Subnormal Inexact Rounded
+sqtx8374 squareroot 4.6225E-20 -> 2.2E-10 Underflow Subnormal Inexact Rounded
+sqtx8375 squareroot 5.0625E-20 -> 2.2E-10 Underflow Subnormal Inexact Rounded
+sqtx8376 squareroot 5.5225E-20 -> 2.4E-10 Underflow Subnormal Inexact Rounded
+sqtx8377 squareroot 6.0025E-20 -> 2.4E-10 Underflow Subnormal Inexact Rounded
+sqtx8378 squareroot 6.5025E-20 -> 2.6E-10 Underflow Subnormal Inexact Rounded
+sqtx8379 squareroot 7.0225E-20 -> 2.6E-10 Underflow Subnormal Inexact Rounded
+sqtx8380 squareroot 7.5625E-20 -> 2.8E-10 Underflow Subnormal Inexact Rounded
+sqtx8381 squareroot 8.1225E-20 -> 2.8E-10 Underflow Subnormal Inexact Rounded
+sqtx8382 squareroot 8.7025E-20 -> 3.0E-10 Underflow Subnormal Inexact Rounded
+sqtx8383 squareroot 9.3025E-20 -> 3.0E-10 Underflow Subnormal Inexact Rounded
+sqtx8384 squareroot 9.9225E-20 -> 3.2E-10 Underflow Subnormal Inexact Rounded
+
+--precision 4, input precision <= 4
+precision: 4
+sqtx8385 squareroot 2.5E-25 -> 0E-12 Underflow Subnormal Inexact Rounded Clamped
+sqtx8386 squareroot 2.25E-24 -> 2E-12 Underflow Subnormal Inexact Rounded
+sqtx8387 squareroot 6.25E-24 -> 2E-12 Underflow Subnormal Inexact Rounded
+sqtx8388 squareroot 1.225E-23 -> 4E-12 Underflow Subnormal Inexact Rounded
+sqtx8389 squareroot 2.025E-23 -> 4E-12 Underflow Subnormal Inexact Rounded
+sqtx8390 squareroot 3.025E-23 -> 6E-12 Underflow Subnormal Inexact Rounded
+sqtx8391 squareroot 4.225E-23 -> 6E-12 Underflow Subnormal Inexact Rounded
+sqtx8392 squareroot 5.625E-23 -> 8E-12 Underflow Subnormal Inexact Rounded
+sqtx8393 squareroot 7.225E-23 -> 8E-12 Underflow Subnormal Inexact Rounded
+sqtx8394 squareroot 9.025E-23 -> 1.0E-11 Underflow Subnormal Inexact Rounded
+
+--precision 5, input precision <= 5
+precision: 5
+sqtx8395 squareroot 2.5E-27 -> 0E-13 Underflow Subnormal Inexact Rounded Clamped
+sqtx8396 squareroot 2.25E-26 -> 2E-13 Underflow Subnormal Inexact Rounded
+sqtx8397 squareroot 6.25E-26 -> 2E-13 Underflow Subnormal Inexact Rounded
+sqtx8398 squareroot 1.225E-25 -> 4E-13 Underflow Subnormal Inexact Rounded
+sqtx8399 squareroot 2.025E-25 -> 4E-13 Underflow Subnormal Inexact Rounded
+sqtx8400 squareroot 3.025E-25 -> 6E-13 Underflow Subnormal Inexact Rounded
+sqtx8401 squareroot 4.225E-25 -> 6E-13 Underflow Subnormal Inexact Rounded
+sqtx8402 squareroot 5.625E-25 -> 8E-13 Underflow Subnormal Inexact Rounded
+sqtx8403 squareroot 7.225E-25 -> 8E-13 Underflow Subnormal Inexact Rounded
+sqtx8404 squareroot 9.025E-25 -> 1.0E-12 Underflow Subnormal Inexact Rounded
+sqtx8405 squareroot 1.1025E-24 -> 1.0E-12 Underflow Subnormal Inexact Rounded
+sqtx8406 squareroot 1.3225E-24 -> 1.2E-12 Underflow Subnormal Inexact Rounded
+sqtx8407 squareroot 1.5625E-24 -> 1.2E-12 Underflow Subnormal Inexact Rounded
+sqtx8408 squareroot 1.8225E-24 -> 1.4E-12 Underflow Subnormal Inexact Rounded
+sqtx8409 squareroot 2.1025E-24 -> 1.4E-12 Underflow Subnormal Inexact Rounded
+sqtx8410 squareroot 2.4025E-24 -> 1.6E-12 Underflow Subnormal Inexact Rounded
+sqtx8411 squareroot 2.7225E-24 -> 1.6E-12 Underflow Subnormal Inexact Rounded
+sqtx8412 squareroot 3.0625E-24 -> 1.8E-12 Underflow Subnormal Inexact Rounded
+sqtx8413 squareroot 3.4225E-24 -> 1.8E-12 Underflow Subnormal Inexact Rounded
+sqtx8414 squareroot 3.8025E-24 -> 2.0E-12 Underflow Subnormal Inexact Rounded
+sqtx8415 squareroot 4.2025E-24 -> 2.0E-12 Underflow Subnormal Inexact Rounded
+sqtx8416 squareroot 4.6225E-24 -> 2.2E-12 Underflow Subnormal Inexact Rounded
+sqtx8417 squareroot 5.0625E-24 -> 2.2E-12 Underflow Subnormal Inexact Rounded
+sqtx8418 squareroot 5.5225E-24 -> 2.4E-12 Underflow Subnormal Inexact Rounded
+sqtx8419 squareroot 6.0025E-24 -> 2.4E-12 Underflow Subnormal Inexact Rounded
+sqtx8420 squareroot 6.5025E-24 -> 2.6E-12 Underflow Subnormal Inexact Rounded
+sqtx8421 squareroot 7.0225E-24 -> 2.6E-12 Underflow Subnormal Inexact Rounded
+sqtx8422 squareroot 7.5625E-24 -> 2.8E-12 Underflow Subnormal Inexact Rounded
+sqtx8423 squareroot 8.1225E-24 -> 2.8E-12 Underflow Subnormal Inexact Rounded
+sqtx8424 squareroot 8.7025E-24 -> 3.0E-12 Underflow Subnormal Inexact Rounded
+sqtx8425 squareroot 9.3025E-24 -> 3.0E-12 Underflow Subnormal Inexact Rounded
+sqtx8426 squareroot 9.9225E-24 -> 3.2E-12 Underflow Subnormal Inexact Rounded
+
+-- a random selection of values that Python2.5.1 rounds incorrectly
+precision: 1
+sqtx8427 squareroot 227 -> 2E+1 Inexact Rounded
+sqtx8428 squareroot 625 -> 2E+1 Inexact Rounded
+sqtx8429 squareroot 1215 -> 3E+1 Inexact Rounded
+sqtx8430 squareroot 2008 -> 4E+1 Inexact Rounded
+sqtx8431 squareroot 2020 -> 4E+1 Inexact Rounded
+sqtx8432 squareroot 2026 -> 5E+1 Inexact Rounded
+sqtx8433 squareroot 2027 -> 5E+1 Inexact Rounded
+sqtx8434 squareroot 2065 -> 5E+1 Inexact Rounded
+sqtx8435 squareroot 2075 -> 5E+1 Inexact Rounded
+sqtx8436 squareroot 2088 -> 5E+1 Inexact Rounded
+sqtx8437 squareroot 3049 -> 6E+1 Inexact Rounded
+sqtx8438 squareroot 3057 -> 6E+1 Inexact Rounded
+sqtx8439 squareroot 3061 -> 6E+1 Inexact Rounded
+sqtx8440 squareroot 3092 -> 6E+1 Inexact Rounded
+sqtx8441 squareroot 4222 -> 6E+1 Inexact Rounded
+sqtx8442 squareroot 5676 -> 8E+1 Inexact Rounded
+sqtx8443 squareroot 5686 -> 8E+1 Inexact Rounded
+sqtx8444 squareroot 7215 -> 8E+1 Inexact Rounded
+sqtx8445 squareroot 9086 -> 1E+2 Inexact Rounded
+sqtx8446 squareroot 9095 -> 1E+2 Inexact Rounded
+
+precision: 2
+sqtx8447 squareroot 1266 -> 36 Inexact Rounded
+sqtx8448 squareroot 2552 -> 51 Inexact Rounded
+sqtx8449 squareroot 5554 -> 75 Inexact Rounded
+sqtx8450 squareroot 7832 -> 88 Inexact Rounded
+sqtx8451 squareroot 13201 -> 1.1E+2 Inexact Rounded
+sqtx8452 squareroot 15695 -> 1.3E+2 Inexact Rounded
+sqtx8453 squareroot 18272 -> 1.4E+2 Inexact Rounded
+sqtx8454 squareroot 21026 -> 1.5E+2 Inexact Rounded
+sqtx8455 squareroot 24069 -> 1.6E+2 Inexact Rounded
+sqtx8456 squareroot 34277 -> 1.9E+2 Inexact Rounded
+sqtx8457 squareroot 46233 -> 2.2E+2 Inexact Rounded
+sqtx8458 squareroot 46251 -> 2.2E+2 Inexact Rounded
+sqtx8459 squareroot 46276 -> 2.2E+2 Inexact Rounded
+sqtx8460 squareroot 70214 -> 2.6E+2 Inexact Rounded
+sqtx8461 squareroot 81249 -> 2.9E+2 Inexact Rounded
+sqtx8462 squareroot 81266 -> 2.9E+2 Inexact Rounded
+sqtx8463 squareroot 93065 -> 3.1E+2 Inexact Rounded
+sqtx8464 squareroot 93083 -> 3.1E+2 Inexact Rounded
+sqtx8465 squareroot 99230 -> 3.2E+2 Inexact Rounded
+sqtx8466 squareroot 99271 -> 3.2E+2 Inexact Rounded
+
+precision: 3
+sqtx8467 squareroot 11349 -> 107 Inexact Rounded
+sqtx8468 squareroot 26738 -> 164 Inexact Rounded
+sqtx8469 squareroot 31508 -> 178 Inexact Rounded
+sqtx8470 squareroot 44734 -> 212 Inexact Rounded
+sqtx8471 squareroot 44738 -> 212 Inexact Rounded
+sqtx8472 squareroot 51307 -> 227 Inexact Rounded
+sqtx8473 squareroot 62259 -> 250 Inexact Rounded
+sqtx8474 squareroot 75901 -> 276 Inexact Rounded
+sqtx8475 squareroot 76457 -> 277 Inexact Rounded
+sqtx8476 squareroot 180287 -> 425 Inexact Rounded
+sqtx8477 squareroot 202053 -> 450 Inexact Rounded
+sqtx8478 squareroot 235747 -> 486 Inexact Rounded
+sqtx8479 squareroot 256537 -> 506 Inexact Rounded
+sqtx8480 squareroot 299772 -> 548 Inexact Rounded
+sqtx8481 squareroot 415337 -> 644 Inexact Rounded
+sqtx8482 squareroot 617067 -> 786 Inexact Rounded
+sqtx8483 squareroot 628022 -> 792 Inexact Rounded
+sqtx8484 squareroot 645629 -> 804 Inexact Rounded
+sqtx8485 squareroot 785836 -> 886 Inexact Rounded
+sqtx8486 squareroot 993066 -> 997 Inexact Rounded
+
+precision: 6
+sqtx8487 squareroot 14917781 -> 3862.35 Inexact Rounded
+sqtx8488 squareroot 17237238 -> 4151.78 Inexact Rounded
+sqtx8489 squareroot 18054463 -> 4249.05 Inexact Rounded
+sqtx8490 squareroot 19990694 -> 4471.10 Inexact Rounded
+sqtx8491 squareroot 29061855 -> 5390.90 Inexact Rounded
+sqtx8492 squareroot 49166257 -> 7011.87 Inexact Rounded
+sqtx8493 squareroot 53082086 -> 7285.75 Inexact Rounded
+sqtx8494 squareroot 56787909 -> 7535.78 Inexact Rounded
+sqtx8495 squareroot 81140019 -> 9007.78 Inexact Rounded
+sqtx8496 squareroot 87977554 -> 9379.64 Inexact Rounded
+sqtx8497 squareroot 93624683 -> 9675.98 Inexact Rounded
+sqtx8498 squareroot 98732747 -> 9936.44 Inexact Rounded
+sqtx8499 squareroot 99222813 -> 9961.06 Inexact Rounded
+sqtx8500 squareroot 143883626 -> 11995.2 Inexact Rounded
+sqtx8501 squareroot 180433301 -> 13432.5 Inexact Rounded
+sqtx8502 squareroot 227034020 -> 15067.6 Inexact Rounded
+sqtx8503 squareroot 283253992 -> 16830.2 Inexact Rounded
+sqtx8504 squareroot 617047954 -> 24840.4 Inexact Rounded
+sqtx8505 squareroot 736870094 -> 27145.4 Inexact Rounded
+sqtx8506 squareroot 897322915 -> 29955.3 Inexact Rounded
+
+-- results close to minimum normal
+precision: 1
+sqtx8507 squareroot 1E-20 -> 0E-9 Underflow Subnormal Inexact Rounded Clamped
+sqtx8508 squareroot 1E-19 -> 0E-9 Underflow Subnormal Inexact Rounded Clamped
+sqtx8509 squareroot 1E-18 -> 1E-9
+
+precision: 2
+sqtx8510 squareroot 8.1E-19 -> 9E-10 Subnormal
+sqtx8511 squareroot 8.10E-19 -> 9E-10 Subnormal Rounded
+sqtx8512 squareroot 9.0E-19 -> 9E-10 Underflow Subnormal Inexact Rounded
+sqtx8513 squareroot 9.02E-19 -> 9E-10 Underflow Subnormal Inexact Rounded
+sqtx8514 squareroot 9.03E-19 -> 1.0E-9 Underflow Subnormal Inexact Rounded
+sqtx8515 squareroot 9.1E-19 -> 1.0E-9 Underflow Subnormal Inexact Rounded
+sqtx8516 squareroot 9.9E-19 -> 1.0E-9 Underflow Subnormal Inexact Rounded
+sqtx8517 squareroot 9.91E-19 -> 1.0E-9 Underflow Subnormal Inexact Rounded
+sqtx8518 squareroot 9.92E-19 -> 1.0E-9 Underflow Subnormal Inexact Rounded
+sqtx8519 squareroot 9.95E-19 -> 1.0E-9 Underflow Subnormal Inexact Rounded
+sqtx8520 squareroot 9.98E-19 -> 1.0E-9 Underflow Subnormal Inexact Rounded
+sqtx8521 squareroot 9.99E-19 -> 1.0E-9 Underflow Subnormal Inexact Rounded
+sqtx8522 squareroot 1E-18 -> 1E-9
+sqtx8523 squareroot 1.0E-18 -> 1.0E-9
+sqtx8524 squareroot 1.00E-18 -> 1.0E-9
+sqtx8525 squareroot 1.000E-18 -> 1.0E-9 Rounded
+sqtx8526 squareroot 1.0000E-18 -> 1.0E-9 Rounded
+sqtx8527 squareroot 1.01E-18 -> 1.0E-9 Inexact Rounded
+sqtx8528 squareroot 1.02E-18 -> 1.0E-9 Inexact Rounded
+sqtx8529 squareroot 1.1E-18 -> 1.0E-9 Inexact Rounded
+
+precision: 3
+sqtx8530 squareroot 8.1E-19 -> 9E-10 Subnormal
+sqtx8531 squareroot 8.10E-19 -> 9.0E-10 Subnormal
+sqtx8532 squareroot 8.100E-19 -> 9.0E-10 Subnormal
+sqtx8533 squareroot 8.1000E-19 -> 9.0E-10 Subnormal Rounded
+sqtx8534 squareroot 9.9E-19 -> 9.9E-10 Underflow Subnormal Inexact Rounded
+sqtx8535 squareroot 9.91E-19 -> 1.00E-9 Underflow Subnormal Inexact Rounded
+sqtx8536 squareroot 9.99E-19 -> 1.00E-9 Underflow Subnormal Inexact Rounded
+sqtx8537 squareroot 9.998E-19 -> 1.00E-9 Underflow Subnormal Inexact Rounded
+sqtx8538 squareroot 1E-18 -> 1E-9
+sqtx8539 squareroot 1.0E-18 -> 1.0E-9
+sqtx8540 squareroot 1.00E-18 -> 1.0E-9
+sqtx8541 squareroot 1.000E-18 -> 1.00E-9
+sqtx8542 squareroot 1.0000E-18 -> 1.00E-9
+sqtx8543 squareroot 1.00000E-18 -> 1.00E-9 Rounded
+sqtx8544 squareroot 1.000000E-18 -> 1.00E-9 Rounded
+sqtx8545 squareroot 1.01E-18 -> 1.00E-9 Inexact Rounded
+sqtx8546 squareroot 1.02E-18 -> 1.01E-9 Inexact Rounded
+
+-- result exactly representable with precision p, but not necessarily
+-- exactly representable as a subnormal; check the correct flags are raised
+precision: 2
+sqtx8547 squareroot 1.21E-20 -> 1E-10 Underflow Subnormal Inexact Rounded
+sqtx8548 squareroot 1.44E-20 -> 1E-10 Underflow Subnormal Inexact Rounded
+sqtx8549 squareroot 9.61E-20 -> 3E-10 Underflow Subnormal Inexact Rounded
+sqtx8550 squareroot 8.836E-19 -> 9E-10 Underflow Subnormal Inexact Rounded
+sqtx8551 squareroot 9.216E-19 -> 1.0E-9 Underflow Subnormal Inexact Rounded
+
+precision: 3
+sqtx8552 squareroot 1.21E-22 -> 1E-11 Underflow Subnormal Inexact Rounded
+sqtx8553 squareroot 1.21E-20 -> 1.1E-10 Subnormal
+sqtx8554 squareroot 1.96E-22 -> 1E-11 Underflow Subnormal Inexact Rounded
+sqtx8555 squareroot 1.96E-20 -> 1.4E-10 Subnormal
+sqtx8556 squareroot 2.56E-22 -> 2E-11 Underflow Subnormal Inexact Rounded
+sqtx8557 squareroot 4.00E-22 -> 2E-11 Subnormal Rounded
+sqtx8558 squareroot 7.84E-22 -> 3E-11 Underflow Subnormal Inexact Rounded
+sqtx8559 squareroot 9.801E-21 -> 1.0E-10 Underflow Subnormal Inexact Rounded
+sqtx8560 squareroot 9.801E-19 -> 9.9E-10 Subnormal
+sqtx8561 squareroot 1.0201E-20 -> 1.0E-10 Underflow Subnormal Inexact Rounded
+sqtx8562 squareroot 1.1025E-20 -> 1.0E-10 Underflow Subnormal Inexact Rounded
+sqtx8563 squareroot 1.1236E-20 -> 1.1E-10 Underflow Subnormal Inexact Rounded
+sqtx8564 squareroot 1.2996E-20 -> 1.1E-10 Underflow Subnormal Inexact Rounded
+sqtx8565 squareroot 1.3225E-20 -> 1.2E-10 Underflow Subnormal Inexact Rounded
+
+-- A selection of subnormal results prone to double rounding errors
+precision: 2
+sqtx8566 squareroot 2.3E-21 -> 0E-10 Underflow Subnormal Inexact Rounded Clamped
+sqtx8567 squareroot 2.4E-21 -> 0E-10 Underflow Subnormal Inexact Rounded Clamped
+sqtx8568 squareroot 2.5E-21 -> 0E-10 Underflow Subnormal Inexact Rounded Clamped
+sqtx8569 squareroot 2.6E-21 -> 1E-10 Underflow Subnormal Inexact Rounded
+sqtx8570 squareroot 2.7E-21 -> 1E-10 Underflow Subnormal Inexact Rounded
+sqtx8571 squareroot 2.8E-21 -> 1E-10 Underflow Subnormal Inexact Rounded
+sqtx8572 squareroot 2.2E-20 -> 1E-10 Underflow Subnormal Inexact Rounded
+sqtx8573 squareroot 2.3E-20 -> 2E-10 Underflow Subnormal Inexact Rounded
+sqtx8574 squareroot 2.4E-20 -> 2E-10 Underflow Subnormal Inexact Rounded
+sqtx8575 squareroot 6.2E-20 -> 2E-10 Underflow Subnormal Inexact Rounded
+sqtx8576 squareroot 6.3E-20 -> 3E-10 Underflow Subnormal Inexact Rounded
+sqtx8577 squareroot 6.4E-20 -> 3E-10 Underflow Subnormal Inexact Rounded
+sqtx8578 squareroot 6.5E-20 -> 3E-10 Underflow Subnormal Inexact Rounded
+sqtx8579 squareroot 1.2E-19 -> 3E-10 Underflow Subnormal Inexact Rounded
+sqtx8580 squareroot 2.0E-19 -> 4E-10 Underflow Subnormal Inexact Rounded
+sqtx8581 squareroot 4.2E-19 -> 6E-10 Underflow Subnormal Inexact Rounded
+sqtx8582 squareroot 5.6E-19 -> 7E-10 Underflow Subnormal Inexact Rounded
+sqtx8583 squareroot 5.7E-19 -> 8E-10 Underflow Subnormal Inexact Rounded
+sqtx8584 squareroot 9.0E-19 -> 9E-10 Underflow Subnormal Inexact Rounded
+sqtx8585 squareroot 9.1E-19 -> 1.0E-9 Underflow Subnormal Inexact Rounded
+precision: 3
+sqtx8586 squareroot 2.6E-23 -> 1E-11 Underflow Subnormal Inexact Rounded
+sqtx8587 squareroot 2.22E-22 -> 1E-11 Underflow Subnormal Inexact Rounded
+sqtx8588 squareroot 6.07E-22 -> 2E-11 Underflow Subnormal Inexact Rounded
+sqtx8589 squareroot 6.25E-22 -> 2E-11 Underflow Subnormal Inexact Rounded
+sqtx8590 squareroot 6.45E-22 -> 3E-11 Underflow Subnormal Inexact Rounded
+sqtx8591 squareroot 6.50E-22 -> 3E-11 Underflow Subnormal Inexact Rounded
+sqtx8592 squareroot 1.22E-21 -> 3E-11 Underflow Subnormal Inexact Rounded
+sqtx8593 squareroot 1.24E-21 -> 4E-11 Underflow Subnormal Inexact Rounded
+sqtx8594 squareroot 4.18E-21 -> 6E-11 Underflow Subnormal Inexact Rounded
+sqtx8595 squareroot 7.19E-21 -> 8E-11 Underflow Subnormal Inexact Rounded
+sqtx8596 squareroot 8.94E-21 -> 9E-11 Underflow Subnormal Inexact Rounded
+sqtx8597 squareroot 1.81E-20 -> 1.3E-10 Underflow Subnormal Inexact Rounded
+sqtx8598 squareroot 4.64E-20 -> 2.2E-10 Underflow Subnormal Inexact Rounded
+sqtx8599 squareroot 5.06E-20 -> 2.2E-10 Underflow Subnormal Inexact Rounded
+sqtx8600 squareroot 5.08E-20 -> 2.3E-10 Underflow Subnormal Inexact Rounded
+sqtx8601 squareroot 7.00E-20 -> 2.6E-10 Underflow Subnormal Inexact Rounded
+sqtx8602 squareroot 1.81E-19 -> 4.3E-10 Underflow Subnormal Inexact Rounded
+sqtx8603 squareroot 6.64E-19 -> 8.1E-10 Underflow Subnormal Inexact Rounded
+sqtx8604 squareroot 7.48E-19 -> 8.6E-10 Underflow Subnormal Inexact Rounded
+sqtx8605 squareroot 9.91E-19 -> 1.00E-9 Underflow Subnormal Inexact Rounded
+precision: 4
+sqtx8606 squareroot 6.24E-24 -> 2E-12 Underflow Subnormal Inexact Rounded
+sqtx8607 squareroot 7.162E-23 -> 8E-12 Underflow Subnormal Inexact Rounded
+sqtx8608 squareroot 7.243E-23 -> 9E-12 Underflow Subnormal Inexact Rounded
+sqtx8609 squareroot 8.961E-23 -> 9E-12 Underflow Subnormal Inexact Rounded
+sqtx8610 squareroot 9.029E-23 -> 1.0E-11 Underflow Subnormal Inexact Rounded
+sqtx8611 squareroot 4.624E-22 -> 2.2E-11 Underflow Subnormal Inexact Rounded
+sqtx8612 squareroot 5.980E-22 -> 2.4E-11 Underflow Subnormal Inexact Rounded
+sqtx8613 squareroot 6.507E-22 -> 2.6E-11 Underflow Subnormal Inexact Rounded
+sqtx8614 squareroot 1.483E-21 -> 3.9E-11 Underflow Subnormal Inexact Rounded
+sqtx8615 squareroot 3.903E-21 -> 6.2E-11 Underflow Subnormal Inexact Rounded
+sqtx8616 squareroot 8.733E-21 -> 9.3E-11 Underflow Subnormal Inexact Rounded
+sqtx8617 squareroot 1.781E-20 -> 1.33E-10 Underflow Subnormal Inexact Rounded
+sqtx8618 squareroot 6.426E-20 -> 2.53E-10 Underflow Subnormal Inexact Rounded
+sqtx8619 squareroot 7.102E-20 -> 2.66E-10 Underflow Subnormal Inexact Rounded
+sqtx8620 squareroot 7.535E-20 -> 2.74E-10 Underflow Subnormal Inexact Rounded
+sqtx8621 squareroot 9.892E-20 -> 3.15E-10 Underflow Subnormal Inexact Rounded
+sqtx8622 squareroot 1.612E-19 -> 4.01E-10 Underflow Subnormal Inexact Rounded
+sqtx8623 squareroot 1.726E-19 -> 4.15E-10 Underflow Subnormal Inexact Rounded
+sqtx8624 squareroot 1.853E-19 -> 4.30E-10 Underflow Subnormal Inexact Rounded
+sqtx8625 squareroot 4.245E-19 -> 6.52E-10 Underflow Subnormal Inexact Rounded
+
+-- clamping and overflow for large exponents
+precision: 1
+sqtx8626 squareroot 1E+18 -> 1E+9
+sqtx8627 squareroot 1E+19 -> 3E+9 Inexact Rounded
+sqtx8628 squareroot 9E+19 -> 9E+9 Inexact Rounded
+sqtx8629 squareroot 9.1E+19 -> Infinity Overflow Inexact Rounded
+sqtx8630 squareroot 1E+20 -> Infinity Overflow Inexact Rounded
+
+precision: 2
+sqtx8631 squareroot 1E+18 -> 1E+9
+sqtx8632 squareroot 1.0E+18 -> 1.0E+9
+sqtx8633 squareroot 1.00E+18 -> 1.0E+9
+sqtx8634 squareroot 1.000E+18 -> 1.0E+9 Rounded
+sqtx8635 squareroot 1E+20 -> Infinity Overflow Inexact Rounded
+clamp: 1
+sqtx8636 squareroot 1E+18 -> 1.0E+9 Clamped
+sqtx8637 squareroot 1.0E+18 -> 1.0E+9
+sqtx8638 squareroot 1E+20 -> Infinity Overflow Inexact Rounded
+clamp: 0
+
+precision: 6
+sqtx8639 squareroot 1E+18 -> 1E+9
+sqtx8640 squareroot 1.0000000000E+18 -> 1.00000E+9
+sqtx8641 squareroot 1.00000000000E+18 -> 1.00000E+9 Rounded
+sqtx8642 squareroot 1E+20 -> Infinity Overflow Inexact Rounded
+clamp: 1
+sqtx8643 squareroot 1E+8 -> 1E+4
+sqtx8644 squareroot 1E+10 -> 1.0E+5 Clamped
+sqtx8645 squareroot 1.0E+10 -> 1.0E+5
+sqtx8646 squareroot 1E+12 -> 1.00E+6 Clamped
+sqtx8647 squareroot 1.0E+12 -> 1.00E+6 Clamped
+sqtx8648 squareroot 1.00E+12 -> 1.00E+6 Clamped
+sqtx8649 squareroot 1.000E+12 -> 1.00E+6
+sqtx8650 squareroot 1E+18 -> 1.00000E+9 Clamped
+sqtx8651 squareroot 1.00000000E+18 -> 1.00000E+9 Clamped
+sqtx8652 squareroot 1.000000000E+18 -> 1.00000E+9
+sqtx8653 squareroot 1E+20 -> Infinity Overflow Inexact Rounded
+clamp: 0
+
+-- The following example causes a TypeError in Python 2.5.1
+precision: 3
+maxexponent: 9
+minexponent: -9
+sqtx8654 squareroot 10000000000 -> 1.00E+5 Rounded
+
+-- Additional tricky cases of underflown subnormals
+rounding: half_even
+precision: 5
+maxexponent: 999
+minexponent: -999
+sqtx8700 squareroot 2.8073E-2000 -> 1.675E-1000 Underflow Subnormal Inexact Rounded
+sqtx8701 squareroot 2.8883E-2000 -> 1.699E-1000 Underflow Subnormal Inexact Rounded
+sqtx8702 squareroot 3.1524E-2000 -> 1.775E-1000 Underflow Subnormal Inexact Rounded
+sqtx8703 squareroot 3.2382E-2000 -> 1.799E-1000 Underflow Subnormal Inexact Rounded
+sqtx8704 squareroot 3.5175E-2000 -> 1.875E-1000 Underflow Subnormal Inexact Rounded
+sqtx8705 squareroot 3.6081E-2000 -> 1.899E-1000 Underflow Subnormal Inexact Rounded
+sqtx8706 squareroot 3.9026E-2000 -> 1.975E-1000 Underflow Subnormal Inexact Rounded
+sqtx8707 squareroot 3.9980E-2000 -> 1.999E-1000 Underflow Subnormal Inexact Rounded
+sqtx8708 squareroot 4.3077E-2000 -> 2.075E-1000 Underflow Subnormal Inexact Rounded
+sqtx8709 squareroot 4.4079E-2000 -> 2.099E-1000 Underflow Subnormal Inexact Rounded
+sqtx8710 squareroot 4.7328E-2000 -> 2.175E-1000 Underflow Subnormal Inexact Rounded
+sqtx8711 squareroot 4.8378E-2000 -> 2.199E-1000 Underflow Subnormal Inexact Rounded
+sqtx8712 squareroot 5.1779E-2000 -> 2.275E-1000 Underflow Subnormal Inexact Rounded
+sqtx8713 squareroot 5.2877E-2000 -> 2.299E-1000 Underflow Subnormal Inexact Rounded
+sqtx8714 squareroot 5.6430E-2000 -> 2.375E-1000 Underflow Subnormal Inexact Rounded
+sqtx8715 squareroot 5.7576E-2000 -> 2.399E-1000 Underflow Subnormal Inexact Rounded
+sqtx8716 squareroot 6.1281E-2000 -> 2.475E-1000 Underflow Subnormal Inexact Rounded
+sqtx8717 squareroot 6.2475E-2000 -> 2.499E-1000 Underflow Subnormal Inexact Rounded
+sqtx8718 squareroot 6.6332E-2000 -> 2.575E-1000 Underflow Subnormal Inexact Rounded
+sqtx8719 squareroot 6.7574E-2000 -> 2.599E-1000 Underflow Subnormal Inexact Rounded
+sqtx8720 squareroot 7.1583E-2000 -> 2.675E-1000 Underflow Subnormal Inexact Rounded
+sqtx8721 squareroot 7.2873E-2000 -> 2.699E-1000 Underflow Subnormal Inexact Rounded
+sqtx8722 squareroot 7.7034E-2000 -> 2.775E-1000 Underflow Subnormal Inexact Rounded
+sqtx8723 squareroot 7.8372E-2000 -> 2.799E-1000 Underflow Subnormal Inexact Rounded
+sqtx8724 squareroot 8.2685E-2000 -> 2.875E-1000 Underflow Subnormal Inexact Rounded
+sqtx8725 squareroot 8.4071E-2000 -> 2.899E-1000 Underflow Subnormal Inexact Rounded
+sqtx8726 squareroot 8.8536E-2000 -> 2.975E-1000 Underflow Subnormal Inexact Rounded
+sqtx8727 squareroot 8.9970E-2000 -> 2.999E-1000 Underflow Subnormal Inexact Rounded
+sqtx8728 squareroot 9.4587E-2000 -> 3.075E-1000 Underflow Subnormal Inexact Rounded
+sqtx8729 squareroot 9.6069E-2000 -> 3.099E-1000 Underflow Subnormal Inexact Rounded
+-- (End of Mark Dickinson's testcases.)
+
+
+-- Some additional edge cases
+maxexponent: 9
+minexponent: -9
+precision: 2
+sqtx9000 squareroot 9980.01 -> 1.0E+2 Inexact Rounded
+precision: 3
+sqtx9001 squareroot 9980.01 -> 99.9
+precision: 4
+sqtx9002 squareroot 9980.01 -> 99.9
+
+-- Exact from over-precise
+precision: 4
+sqtx9003 squareroot 11025 -> 105
+precision: 3
+sqtx9004 squareroot 11025 -> 105
+precision: 2
+sqtx9005 squareroot 11025 -> 1.0E+2 Inexact Rounded
+precision: 1
+sqtx9006 squareroot 11025 -> 1E+2 Inexact Rounded
+
+-- Out-of-bounds zeros
+precision: 4
+sqtx9010 squareroot 0E-9 -> 0.00000
+sqtx9011 squareroot 0E-10 -> 0.00000
+sqtx9012 squareroot 0E-11 -> 0.000000
+sqtx9013 squareroot 0E-12 -> 0.000000
+sqtx9014 squareroot 0E-13 -> 0E-7
+sqtx9015 squareroot 0E-14 -> 0E-7
+sqtx9020 squareroot 0E-17 -> 0E-9
+sqtx9021 squareroot 0E-20 -> 0E-10
+sqtx9022 squareroot 0E-22 -> 0E-11
+sqtx9023 squareroot 0E-24 -> 0E-12
+sqtx9024 squareroot 0E-25 -> 0E-12 Clamped
+sqtx9025 squareroot 0E-26 -> 0E-12 Clamped
+sqtx9026 squareroot 0E-27 -> 0E-12 Clamped
+sqtx9027 squareroot 0E-28 -> 0E-12 Clamped
+
+sqtx9030 squareroot 0E+8 -> 0E+4
+sqtx9031 squareroot 0E+10 -> 0E+5
+sqtx9032 squareroot 0E+12 -> 0E+6
+sqtx9033 squareroot 0E+14 -> 0E+7
+sqtx9034 squareroot 0E+15 -> 0E+7
+sqtx9035 squareroot 0E+16 -> 0E+8
+sqtx9036 squareroot 0E+18 -> 0E+9
+sqtx9037 squareroot 0E+19 -> 0E+9
+sqtx9038 squareroot 0E+20 -> 0E+9 Clamped
+sqtx9039 squareroot 0E+21 -> 0E+9 Clamped
+sqtx9040 squareroot 0E+22 -> 0E+9 Clamped
+
+
-- Null test
-sqtx900 squareroot # -> NaN Invalid_operation
+sqtx9900 squareroot # -> NaN Invalid_operation
Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/subtract.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/subtract.decTest (original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/subtract.decTest Fri Sep 21 03:17:09 2007
@@ -1,6 +1,6 @@
------------------------------------------------------------------------
-- subtract.decTest -- decimal subtraction --
--- Copyright (c) IBM Corporation, 1981, 2004. All rights reserved. --
+-- Copyright (c) IBM Corporation, 1981, 2007. All rights reserved. --
------------------------------------------------------------------------
-- Please see the document "General Decimal Arithmetic Testcases" --
-- at http://www2.hursley.ibm.com/decimal for the description of --
@@ -17,7 +17,7 @@
-- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
-- mfc at uk.ibm.com --
------------------------------------------------------------------------
-version: 2.39
+version: 2.56
extended: 1
precision: 9
@@ -805,9 +805,9 @@
subx1015 subtract 0 0.999E-999 -> -1.00E-999 Inexact Rounded Subnormal Underflow
subx1016 subtract 0 0.099E-999 -> -1.0E-1000 Inexact Rounded Subnormal Underflow
subx1017 subtract 0 0.009E-999 -> -1E-1001 Inexact Rounded Subnormal Underflow
-subx1018 subtract 0 0.001E-999 -> -0E-1001 Inexact Rounded Subnormal Underflow
-subx1019 subtract 0 0.0009E-999 -> -0E-1001 Inexact Rounded Subnormal Underflow
-subx1020 subtract 0 0.0001E-999 -> -0E-1001 Inexact Rounded Subnormal Underflow
+subx1018 subtract 0 0.001E-999 -> -0E-1001 Inexact Rounded Subnormal Underflow Clamped
+subx1019 subtract 0 0.0009E-999 -> -0E-1001 Inexact Rounded Subnormal Underflow Clamped
+subx1020 subtract 0 0.0001E-999 -> -0E-1001 Inexact Rounded Subnormal Underflow Clamped
subx1030 subtract 0 -1.00E-999 -> 1.00E-999
subx1031 subtract 0 -0.1E-999 -> 1E-1000 Subnormal
@@ -818,9 +818,9 @@
subx1035 subtract 0 -0.999E-999 -> 1.00E-999 Inexact Rounded Subnormal Underflow
subx1036 subtract 0 -0.099E-999 -> 1.0E-1000 Inexact Rounded Subnormal Underflow
subx1037 subtract 0 -0.009E-999 -> 1E-1001 Inexact Rounded Subnormal Underflow
-subx1038 subtract 0 -0.001E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow
-subx1039 subtract 0 -0.0009E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow
-subx1040 subtract 0 -0.0001E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow
+subx1038 subtract 0 -0.001E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow Clamped
+subx1039 subtract 0 -0.0009E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow Clamped
+subx1040 subtract 0 -0.0001E-999 -> 0E-1001 Inexact Rounded Subnormal Underflow Clamped
-- some non-zero subnormal subtracts
-- subx1056 is a tricky case
@@ -831,7 +831,7 @@
subx1053 subtract 0.100E-999 0.1E-999 -> 0E-1001 Clamped
subx1054 subtract 0.01E-999 0.1E-999 -> -9E-1001 Subnormal
subx1055 subtract 0.999E-999 0.1E-999 -> 9.0E-1000 Inexact Rounded Subnormal Underflow
-subx1056 subtract 0.099E-999 0.1E-999 -> -0E-1001 Inexact Rounded Subnormal Underflow
+subx1056 subtract 0.099E-999 0.1E-999 -> -0E-1001 Inexact Rounded Subnormal Underflow Clamped
subx1057 subtract 0.009E-999 0.1E-999 -> -9E-1001 Inexact Rounded Subnormal Underflow
subx1058 subtract 0.001E-999 0.1E-999 -> -1.0E-1000 Inexact Rounded Subnormal Underflow
subx1059 subtract 0.0009E-999 0.1E-999 -> -1.0E-1000 Inexact Rounded Subnormal Underflow
@@ -849,15 +849,25 @@
subx1105 subtract 1.52445E-80 0 -> 1.524E-80 Inexact Rounded Subnormal Underflow
subx1106 subtract 1.52446E-80 0 -> 1.524E-80 Inexact Rounded Subnormal Underflow
-subx1111 subtract 1.2345678E-80 1.2345671E-80 -> 0E-83 Inexact Rounded Subnormal Underflow
-subx1112 subtract 1.2345678E-80 1.2345618E-80 -> 0E-83 Inexact Rounded Subnormal Underflow
-subx1113 subtract 1.2345678E-80 1.2345178E-80 -> 0E-83 Inexact Rounded Subnormal Underflow
-subx1114 subtract 1.2345678E-80 1.2341678E-80 -> 0E-83 Inexact Rounded Subnormal Underflow
+subx1111 subtract 1.2345678E-80 1.2345671E-80 -> 0E-83 Inexact Rounded Subnormal Underflow Clamped
+subx1112 subtract 1.2345678E-80 1.2345618E-80 -> 0E-83 Inexact Rounded Subnormal Underflow Clamped
+subx1113 subtract 1.2345678E-80 1.2345178E-80 -> 0E-83 Inexact Rounded Subnormal Underflow Clamped
+subx1114 subtract 1.2345678E-80 1.2341678E-80 -> 0E-83 Inexact Rounded Subnormal Underflow Clamped
subx1115 subtract 1.2345678E-80 1.2315678E-80 -> 3E-83 Rounded Subnormal
subx1116 subtract 1.2345678E-80 1.2145678E-80 -> 2.0E-82 Rounded Subnormal
subx1117 subtract 1.2345678E-80 1.1345678E-80 -> 1.00E-81 Rounded Subnormal
subx1118 subtract 1.2345678E-80 0.2345678E-80 -> 1.000E-80 Rounded Subnormal
+precision: 34
+rounding: half_up
+maxExponent: 6144
+minExponent: -6143
+-- Examples from SQL proposal (Krishna Kulkarni)
+subx1125 subtract 130E-2 120E-2 -> 0.10
+subx1126 subtract 130E-2 12E-1 -> 0.10
+subx1127 subtract 130E-2 1E0 -> 0.30
+subx1128 subtract 1E2 1E4 -> -9.9E+3
+
-- Null tests
subx9990 subtract 10 # -> NaN Invalid_operation
subx9991 subtract # 10 -> NaN Invalid_operation
Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/testall.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/testall.decTest (original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/testall.decTest Fri Sep 21 03:17:09 2007
@@ -1,6 +1,6 @@
------------------------------------------------------------------------
-- testall.decTest -- run all general decimal arithmetic testcases --
--- Copyright (c) IBM Corporation, 1981, 2004. All rights reserved. --
+-- Copyright (c) IBM Corporation, 1981, 2007. All rights reserved. --
------------------------------------------------------------------------
-- Please see the document "General Decimal Arithmetic Testcases" --
-- at http://www2.hursley.ibm.com/decimal for the description of --
@@ -17,41 +17,70 @@
-- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
-- mfc at uk.ibm.com --
------------------------------------------------------------------------
-version: 2.39
+version: 2.56
-- core tests (using Extended: 1) --------------------------------------
dectest: base
+
dectest: abs
dectest: add
+dectest: and
dectest: clamp
+dectest: class
dectest: compare
+dectest: comparesig
+dectest: comparetotal
+dectest: comparetotmag
+dectest: copy
+dectest: copyabs
+dectest: copynegate
+dectest: copysign
dectest: divide
dectest: divideint
+dectest: exp
+dectest: fma
dectest: inexact
+dectest: invert
+dectest: ln
+dectest: logb
+dectest: log10
dectest: max
+dectest: maxmag
dectest: min
+dectest: minmag
dectest: minus
dectest: multiply
-dectest: normalize
+dectest: nextminus
+dectest: nextplus
+dectest: nexttoward
+dectest: or
dectest: plus
dectest: power
+dectest: powersqrt
dectest: quantize
dectest: randoms
+dectest: reduce -- [was called normalize]
dectest: remainder
dectest: remaindernear
dectest: rescale -- [obsolete]
+dectest: rotate
dectest: rounding
dectest: samequantum
+dectest: scaleb
+dectest: shift
dectest: squareroot
dectest: subtract
dectest: tointegral
+dectest: tointegralx
dectest: trim
+dectest: xor
--- The next are for the Strawman 4d concrete representations
-dectest: decimal32
-dectest: decimal64
-dectest: decimal128
-
+-- The next are for the Strawman 4d concrete representations and
+-- tests at those sizes [including dsEncode, ddEncode, and dqEncode,
+-- which replace decimal32, decimal64, and decimal128]
+dectest: decSingle
+dectest: decDouble
+dectest: decQuad
-- General 31->33-digit boundary tests
dectest: randombound32
Modified: python/branches/py3k-importlib/Lib/test/decimaltestdata/tointegral.decTest
==============================================================================
--- python/branches/py3k-importlib/Lib/test/decimaltestdata/tointegral.decTest (original)
+++ python/branches/py3k-importlib/Lib/test/decimaltestdata/tointegral.decTest Fri Sep 21 03:17:09 2007
@@ -1,6 +1,6 @@
------------------------------------------------------------------------
-- tointegral.decTest -- round decimal to integral value --
--- Copyright (c) IBM Corporation, 2001, 2003. All rights reserved. --
+-- Copyright (c) IBM Corporation, 2001, 2007. All rights reserved. --
------------------------------------------------------------------------
-- Please see the document "General Decimal Arithmetic Testcases" --
-- at http://www2.hursley.ibm.com/decimal for the description of --
@@ -17,7 +17,7 @@
-- IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK --
-- mfc at uk.ibm.com --
------------------------------------------------------------------------
-version: 2.39
+version: 2.56
-- This set of tests tests the extended specification 'round-to-integral
-- value' operation (from IEEE 854, later modified in 754r).
@@ -174,3 +174,68 @@
intx206 tointegral 7.89E+77 -> 7.89E+77
intx207 tointegral -Inf -> -Infinity
+
+-- all rounding modes
+rounding: half_even
+
+intx210 tointegral 55.5 -> 56
+intx211 tointegral 56.5 -> 56
+intx212 tointegral 57.5 -> 58
+intx213 tointegral -55.5 -> -56
+intx214 tointegral -56.5 -> -56
+intx215 tointegral -57.5 -> -58
+
+rounding: half_up
+
+intx220 tointegral 55.5 -> 56
+intx221 tointegral 56.5 -> 57
+intx222 tointegral 57.5 -> 58
+intx223 tointegral -55.5 -> -56
+intx224 tointegral -56.5 -> -57
+intx225 tointegral -57.5 -> -58
+
+rounding: half_down
+
+intx230 tointegral 55.5 -> 55
+intx231 tointegral 56.5 -> 56
+intx232 tointegral 57.5 -> 57
+intx233 tointegral -55.5 -> -55
+intx234 tointegral -56.5 -> -56
+intx235 tointegral -57.5 -> -57
+
+rounding: up
+
+intx240 tointegral 55.3 -> 56
+intx241 tointegral 56.3 -> 57
+intx242 tointegral 57.3 -> 58
+intx243 tointegral -55.3 -> -56
+intx244 tointegral -56.3 -> -57
+intx245 tointegral -57.3 -> -58
+
+rounding: down
+
+intx250 tointegral 55.7 -> 55
+intx251 tointegral 56.7 -> 56
+intx252 tointegral 57.7 -> 57
+intx253 tointegral -55.7 -> -55
+intx254 tointegral -56.7 -> -56
+intx255 tointegral -57.7 -> -57
+
+rounding: ceiling
+
+intx260 tointegral 55.3 -> 56
+intx261 tointegral 56.3 -> 57
+intx262 tointegral 57.3 -> 58
+intx263 tointegral -55.3 -> -55
+intx264 tointegral -56.3 -> -56
+intx265 tointegral -57.3 -> -57
+
+rounding: floor
+
+intx270 tointegral 55.7 -> 55
+intx271 tointegral 56.7 -> 56
+intx272 tointegral 57.7 -> 57
+intx273 tointegral -55.7 -> -56
+intx274 tointegral -56.7 -> -57
+intx275 tointegral -57.7 -> -58
+
Modified: python/branches/py3k-importlib/Lib/test/list_tests.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/list_tests.py (original)
+++ python/branches/py3k-importlib/Lib/test/list_tests.py Fri Sep 21 03:17:09 2007
@@ -46,6 +46,11 @@
self.assertEqual(str(a2), "[0, 1, 2, [...], 3]")
self.assertEqual(repr(a2), "[0, 1, 2, [...], 3]")
+ l0 = []
+ for i in range(sys.getrecursionlimit() + 100):
+ l0 = [l0]
+ self.assertRaises(RuntimeError, repr, l0)
+
def test_print(self):
d = self.type2test(range(200))
d.append(d)
Modified: python/branches/py3k-importlib/Lib/test/regrtest.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/regrtest.py (original)
+++ python/branches/py3k-importlib/Lib/test/regrtest.py Fri Sep 21 03:17:09 2007
@@ -1108,7 +1108,6 @@
class _ExpectedSkips:
def __init__(self):
import os.path
- from test import test_socket_ssl
from test import test_timeout
self.valid = False
@@ -1120,8 +1119,13 @@
if not os.path.supports_unicode_filenames:
self.expected.add('test_pep277')
- if test_socket_ssl.skip_expected:
- self.expected.add('test_socket_ssl')
+ try:
+ from test import test_socket_ssl
+ except ImportError:
+ pass
+ else:
+ if test_socket_ssl.skip_expected:
+ self.expected.add('test_socket_ssl')
if test_timeout.skip_expected:
self.expected.add('test_timeout')
Modified: python/branches/py3k-importlib/Lib/test/test_cmd_line.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_cmd_line.py (original)
+++ python/branches/py3k-importlib/Lib/test/test_cmd_line.py Fri Sep 21 03:17:09 2007
@@ -4,7 +4,7 @@
import subprocess
def _spawn_python(*args):
- cmd_line = [sys.executable]
+ cmd_line = [sys.executable, '-E']
cmd_line.extend(args)
return subprocess.Popen(cmd_line, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
@@ -24,7 +24,7 @@
return _kill_python(p)
def exit_code(self, *args):
- cmd_line = [sys.executable]
+ cmd_line = [sys.executable, '-E']
cmd_line.extend(args)
return subprocess.call(cmd_line, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
@@ -38,9 +38,6 @@
self.assertTrue(data == b'' or data.endswith(b'\n'))
self.assertTrue(b'Traceback' not in data)
- def test_environment(self):
- self.verify_valid_flag('-E')
-
def test_optimize(self):
self.verify_valid_flag('-O')
self.verify_valid_flag('-OO')
Modified: python/branches/py3k-importlib/Lib/test/test_collections.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_collections.py (original)
+++ python/branches/py3k-importlib/Lib/test/test_collections.py Fri Sep 21 03:17:09 2007
@@ -38,6 +38,13 @@
self.assertEqual(repr(p), 'Point(x=11, y=22)')
self.assert_('__dict__' not in dir(p)) # verify instance has no dict
self.assert_('__weakref__' not in dir(p))
+ self.assertEqual(p.__fields__, ('x', 'y')) # test __fields__ attribute
+ self.assertEqual(p.__replace__('x', 1), (1, 22)) # test __replace__ method
+
+ # verify that field string can have commas
+ Point = NamedTuple('Point', 'x, y')
+ p = Point(x=11, y=22)
+ self.assertEqual(repr(p), 'Point(x=11, y=22)')
def test_tupleness(self):
Point = NamedTuple('Point', 'x y')
@@ -58,6 +65,12 @@
self.assertEqual(p.y, y)
self.assertRaises(AttributeError, eval, 'p.z', locals())
+ def test_odd_sizes(self):
+ Zero = NamedTuple('Zero', '')
+ self.assertEqual(Zero(), ())
+ Dot = NamedTuple('Dot', 'd')
+ self.assertEqual(Dot(1), (1,))
+
class TestOneTrickPonyABCs(unittest.TestCase):
Modified: python/branches/py3k-importlib/Lib/test/test_decimal.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_decimal.py (original)
+++ python/branches/py3k-importlib/Lib/test/test_decimal.py Fri Sep 21 03:17:09 2007
@@ -65,9 +65,7 @@
# Slower, since it runs some things several times.
EXTENDEDERRORTEST = False
-
#Map the test cases' error names to the actual errors
-
ErrorNames = {'clamped' : Clamped,
'conversion_syntax' : InvalidOperation,
'division_by_zero' : DivisionByZero,
@@ -92,20 +90,62 @@
'half_down' : ROUND_HALF_DOWN,
'half_even' : ROUND_HALF_EVEN,
'half_up' : ROUND_HALF_UP,
- 'up' : ROUND_UP}
+ 'up' : ROUND_UP,
+ '05up' : ROUND_05UP}
# Name adapter to be able to change the Decimal and Context
# interface without changing the test files from Cowlishaw
nameAdapter = {'toeng':'to_eng_string',
'tosci':'to_sci_string',
'samequantum':'same_quantum',
- 'tointegral':'to_integral',
+ 'tointegral':'to_integral_value',
+ 'tointegralx':'to_integral_exact',
'remaindernear':'remainder_near',
'divideint':'divide_int',
'squareroot':'sqrt',
'apply':'_apply',
+ 'class':'number_class',
+ 'comparesig':'compare_signal',
+ 'comparetotal':'compare_total',
+ 'comparetotmag':'compare_total_mag',
+ 'copyabs':'copy_abs',
+ 'copy':'copy_decimal',
+ 'copynegate':'copy_negate',
+ 'copysign':'copy_sign',
+ 'and':'logical_and',
+ 'or':'logical_or',
+ 'xor':'logical_xor',
+ 'invert':'logical_invert',
+ 'maxmag':'max_mag',
+ 'minmag':'min_mag',
+ 'nextminus':'next_minus',
+ 'nextplus':'next_plus',
+ 'nexttoward':'next_toward',
+ 'reduce':'normalize',
}
+# For some operations (currently exp, ln, log10, power), the decNumber
+# reference implementation imposes additional restrictions on the
+# context and operands. These restrictions are not part of the
+# specification; however, the effect of these restrictions does show
+# up in some of the testcases. We skip testcases that violate these
+# restrictions, since Decimal behaves differently from decNumber for
+# these testcases so these testcases would otherwise fail.
+
+decNumberRestricted = ('power', 'ln', 'log10', 'exp')
+DEC_MAX_MATH = 999999
+def outside_decNumber_bounds(v, context):
+ if (context.prec > DEC_MAX_MATH or
+ context.Emax > DEC_MAX_MATH or
+ -context.Emin > DEC_MAX_MATH):
+ return True
+ if not v._is_special and v and (
+ len(v._int) > DEC_MAX_MATH or
+ v.adjusted() > DEC_MAX_MATH or
+ v.adjusted() < 1-2*DEC_MAX_MATH):
+ return True
+ return False
+
class DecimalTest(unittest.TestCase):
"""Class which tests the Decimal class against the test cases.
@@ -142,10 +182,6 @@
#print line
try:
t = self.eval_line(line)
- except InvalidOperation:
- print('Error in test cases:')
- print(line)
- continue
except DecimalException as exception:
#Exception raised where there shoudn't have been one.
self.fail('Exception "'+exception.__class__.__name__ + '" raised on line '+line)
@@ -194,7 +230,8 @@
Sides = s.split('->')
L = Sides[0].strip().split()
id = L[0]
-# print id,
+ if DEBUG:
+ print("Test ", id, end=" ")
funct = L[1].lower()
valstemp = L[2:]
L = Sides[1].strip().split()
@@ -246,11 +283,27 @@
self.context.traps[error] = 0
v = self.context.create_decimal(v)
else:
- v = Decimal(v)
+ v = Decimal(v, self.context)
vals.append(v)
ans = FixQuotes(ans)
+ # skip tests that are related to bounds imposed in the decNumber
+ # reference implementation
+ if fname in decNumberRestricted:
+ if fname == 'power':
+ if not (vals[1]._isinteger() and
+ -1999999997 <= vals[1] <= 999999999):
+ if outside_decNumber_bounds(vals[0], self.context) or \
+ outside_decNumber_bounds(vals[1], self.context):
+ #print "Skipping test %s" % s
+ return
+ else:
+ if outside_decNumber_bounds(vals[0], self.context):
+ #print "Skipping test %s" % s
+ return
+
+
if EXTENDEDERRORTEST and fname not in ('to_sci_string', 'to_eng_string'):
for error in theirexceptions:
self.context.traps[error] = 1
@@ -264,6 +317,8 @@
else:
self.fail("Did not raise %s in %s" % (error, s))
self.context.traps[error] = 0
+ if DEBUG:
+ print("--", self.context)
try:
result = str(funct(*vals))
if fname == 'same_quantum':
@@ -283,8 +338,7 @@
self.assertEqual(result, ans,
'Incorrect answer for ' + s + ' -- got ' + result)
self.assertEqual(myexceptions, theirexceptions,
- 'Incorrect flags set in ' + s + ' -- got ' \
- + str(myexceptions))
+ 'Incorrect flags set in ' + s + ' -- got ' + str(myexceptions))
return
def getexceptions(self):
@@ -301,17 +355,6 @@
def change_clamp(self, clamp):
self.context._clamp = clamp
-# Dynamically build custom test definition for each file in the test
-# directory and add the definitions to the DecimalTest class. This
-# procedure insures that new files do not get skipped.
-for filename in os.listdir(directory):
- if '.decTest' not in filename:
- continue
- head, tail = filename.split('.')
- tester = lambda self, f=filename: self.eval_file(directory + f)
- setattr(DecimalTest, 'test_' + head, tester)
- del filename, head, tail, tester
-
# The following classes test the behaviour of Decimal according to PEP 327
@@ -798,7 +841,7 @@
th2.start()
self.finish1.wait()
- self.finish1.wait()
+ self.finish2.wait()
return
if threading is None:
@@ -858,6 +901,38 @@
def test_hash_method(self):
#just that it's hashable
hash(Decimal(23))
+
+ test_values = [Decimal(sign*(2**m + n))
+ for m in [0, 14, 15, 16, 17, 30, 31,
+ 32, 33, 62, 63, 64, 65, 66]
+ for n in range(-10, 10)
+ for sign in [-1, 1]]
+ test_values.extend([
+ Decimal("-0"), # zeros
+ Decimal("0.00"),
+ Decimal("-0.000"),
+ Decimal("0E10"),
+ Decimal("-0E12"),
+ Decimal("10.0"), # negative exponent
+ Decimal("-23.00000"),
+ Decimal("1230E100"), # positive exponent
+ Decimal("-4.5678E50"),
+ # a value for which hash(n) != hash(n % (2**64-1))
+ # in Python pre-2.6
+ Decimal(2**64 + 2**32 - 1),
+ # selection of values which fail with the old (before
+ # version 2.6) long.__hash__
+ Decimal("1.634E100"),
+ Decimal("90.697E100"),
+ Decimal("188.83E100"),
+ Decimal("1652.9E100"),
+ Decimal("56531E100"),
+ ])
+
+ # check that hash(d) == hash(int(d)) for integral values
+ for value in test_values:
+ self.assertEqual(hash(value), hash(int(value)))
+
#the same hash that to an int
self.assertEqual(hash(Decimal(23)), hash(23))
self.assertRaises(TypeError, hash, Decimal('NaN'))
@@ -955,8 +1030,8 @@
d1 = Decimal('-25e55')
b1 = Decimal('-25e55')
- d2 = Decimal('33e-33')
- b2 = Decimal('33e-33')
+ d2 = Decimal('33e+33')
+ b2 = Decimal('33e+33')
def checkSameDec(operation, useOther=False):
if useOther:
@@ -987,7 +1062,6 @@
checkSameDec("__floordiv__", True)
checkSameDec("__hash__")
checkSameDec("__int__")
- checkSameDec("__long__")
checkSameDec("__mod__", True)
checkSameDec("__mul__", True)
checkSameDec("__neg__")
@@ -1018,6 +1092,21 @@
checkSameDec("to_eng_string")
checkSameDec("to_integral")
+ def test_subclassing(self):
+ # Different behaviours when subclassing Decimal
+
+ class MyDecimal(Decimal):
+ pass
+
+ d1 = MyDecimal(1)
+ d2 = MyDecimal(2)
+ d = d1 + d2
+ self.assertTrue(type(d) is Decimal)
+
+ d = d1.max(d2)
+ self.assertTrue(type(d) is Decimal)
+
+
class DecimalPythonAPItests(unittest.TestCase):
def test_pickle(self):
@@ -1084,7 +1173,59 @@
self.assert_(new_ctx is not set_ctx, 'did not copy the context')
self.assert_(set_ctx is enter_ctx, '__enter__ returned wrong context')
-def test_main(arith=False, verbose=None):
+class ContextFlags(unittest.TestCase):
+ def test_flags_irrelevant(self):
+ # check that the result (numeric result + flags raised) of an
+ # arithmetic operation doesn't depend on the current flags
+
+ context = Context(prec=9, Emin = -999999999, Emax = 999999999,
+ rounding=ROUND_HALF_EVEN, traps=[], flags=[])
+
+ # operations that raise various flags, in the form (function, arglist)
+ operations = [
+ (context._apply, [Decimal("100E-1000000009")]),
+ (context.sqrt, [Decimal(2)]),
+ (context.add, [Decimal("1.23456789"), Decimal("9.87654321")]),
+ (context.multiply, [Decimal("1.23456789"), Decimal("9.87654321")]),
+ (context.subtract, [Decimal("1.23456789"), Decimal("9.87654321")]),
+ ]
+
+ # try various flags individually, then a whole lot at once
+ flagsets = [[Inexact], [Rounded], [Underflow], [Clamped], [Subnormal],
+ [Inexact, Rounded, Underflow, Clamped, Subnormal]]
+
+ for fn, args in operations:
+ # find answer and flags raised using a clean context
+ context.clear_flags()
+ ans = fn(*args)
+ flags = [k for k, v in context.flags.items() if v]
+
+ for extra_flags in flagsets:
+ # set flags, before calling operation
+ context.clear_flags()
+ for flag in extra_flags:
+ context._raise_error(flag)
+ new_ans = fn(*args)
+
+ # flags that we expect to be set after the operation
+ expected_flags = list(flags)
+ for flag in extra_flags:
+ if flag not in expected_flags:
+ expected_flags.append(flag)
+ expected_flags.sort(key=id)
+
+ # flags we actually got
+ new_flags = [k for k,v in context.flags.items() if v]
+ new_flags.sort(key=id)
+
+ self.assertEqual(ans, new_ans,
+ "operation produces different answers depending on flags set: " +
+ "expected %s, got %s." % (ans, new_ans))
+ self.assertEqual(new_flags, expected_flags,
+ "operation raises different flags depending on flags set: " +
+ "expected %s, got %s" % (expected_flags, new_flags))
+
+def test_main(arith=False, verbose=None, todo_tests=None, debug=None):
""" Execute the tests.
Runs all arithmetic tests if arith is True or if the "decimal" resource
@@ -1092,35 +1233,58 @@
"""
init()
- global TEST_ALL
+ global TEST_ALL, DEBUG
TEST_ALL = arith or is_resource_enabled('decimal')
+ DEBUG = debug
+
+ if todo_tests is None:
+ test_classes = [
+ DecimalExplicitConstructionTest,
+ DecimalImplicitConstructionTest,
+ DecimalArithmeticOperatorsTest,
+ DecimalUseOfContextTest,
+ DecimalUsabilityTest,
+ DecimalPythonAPItests,
+ ContextAPItests,
+ DecimalTest,
+ WithStatementTest,
+ ContextFlags
+ ]
+ else:
+ test_classes = [DecimalTest]
+
+ # Dynamically build custom test definition for each file in the test
+ # directory and add the definitions to the DecimalTest class. This
+ # procedure insures that new files do not get skipped.
+ for filename in os.listdir(directory):
+ if '.decTest' not in filename or filename.startswith("."):
+ continue
+ head, tail = filename.split('.')
+ if todo_tests is not None and head not in todo_tests:
+ continue
+ tester = lambda self, f=filename: self.eval_file(directory + f)
+ setattr(DecimalTest, 'test_' + head, tester)
+ del filename, head, tail, tester
- test_classes = [
- DecimalExplicitConstructionTest,
- DecimalImplicitConstructionTest,
- DecimalArithmeticOperatorsTest,
- DecimalUseOfContextTest,
- DecimalUsabilityTest,
- DecimalPythonAPItests,
- ContextAPItests,
- DecimalTest,
- WithStatementTest,
- ]
try:
run_unittest(*test_classes)
- import decimal as DecimalModule
- run_doctest(DecimalModule, verbose)
+ if todo_tests is None:
+ import decimal as DecimalModule
+ run_doctest(DecimalModule, verbose)
finally:
setcontext(ORIGINAL_CONTEXT)
if __name__ == '__main__':
- # Calling with no arguments runs all tests.
- # Calling with "Skip" will skip over 90% of the arithmetic tests.
- if len(sys.argv) == 1:
- test_main(arith=True, verbose=True)
- elif len(sys.argv) == 2:
- arith = sys.argv[1].lower() != 'skip'
- test_main(arith=arith, verbose=True)
+ import optparse
+ p = optparse.OptionParser("test_decimal.py [--debug] [{--skip | test1 [test2 [...]]}]")
+ p.add_option('--debug', '-d', action='store_true', help='shows the test number and context before each test')
+ p.add_option('--skip', '-s', action='store_true', help='skip over 90% of the arithmetic tests')
+ (opt, args) = p.parse_args()
+
+ if opt.skip:
+ test_main(arith=False, verbose=True)
+ elif args:
+ test_main(arith=True, verbose=True, todo_tests=args, debug=opt.debug)
else:
- raise ValueError("test called with wrong arguments, use test_Decimal [Skip]")
+ test_main(arith=True, verbose=True)
Modified: python/branches/py3k-importlib/Lib/test/test_hash.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_hash.py (original)
+++ python/branches/py3k-importlib/Lib/test/test_hash.py Fri Sep 21 03:17:09 2007
@@ -18,10 +18,19 @@
def test_numeric_literals(self):
self.same_hash(1, 1, 1.0, 1.0+0.0j)
+ self.same_hash(0, 0.0, 0.0+0.0j)
+ self.same_hash(-1, -1.0, -1.0+0.0j)
+ self.same_hash(-2, -2.0, -2.0+0.0j)
def test_coerced_integers(self):
self.same_hash(int(1), int(1), float(1), complex(1),
int('1'), float('1.0'))
+ self.same_hash(int(-2**31), float(-2**31))
+ self.same_hash(int(1-2**31), float(1-2**31))
+ self.same_hash(int(2**31-1), float(2**31-1))
+ # for 64-bit platforms
+ self.same_hash(int(2**31), float(2**31))
+ self.same_hash(int(-2**63), float(-2**63))
def test_coerced_floats(self):
self.same_hash(int(1.23e300), float(1.23e300))
Modified: python/branches/py3k-importlib/Lib/test/test_re.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_re.py (original)
+++ python/branches/py3k-importlib/Lib/test/test_re.py Fri Sep 21 03:17:09 2007
@@ -83,6 +83,34 @@
self.assertEqual(re.sub('\r\n', '\n', 'abc\r\ndef\r\n'),
'abc\ndef\n')
+# This test makes no sense until re supports bytes, and should then probably
+# test for the *in*ability to mix bytes and str this way :)
+#
+# def test_bug_1140(self):
+# # re.sub(x, y, b'') should return b'', not '', and
+# # re.sub(x, y, '') should return '', not b''.
+# # Also:
+# # re.sub(x, y, str(x)) should return str(y), and
+# # re.sub(x, y, bytes(x)) should return
+# # str(y) if isinstance(y, str) else unicode(y).
+# for x in 'x', u'x':
+# for y in 'y', u'y':
+# z = re.sub(x, y, u'')
+# self.assertEqual(z, u'')
+# self.assertEqual(type(z), unicode)
+# #
+# z = re.sub(x, y, '')
+# self.assertEqual(z, '')
+# self.assertEqual(type(z), str)
+# #
+# z = re.sub(x, y, unicode(x))
+# self.assertEqual(z, y)
+# self.assertEqual(type(z), unicode)
+# #
+# z = re.sub(x, y, str(x))
+# self.assertEqual(z, y)
+# self.assertEqual(type(z), type(y))
+
def test_sub_template_numeric_escape(self):
# bug 776311 and friends
self.assertEqual(re.sub('x', r'\0', 'x'), '\0')
Modified: python/branches/py3k-importlib/Lib/test/test_repr.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_repr.py (original)
+++ python/branches/py3k-importlib/Lib/test/test_repr.py Fri Sep 21 03:17:09 2007
@@ -188,6 +188,16 @@
x = classmethod(C.foo)
self.failUnless(repr(x).startswith('<classmethod object at 0x'))
+ def test_unsortable(self):
+ # Repr.repr() used to call sorted() on sets, frozensets and dicts
+ # without taking into account that not all objects are comparable
+ x = set([1j, 2j, 3j])
+ y = frozenset(x)
+ z = {1j: 1, 2j: 2}
+ r(x)
+ r(y)
+ r(z)
+
def touch(path, text=''):
fp = open(path, 'w')
fp.write(text)
Modified: python/branches/py3k-importlib/Lib/test/test_socket_ssl.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_socket_ssl.py (original)
+++ python/branches/py3k-importlib/Lib/test/test_socket_ssl.py Fri Sep 21 03:17:09 2007
@@ -113,9 +113,9 @@
import os, httplib, ssl
with test_support.transient_internet():
s = socket.socket(socket.AF_INET)
- s.connect(("www.sf.net", 443))
+ s.connect(("svn.python.org", 443))
fd = s.fileno()
- sock = ssl.sslsocket(s)
+ sock = ssl.wrap_socket(s)
s = None
sock.close()
try:
Modified: python/branches/py3k-importlib/Lib/test/test_ssl.py
==============================================================================
--- python/branches/py3k-importlib/Lib/test/test_ssl.py (original)
+++ python/branches/py3k-importlib/Lib/test/test_ssl.py Fri Sep 21 03:17:09 2007
@@ -5,15 +5,17 @@
from test import test_support
import socket
import errno
-import threading
import subprocess
import time
import os
import pprint
-import urllib
+import urllib, urlparse
import shutil
import traceback
+from BaseHTTPServer import HTTPServer
+from SimpleHTTPServer import SimpleHTTPRequestHandler
+
# Optionally test SSL support, if we have it in the tested platform
skip_expected = False
try:
@@ -22,348 +24,863 @@
skip_expected = True
CERTFILE = None
+SVN_PYTHON_ORG_ROOT_CERT = None
+TESTPORT = 10025
def handle_error(prefix):
exc_format = ' '.join(traceback.format_exception(*sys.exc_info()))
- sys.stdout.write(prefix + exc_format)
+ if test_support.verbose:
+ sys.stdout.write(prefix + exc_format)
class BasicTests(unittest.TestCase):
- def testRudeShutdown(self):
- # Some random port to connect to.
- PORT = [9934]
-
- listener_ready = threading.Event()
- listener_gone = threading.Event()
-
- # `listener` runs in a thread. It opens a socket listening on
- # PORT, and sits in an accept() until the main thread connects.
- # Then it rudely closes the socket, and sets Event `listener_gone`
- # to let the main thread know the socket is gone.
- def listener():
- s = socket.socket()
- PORT[0] = test_support.bind_port(s, '', PORT[0])
- s.listen(5)
- listener_ready.set()
- s.accept()
- s = None # reclaim the socket object, which also closes it
- listener_gone.set()
-
- def connector():
- listener_ready.wait()
- s = socket.socket()
- s.connect(('localhost', PORT[0]))
- listener_gone.wait()
- try:
- ssl_sock = socket.ssl(s)
- except socket.sslerror:
- pass
- else:
- raise test_support.TestFailed(
- 'connecting to closed SSL socket should have failed')
-
- t = threading.Thread(target=listener)
- t.start()
- connector()
- t.join()
-
def testSSLconnect(self):
import os
- with test_support.transient_internet():
- s = ssl.sslsocket(socket.socket(socket.AF_INET),
- cert_reqs=ssl.CERT_NONE)
- s.connect(("pop.gmail.com", 995))
- c = s.getpeercert()
- if c:
- raise test_support.TestFailed("Peer cert %s shouldn't be here!")
+ s = ssl.wrap_socket(socket.socket(socket.AF_INET),
+ cert_reqs=ssl.CERT_NONE)
+ s.connect(("svn.python.org", 443))
+ c = s.getpeercert()
+ if c:
+ raise test_support.TestFailed("Peer cert %s shouldn't be here!")
+ s.close()
+
+ # this should fail because we have no verification certs
+ s = ssl.wrap_socket(socket.socket(socket.AF_INET),
+ cert_reqs=ssl.CERT_REQUIRED)
+ try:
+ s.connect(("svn.python.org", 443))
+ except ssl.SSLError:
+ pass
+ finally:
s.close()
- # this should fail because we have no verification certs
- s = ssl.sslsocket(socket.socket(socket.AF_INET),
- cert_reqs=ssl.CERT_REQUIRED)
- try:
- s.connect(("pop.gmail.com", 995))
- except ssl.sslerror:
- pass
- finally:
- s.close()
-
-class ConnectedTests(unittest.TestCase):
- def testTLSecho (self):
+ def testCrucialConstants(self):
+ ssl.PROTOCOL_SSLv2
+ ssl.PROTOCOL_SSLv23
+ ssl.PROTOCOL_SSLv3
+ ssl.PROTOCOL_TLSv1
+ ssl.CERT_NONE
+ ssl.CERT_OPTIONAL
+ ssl.CERT_REQUIRED
- s1 = socket.socket()
+ def testRAND(self):
+ v = ssl.RAND_status()
+ if test_support.verbose:
+ sys.stdout.write("\n RAND_status is %d (%s)\n"
+ % (v, (v and "sufficient randomness") or
+ "insufficient randomness"))
try:
- s1.connect(('127.0.0.1', 10024))
- except:
- handle_error("connection failure:\n")
- raise test_support.TestFailed("Can't connect to test server")
+ ssl.RAND_egd(1)
+ except TypeError:
+ pass
else:
- try:
- c1 = ssl.sslsocket(s1, ssl_version=ssl.PROTOCOL_TLSv1)
- except:
- handle_error("SSL handshake failure:\n")
- raise test_support.TestFailed("Can't SSL-handshake with test server")
- else:
- if not c1:
- raise test_support.TestFailed("Can't SSL-handshake with test server")
- indata = "FOO\n"
- c1.write(indata)
- outdata = c1.read()
- if outdata != indata.lower():
- raise test_support.TestFailed("bad data <<%s>> received; expected <<%s>>\n" % (data, indata.lower()))
- c1.close()
+ print("didn't raise TypeError")
+ ssl.RAND_add("this is a random string", 75.0)
- def testReadCert(self):
+ def testParseCert(self):
+ # note that this uses an 'unofficial' function in _ssl.c,
+ # provided solely for this test, to exercise the certificate
+ # parsing code
+ p = ssl._ssl._test_decode_cert(CERTFILE, False)
+ if test_support.verbose:
+ sys.stdout.write("\n" + pprint.pformat(p) + "\n")
- s2 = socket.socket()
+ def testDERtoPEM(self):
+
+ pem = open(SVN_PYTHON_ORG_ROOT_CERT, 'r').read()
+ d1 = ssl.PEM_cert_to_DER_cert(pem)
+ p2 = ssl.DER_cert_to_PEM_cert(d1)
+ d2 = ssl.PEM_cert_to_DER_cert(p2)
+ if (d1 != d2):
+ raise test_support.TestFailed("PEM-to-DER or DER-to-PEM translation failed")
+
+
+class NetworkTests(unittest.TestCase):
+
+ def testConnect(self):
+ import os
+ s = ssl.wrap_socket(socket.socket(socket.AF_INET),
+ cert_reqs=ssl.CERT_NONE)
+ s.connect(("svn.python.org", 443))
+ c = s.getpeercert()
+ if c:
+ raise test_support.TestFailed("Peer cert %s shouldn't be here!")
+ s.close()
+
+ # this should fail because we have no verification certs
+ s = ssl.wrap_socket(socket.socket(socket.AF_INET),
+ cert_reqs=ssl.CERT_REQUIRED)
try:
- s2.connect(('127.0.0.1', 10024))
- except:
- handle_error("connection failure:\n")
- raise test_support.TestFailed("Can't connect to test server")
+ s.connect(("svn.python.org", 443))
+ except ssl.SSLError:
+ pass
+ finally:
+ s.close()
+
+ # this should succeed because we specify the root cert
+ s = ssl.wrap_socket(socket.socket(socket.AF_INET),
+ cert_reqs=ssl.CERT_REQUIRED,
+ ca_certs=SVN_PYTHON_ORG_ROOT_CERT)
+ try:
+ s.connect(("svn.python.org", 443))
+ except ssl.SSLError as x:
+ raise test_support.TestFailed("Unexpected exception %s" % x)
+ finally:
+ s.close()
+
+ def testFetchServerCert(self):
+
+ pem = ssl.get_server_certificate(("svn.python.org", 443))
+ if not pem:
+ raise test_support.TestFailed("No server certificate on svn.python.org:443!")
+
+ try:
+ pem = ssl.get_server_certificate(("svn.python.org", 443), ca_certs=CERTFILE)
+ except ssl.SSLError:
+ #should fail
+ pass
else:
- try:
- c2 = ssl.sslsocket(s2, ssl_version=ssl.PROTOCOL_TLSv1,
- cert_reqs=ssl.CERT_REQUIRED, ca_certs=CERTFILE)
- except:
- handle_error("SSL handshake failure:\n")
- raise test_support.TestFailed("Can't SSL-handshake with test server")
- else:
- if not c2:
- raise test_support.TestFailed("Can't SSL-handshake with test server")
- cert = c2.getpeercert()
- if not cert:
- raise test_support.TestFailed("Can't get peer certificate.")
- if test_support.verbose:
- sys.stdout.write(pprint.pformat(cert) + '\n')
- if not cert.has_key('subject'):
- raise test_support.TestFailed(
- "No subject field in certificate: %s." %
- pprint.pformat(cert))
- if not ('organizationName', 'Python Software Foundation') in cert['subject']:
- raise test_support.TestFailed(
- "Missing or invalid 'organizationName' field in certificate subject; "
- "should be 'Python Software Foundation'.");
- c2.close()
+ raise test_support.TestFailed("Got server certificate %s for svn.python.org!" % pem)
+ pem = ssl.get_server_certificate(("svn.python.org", 443), ca_certs=SVN_PYTHON_ORG_ROOT_CERT)
+ if not pem:
+ raise test_support.TestFailed("No server certificate on svn.python.org:443!")
+ if test_support.verbose:
+ sys.stdout.write("\nVerified certificate for svn.python.org:443 is\n%s\n" % pem)
-class ThreadedEchoServer(threading.Thread):
- class ConnectionHandler(threading.Thread):
+try:
+ import threading
+except ImportError:
+ _have_threads = False
+else:
- def __init__(self, server, connsock):
- self.server = server
- self.running = False
- self.sock = connsock
- threading.Thread.__init__(self)
- self.setDaemon(True)
+ _have_threads = True
- def run (self):
- self.running = True
- try:
- sslconn = ssl.sslsocket(self.sock, server_side=True,
- certfile=self.server.certificate,
- ssl_version=self.server.protocol,
- cert_reqs=self.server.certreqs)
- except:
- # here, we want to stop the server, because this shouldn't
- # happen in the context of our test case
- handle_error("Test server failure:\n")
+ class ThreadedEchoServer(threading.Thread):
+
+ class ConnectionHandler(threading.Thread):
+
+ """A mildly complicated class, because we want it to work both
+ with and without the SSL wrapper around the socket connection, so
+ that we can test the STARTTLS functionality."""
+
+ def __init__(self, server, connsock):
+ self.server = server
self.running = False
- # normally, we'd just stop here, but for the test
- # harness, we want to stop the server
- self.server.stop()
- return
+ self.sock = connsock
+ self.sock.setblocking(1)
+ self.sslconn = None
+ threading.Thread.__init__(self)
+ self.setDaemon(True)
- while self.running:
+ def wrap_conn (self):
try:
- msg = sslconn.read()
- if not msg:
- # eof, so quit this handler
+ self.sslconn = ssl.wrap_socket(self.sock, server_side=True,
+ certfile=self.server.certificate,
+ ssl_version=self.server.protocol,
+ ca_certs=self.server.cacerts,
+ cert_reqs=self.server.certreqs)
+ except:
+ if self.server.chatty:
+ handle_error("\n server: bad connection attempt from " +
+ str(self.sock.getpeername()) + ":\n")
+ if not self.server.expect_bad_connects:
+ # here, we want to stop the server, because this shouldn't
+ # happen in the context of our test case
self.running = False
- sslconn.close()
- elif msg.strip() == 'over':
- sslconn.close()
+ # normally, we'd just stop here, but for the test
+ # harness, we want to stop the server
self.server.stop()
+ return False
+
+ else:
+ if self.server.certreqs == ssl.CERT_REQUIRED:
+ cert = self.sslconn.getpeercert()
+ if test_support.verbose and self.server.chatty:
+ sys.stdout.write(" client cert is " + pprint.pformat(cert) + "\n")
+ cert_binary = self.sslconn.getpeercert(True)
+ if test_support.verbose and self.server.chatty:
+ sys.stdout.write(" cert binary is " + str(len(cert_binary)) + " bytes\n")
+ cipher = self.sslconn.cipher()
+ if test_support.verbose and self.server.chatty:
+ sys.stdout.write(" server: connection cipher is now " + str(cipher) + "\n")
+ return True
+
+ def read(self):
+ if self.sslconn:
+ return self.sslconn.read()
+ else:
+ return self.sock.recv(1024)
+
+ def write(self, bytes):
+ if self.sslconn:
+ return self.sslconn.write(bytes)
+ else:
+ return self.sock.send(bytes)
+
+ def close(self):
+ if self.sslconn:
+ self.sslconn.close()
+ else:
+ self.sock.close()
+
+ def run (self):
+ self.running = True
+ if not self.server.starttls_server:
+ if not self.wrap_conn():
+ return
+ while self.running:
+ try:
+ msg = self.read()
+ if not msg:
+ # eof, so quit this handler
+ self.running = False
+ self.close()
+ elif msg.strip() == 'over':
+ if test_support.verbose and self.server.connectionchatty:
+ sys.stdout.write(" server: client closed connection\n")
+ self.close()
+ return
+ elif self.server.starttls_server and msg.strip() == 'STARTTLS':
+ if test_support.verbose and self.server.connectionchatty:
+ sys.stdout.write(" server: read STARTTLS from client, sending OK...\n")
+ self.write("OK\n")
+ if not self.wrap_conn():
+ return
+ else:
+ if (test_support.verbose and
+ self.server.connectionchatty):
+ ctype = (self.sslconn and "encrypted") or "unencrypted"
+ sys.stdout.write(" server: read %s (%s), sending back %s (%s)...\n"
+ % (repr(msg), ctype, repr(msg.lower()), ctype))
+ self.write(msg.lower())
+ except ssl.SSLError:
+ if self.server.chatty:
+ handle_error("Test server failure:\n")
+ self.close()
self.running = False
- else:
- if test_support.verbose:
- sys.stdout.write("\nserver: %s\n" % msg.strip().lower())
- sslconn.write(msg.lower())
- except ssl.sslerror:
- handle_error("Test server failure:\n")
- sslconn.close()
- self.running = False
- # normally, we'd just stop here, but for the test
- # harness, we want to stop the server
- self.server.stop()
+ # normally, we'd just stop here, but for the test
+ # harness, we want to stop the server
+ self.server.stop()
+ except:
+ handle_error('')
+
+ def __init__(self, port, certificate, ssl_version=None,
+ certreqs=None, cacerts=None, expect_bad_connects=False,
+ chatty=True, connectionchatty=False, starttls_server=False):
+ if ssl_version is None:
+ ssl_version = ssl.PROTOCOL_TLSv1
+ if certreqs is None:
+ certreqs = ssl.CERT_NONE
+ self.certificate = certificate
+ self.protocol = ssl_version
+ self.certreqs = certreqs
+ self.cacerts = cacerts
+ self.expect_bad_connects = expect_bad_connects
+ self.chatty = chatty
+ self.connectionchatty = connectionchatty
+ self.starttls_server = starttls_server
+ self.sock = socket.socket()
+ self.flag = None
+ if hasattr(socket, 'SO_REUSEADDR'):
+ self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+ if hasattr(socket, 'SO_REUSEPORT'):
+ self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
+ self.sock.bind(('127.0.0.1', port))
+ self.active = False
+ threading.Thread.__init__(self)
+ self.setDaemon(False)
+
+ def start (self, flag=None):
+ self.flag = flag
+ threading.Thread.start(self)
+
+ def run (self):
+ self.sock.settimeout(0.5)
+ self.sock.listen(5)
+ self.active = True
+ if self.flag:
+ # signal an event
+ self.flag.set()
+ while self.active:
+ try:
+ newconn, connaddr = self.sock.accept()
+ if test_support.verbose and self.chatty:
+ sys.stdout.write(' server: new connection from '
+ + str(connaddr) + '\n')
+ handler = self.ConnectionHandler(self, newconn)
+ handler.start()
+ except socket.timeout:
+ pass
+ except KeyboardInterrupt:
+ self.stop()
except:
- handle_error('')
+ if self.chatty:
+ handle_error("Test server failure:\n")
+
+ def stop (self):
+ self.active = False
+ self.sock.close()
+
+
+ class AsyncoreHTTPSServer(threading.Thread):
+
+ class HTTPSServer(HTTPServer):
+
+ def __init__(self, server_address, RequestHandlerClass, certfile):
+
+ HTTPServer.__init__(self, server_address, RequestHandlerClass)
+ # we assume the certfile contains both private key and certificate
+ self.certfile = certfile
+ self.active = False
+ self.allow_reuse_address = True
+
+ def get_request (self):
+ # override this to wrap socket with SSL
+ sock, addr = self.socket.accept()
+ sslconn = ssl.wrap_socket(sock, server_side=True,
+ certfile=self.certfile)
+ return sslconn, addr
+
+ # The methods overridden below this are mainly so that we
+ # can run it in a thread and be able to stop it from another
+ # You probably wouldn't need them in other uses.
+
+ def server_activate(self):
+ # We want to run this in a thread for testing purposes,
+ # so we override this to set timeout, so that we get
+ # a chance to stop the server
+ self.socket.settimeout(0.5)
+ HTTPServer.server_activate(self)
+
+ def serve_forever(self):
+ # We want this to run in a thread, so we use a slightly
+ # modified version of "forever".
+ self.active = True
+ while self.active:
+ try:
+ self.handle_request()
+ except socket.timeout:
+ pass
+ except KeyboardInterrupt:
+ self.server_close()
+ return
+ except:
+ sys.stdout.write(''.join(traceback.format_exception(*sys.exc_info())));
+
+ def server_close(self):
+ # Again, we want this to run in a thread, so we need to override
+ # close to clear the "active" flag, so that serve_forever() will
+ # terminate.
+ HTTPServer.server_close(self)
+ self.active = False
+
+ class RootedHTTPRequestHandler(SimpleHTTPRequestHandler):
+
+ # need to override translate_path to get a known root,
+ # instead of using os.curdir, since the test could be
+ # run from anywhere
+
+ server_version = "TestHTTPS/1.0"
+
+ root = None
+
+ def translate_path(self, path):
+ """Translate a /-separated PATH to the local filename syntax.
+
+ Components that mean special things to the local file system
+ (e.g. drive or directory names) are ignored. (XXX They should
+ probably be diagnosed.)
+
+ """
+ # abandon query parameters
+ path = urlparse.urlparse(path)[2]
+ path = os.path.normpath(urllib.unquote(path))
+ words = path.split('/')
+ words = filter(None, words)
+ path = self.root
+ for word in words:
+ drive, word = os.path.splitdrive(word)
+ head, word = os.path.split(word)
+ if word in self.root: continue
+ path = os.path.join(path, word)
+ return path
+
+ def log_message(self, format, *args):
+
+ # we override this to suppress logging unless "verbose"
+
+ if test_support.verbose:
+ sys.stdout.write(" server (%s, %d, %s):\n [%s] %s\n" %
+ (self.server.server_name,
+ self.server.server_port,
+ self.request.cipher(),
+ self.log_date_time_string(),
+ format%args))
+
+
+ def __init__(self, port, certfile):
+ self.flag = None
+ self.active = False
+ self.RootedHTTPRequestHandler.root = os.path.split(CERTFILE)[0]
+ self.server = self.HTTPSServer(
+ ('', port), self.RootedHTTPRequestHandler, certfile)
+ threading.Thread.__init__(self)
+ self.setDaemon(True)
- def __init__(self, port, certificate, ssl_version=None,
- certreqs=None, cacerts=None):
- if ssl_version is None:
- ssl_version = ssl.PROTOCOL_TLSv1
- if certreqs is None:
- certreqs = ssl.CERT_NONE
- self.certificate = certificate
- self.protocol = ssl_version
- self.certreqs = certreqs
- self.cacerts = cacerts
- self.sock = socket.socket()
- self.flag = None
- if hasattr(socket, 'SO_REUSEADDR'):
- self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
- if hasattr(socket, 'SO_REUSEPORT'):
- self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
- self.sock.bind(('127.0.0.1', port))
- self.active = False
- threading.Thread.__init__(self)
- self.setDaemon(False)
-
- def start (self, flag=None):
- self.flag = flag
- threading.Thread.start(self)
-
- def run (self):
- self.sock.settimeout(0.5)
- self.sock.listen(5)
- self.active = True
- if self.flag:
- # signal an event
- self.flag.set()
- while self.active:
+ def __str__(self):
+ return '<%s %s:%d>' % (self.__class__.__name__,
+ self.server.server_name,
+ self.server.server_port)
+
+ def start (self, flag=None):
+ self.flag = flag
+ threading.Thread.start(self)
+
+ def run (self):
+ self.active = True
+ if self.flag:
+ self.flag.set()
+ self.server.serve_forever()
+ self.active = False
+
+ def stop (self):
+ self.active = False
+ self.server.server_close()
+
+
+ def badCertTest (certfile):
+ server = ThreadedEchoServer(TESTPORT, CERTFILE,
+ certreqs=ssl.CERT_REQUIRED,
+ cacerts=CERTFILE, chatty=False)
+ flag = threading.Event()
+ server.start(flag)
+ # wait for it to start
+ flag.wait()
+ # try to connect
+ try:
try:
- newconn, connaddr = self.sock.accept()
+ s = ssl.wrap_socket(socket.socket(),
+ certfile=certfile,
+ ssl_version=ssl.PROTOCOL_TLSv1)
+ s.connect(('127.0.0.1', TESTPORT))
+ except ssl.SSLError as x:
if test_support.verbose:
- sys.stdout.write('\nserver: new connection from ' + str(connaddr) + '\n')
- handler = self.ConnectionHandler(self, newconn)
- handler.start()
- except socket.timeout:
- pass
- except KeyboardInterrupt:
- self.stop()
- except:
- handle_error("Test server failure:\n")
+ sys.stdout.write("\nSSLError is %s\n" % x[1])
+ else:
+ raise test_support.TestFailed(
+ "Use of invalid cert should have failed!")
+ finally:
+ server.stop()
+ server.join()
+
+ def serverParamsTest (certfile, protocol, certreqs, cacertsfile,
+ client_certfile, client_protocol=None, indata="FOO\n",
+ chatty=True, connectionchatty=False):
+
+ server = ThreadedEchoServer(TESTPORT, certfile,
+ certreqs=certreqs,
+ ssl_version=protocol,
+ cacerts=cacertsfile,
+ chatty=chatty,
+ connectionchatty=connectionchatty)
+ flag = threading.Event()
+ server.start(flag)
+ # wait for it to start
+ flag.wait()
+ # try to connect
+ if client_protocol is None:
+ client_protocol = protocol
+ try:
+ try:
+ s = ssl.wrap_socket(socket.socket(),
+ certfile=client_certfile,
+ ca_certs=cacertsfile,
+ cert_reqs=certreqs,
+ ssl_version=client_protocol)
+ s.connect(('127.0.0.1', TESTPORT))
+ except ssl.SSLError as x:
+ raise test_support.TestFailed("Unexpected SSL error: " + str(x))
+ except Exception as x:
+ raise test_support.TestFailed("Unexpected exception: " + str(x))
+ else:
+ if connectionchatty:
+ if test_support.verbose:
+ sys.stdout.write(
+ " client: sending %s...\n" % (repr(indata)))
+ s.write(indata)
+ outdata = s.read()
+ if connectionchatty:
+ if test_support.verbose:
+ sys.stdout.write(" client: read %s\n" % repr(outdata))
+ if outdata != indata.lower():
+ raise test_support.TestFailed(
+ "bad data <<%s>> (%d) received; expected <<%s>> (%d)\n"
+ % (outdata[:min(len(outdata),20)], len(outdata),
+ indata[:min(len(indata),20)].lower(), len(indata)))
+ s.write("over\n")
+ if connectionchatty:
+ if test_support.verbose:
+ sys.stdout.write(" client: closing connection.\n")
+ s.close()
+ finally:
+ server.stop()
+ server.join()
- def stop (self):
- self.active = False
- self.sock.close()
-
-CERTFILE_CONFIG_TEMPLATE = """
-# create RSA certs - Server
-
-[ req ]
-default_bits = 1024
-encrypt_key = yes
-distinguished_name = req_dn
-x509_extensions = cert_type
-
-[ req_dn ]
-countryName = Country Name (2 letter code)
-countryName_default = US
-countryName_min = 2
-countryName_max = 2
-
-stateOrProvinceName = State or Province Name (full name)
-stateOrProvinceName_default = %(state)s
-
-localityName = Locality Name (eg, city)
-localityName_default = %(city)s
-
-0.organizationName = Organization Name (eg, company)
-0.organizationName_default = %(organization)s
-
-organizationalUnitName = Organizational Unit Name (eg, section)
-organizationalUnitName_default = %(unit)s
-
-0.commonName = Common Name (FQDN of your server)
-0.commonName_default = %(common-name)s
-
-# To create a certificate for more than one name uncomment:
-# 1.commonName = DNS alias of your server
-# 2.commonName = DNS alias of your server
-# ...
-# See http://home.netscape.com/eng/security/ssl_2.0_certificate.html
-# to see how Netscape understands commonName.
-
-[ cert_type ]
-nsCertType = server
-"""
-
-def create_cert_files(hostname=None):
-
- """This is the routine that was run to create the certificate
- and private key contained in keycert.pem."""
-
- import tempfile, socket, os
- d = tempfile.mkdtemp()
- # now create a configuration file for the CA signing cert
- fqdn = hostname or socket.getfqdn()
- crtfile = os.path.join(d, "cert.pem")
- conffile = os.path.join(d, "ca.conf")
- fp = open(conffile, "w")
- fp.write(CERTFILE_CONFIG_TEMPLATE %
- {'state': "Delaware",
- 'city': "Wilmington",
- 'organization': "Python Software Foundation",
- 'unit': "SSL",
- 'common-name': fqdn,
- })
- fp.close()
- error = os.system(
- "openssl req -batch -new -x509 -days 2000 -nodes -config %s "
- "-keyout \"%s\" -out \"%s\" > /dev/null < /dev/null 2>&1" %
- (conffile, crtfile, crtfile))
- # now we have a self-signed server cert in crtfile
- os.unlink(conffile)
- if (os.WEXITSTATUS(error) or
- not os.path.exists(crtfile) or os.path.getsize(crtfile) == 0):
+ def tryProtocolCombo (server_protocol,
+ client_protocol,
+ expectedToWork,
+ certsreqs=None):
+
+ if certsreqs == None:
+ certsreqs = ssl.CERT_NONE
+
+ if certsreqs == ssl.CERT_NONE:
+ certtype = "CERT_NONE"
+ elif certsreqs == ssl.CERT_OPTIONAL:
+ certtype = "CERT_OPTIONAL"
+ elif certsreqs == ssl.CERT_REQUIRED:
+ certtype = "CERT_REQUIRED"
if test_support.verbose:
- sys.stdout.write("Unable to create certificate for test, "
- + "error status %d\n" % (error >> 8))
- crtfile = None
- elif test_support.verbose:
- sys.stdout.write(open(crtfile, 'r').read() + '\n')
- return d, crtfile
+ formatstr = (expectedToWork and " %s->%s %s\n") or " {%s->%s} %s\n"
+ sys.stdout.write(formatstr %
+ (ssl.get_protocol_name(client_protocol),
+ ssl.get_protocol_name(server_protocol),
+ certtype))
+ try:
+ serverParamsTest(CERTFILE, server_protocol, certsreqs,
+ CERTFILE, CERTFILE, client_protocol, chatty=False)
+ except test_support.TestFailed:
+ if expectedToWork:
+ raise
+ else:
+ if not expectedToWork:
+ raise test_support.TestFailed(
+ "Client protocol %s succeeded with server protocol %s!"
+ % (ssl.get_protocol_name(client_protocol),
+ ssl.get_protocol_name(server_protocol)))
+
+
+ class ConnectedTests(unittest.TestCase):
+
+ def testRudeShutdown(self):
+
+ listener_ready = threading.Event()
+ listener_gone = threading.Event()
+
+ # `listener` runs in a thread. It opens a socket listening on
+ # PORT, and sits in an accept() until the main thread connects.
+ # Then it rudely closes the socket, and sets Event `listener_gone`
+ # to let the main thread know the socket is gone.
+ def listener():
+ s = socket.socket()
+ if hasattr(socket, 'SO_REUSEADDR'):
+ s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+ if hasattr(socket, 'SO_REUSEPORT'):
+ s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
+ s.bind(('127.0.0.1', TESTPORT))
+ s.listen(5)
+ listener_ready.set()
+ s.accept()
+ s = None # reclaim the socket object, which also closes it
+ listener_gone.set()
+
+ def connector():
+ listener_ready.wait()
+ s = socket.socket()
+ s.connect(('127.0.0.1', TESTPORT))
+ listener_gone.wait()
+ try:
+ ssl_sock = ssl.wrap_socket(s)
+ except socket.sslerror:
+ pass
+ else:
+ raise test_support.TestFailed(
+ 'connecting to closed SSL socket should have failed')
+
+ t = threading.Thread(target=listener)
+ t.start()
+ connector()
+ t.join()
+
+ def testEcho (self):
+
+ if test_support.verbose:
+ sys.stdout.write("\n")
+ serverParamsTest(CERTFILE, ssl.PROTOCOL_TLSv1, ssl.CERT_NONE,
+ CERTFILE, CERTFILE, ssl.PROTOCOL_TLSv1,
+ chatty=True, connectionchatty=True)
+
+ def testReadCert(self):
+
+ if test_support.verbose:
+ sys.stdout.write("\n")
+ s2 = socket.socket()
+ server = ThreadedEchoServer(TESTPORT, CERTFILE,
+ certreqs=ssl.CERT_NONE,
+ ssl_version=ssl.PROTOCOL_SSLv23,
+ cacerts=CERTFILE,
+ chatty=False)
+ flag = threading.Event()
+ server.start(flag)
+ # wait for it to start
+ flag.wait()
+ # try to connect
+ try:
+ try:
+ s = ssl.wrap_socket(socket.socket(),
+ certfile=CERTFILE,
+ ca_certs=CERTFILE,
+ cert_reqs=ssl.CERT_REQUIRED,
+ ssl_version=ssl.PROTOCOL_SSLv23)
+ s.connect(('127.0.0.1', TESTPORT))
+ except ssl.SSLError as x:
+ raise test_support.TestFailed(
+ "Unexpected SSL error: " + str(x))
+ except Exception as x:
+ raise test_support.TestFailed(
+ "Unexpected exception: " + str(x))
+ else:
+ if not s:
+ raise test_support.TestFailed(
+ "Can't SSL-handshake with test server")
+ cert = s.getpeercert()
+ if not cert:
+ raise test_support.TestFailed(
+ "Can't get peer certificate.")
+ cipher = s.cipher()
+ if test_support.verbose:
+ sys.stdout.write(pprint.pformat(cert) + '\n')
+ sys.stdout.write("Connection cipher is " + str(cipher) + '.\n')
+ if not cert.has_key('subject'):
+ raise test_support.TestFailed(
+ "No subject field in certificate: %s." %
+ pprint.pformat(cert))
+ if ((('organizationName', 'Python Software Foundation'),)
+ not in cert['subject']):
+ raise test_support.TestFailed(
+ "Missing or invalid 'organizationName' field in certificate subject; "
+ "should be 'Python Software Foundation'.");
+ s.close()
+ finally:
+ server.stop()
+ server.join()
+
+ def testNULLcert(self):
+ badCertTest(os.path.join(os.path.dirname(__file__) or os.curdir,
+ "nullcert.pem"))
+ def testMalformedCert(self):
+ badCertTest(os.path.join(os.path.dirname(__file__) or os.curdir,
+ "badcert.pem"))
+ def testMalformedKey(self):
+ badCertTest(os.path.join(os.path.dirname(__file__) or os.curdir,
+ "badkey.pem"))
+
+ def testProtocolSSL2(self):
+ if test_support.verbose:
+ sys.stdout.write("\n")
+ tryProtocolCombo(ssl.PROTOCOL_SSLv2, ssl.PROTOCOL_SSLv2, True)
+ tryProtocolCombo(ssl.PROTOCOL_SSLv2, ssl.PROTOCOL_SSLv2, True, ssl.CERT_OPTIONAL)
+ tryProtocolCombo(ssl.PROTOCOL_SSLv2, ssl.PROTOCOL_SSLv2, True, ssl.CERT_REQUIRED)
+ tryProtocolCombo(ssl.PROTOCOL_SSLv2, ssl.PROTOCOL_SSLv23, True)
+ tryProtocolCombo(ssl.PROTOCOL_SSLv2, ssl.PROTOCOL_SSLv3, False)
+ tryProtocolCombo(ssl.PROTOCOL_SSLv2, ssl.PROTOCOL_TLSv1, False)
+
+ def testProtocolSSL23(self):
+ if test_support.verbose:
+ sys.stdout.write("\n")
+ try:
+ tryProtocolCombo(ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_SSLv2, True)
+ except test_support.TestFailed as x:
+ # this fails on some older versions of OpenSSL (0.9.7l, for instance)
+ if test_support.verbose:
+ sys.stdout.write(
+ " SSL2 client to SSL23 server test unexpectedly failed:\n %s\n"
+ % str(x))
+ tryProtocolCombo(ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_SSLv3, True)
+ tryProtocolCombo(ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_SSLv23, True)
+ tryProtocolCombo(ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_TLSv1, True)
+
+ tryProtocolCombo(ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_SSLv3, True, ssl.CERT_OPTIONAL)
+ tryProtocolCombo(ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_SSLv23, True, ssl.CERT_OPTIONAL)
+ tryProtocolCombo(ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_TLSv1, True, ssl.CERT_OPTIONAL)
+
+ tryProtocolCombo(ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_SSLv3, True, ssl.CERT_REQUIRED)
+ tryProtocolCombo(ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_SSLv23, True, ssl.CERT_REQUIRED)
+ tryProtocolCombo(ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_TLSv1, True, ssl.CERT_REQUIRED)
+
+ def testProtocolSSL3(self):
+ if test_support.verbose:
+ sys.stdout.write("\n")
+ tryProtocolCombo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_SSLv3, True)
+ tryProtocolCombo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_SSLv3, True, ssl.CERT_OPTIONAL)
+ tryProtocolCombo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_SSLv3, True, ssl.CERT_REQUIRED)
+ tryProtocolCombo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_SSLv2, False)
+ tryProtocolCombo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_SSLv23, False)
+ tryProtocolCombo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_TLSv1, False)
+
+ def testProtocolTLS1(self):
+ if test_support.verbose:
+ sys.stdout.write("\n")
+ tryProtocolCombo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_TLSv1, True)
+ tryProtocolCombo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_TLSv1, True, ssl.CERT_OPTIONAL)
+ tryProtocolCombo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_TLSv1, True, ssl.CERT_REQUIRED)
+ tryProtocolCombo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_SSLv2, False)
+ tryProtocolCombo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_SSLv3, False)
+ tryProtocolCombo(ssl.PROTOCOL_TLSv1, ssl.PROTOCOL_SSLv23, False)
+
+ def testSTARTTLS (self):
+
+ msgs = ("msg 1", "MSG 2", "STARTTLS", "MSG 3", "msg 4")
+
+ server = ThreadedEchoServer(TESTPORT, CERTFILE,
+ ssl_version=ssl.PROTOCOL_TLSv1,
+ starttls_server=True,
+ chatty=True,
+ connectionchatty=True)
+ flag = threading.Event()
+ server.start(flag)
+ # wait for it to start
+ flag.wait()
+ # try to connect
+ wrapped = False
+ try:
+ try:
+ s = socket.socket()
+ s.setblocking(1)
+ s.connect(('127.0.0.1', TESTPORT))
+ except Exception as x:
+ raise test_support.TestFailed("Unexpected exception: " + str(x))
+ else:
+ if test_support.verbose:
+ sys.stdout.write("\n")
+ for indata in msgs:
+ if test_support.verbose:
+ sys.stdout.write(
+ " client: sending %s...\n" % repr(indata))
+ if wrapped:
+ conn.write(indata)
+ outdata = conn.read()
+ else:
+ s.send(indata)
+ outdata = s.recv(1024)
+ if (indata == "STARTTLS" and
+ outdata.strip().lower().startswith("ok")):
+ if test_support.verbose:
+ sys.stdout.write(
+ " client: read %s from server, starting TLS...\n"
+ % repr(outdata))
+ conn = ssl.wrap_socket(s, ssl_version=ssl.PROTOCOL_TLSv1)
+
+ wrapped = True
+ else:
+ if test_support.verbose:
+ sys.stdout.write(
+ " client: read %s from server\n" % repr(outdata))
+ if test_support.verbose:
+ sys.stdout.write(" client: closing connection.\n")
+ if wrapped:
+ conn.write("over\n")
+ else:
+ s.send("over\n")
+ s.close()
+ finally:
+ server.stop()
+ server.join()
+
+ def testAsyncore(self):
+
+ server = AsyncoreHTTPSServer(TESTPORT, CERTFILE)
+ flag = threading.Event()
+ server.start(flag)
+ # wait for it to start
+ flag.wait()
+ # try to connect
+ try:
+ if test_support.verbose:
+ sys.stdout.write('\n')
+ d1 = open(CERTFILE, 'rb').read()
+ d2 = ''
+ # now fetch the same data from the HTTPS server
+ url = 'https://127.0.0.1:%d/%s' % (
+ TESTPORT, os.path.split(CERTFILE)[1])
+ f = urllib.urlopen(url)
+ dlen = f.info().getheader("content-length")
+ if dlen and (int(dlen) > 0):
+ d2 = f.read(int(dlen))
+ if test_support.verbose:
+ sys.stdout.write(
+ " client: read %d bytes from remote server '%s'\n"
+ % (len(d2), server))
+ f.close()
+ except:
+ msg = ''.join(traceback.format_exception(*sys.exc_info()))
+ if test_support.verbose:
+ sys.stdout.write('\n' + msg)
+ raise test_support.TestFailed(msg)
+ else:
+ if not (d1 == d2):
+ raise test_support.TestFailed(
+ "Couldn't fetch data from HTTPS server")
+ finally:
+ server.stop()
+ server.join()
+
+
+def findtestsocket(start, end):
+ def testbind(i):
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ try:
+ s.bind(("127.0.0.1", i))
+ except:
+ return 0
+ else:
+ return 1
+ finally:
+ s.close()
+
+ for i in range(start, end):
+ if testbind(i) and testbind(i+1):
+ return i
+ return 0
def test_main(verbose=False):
if skip_expected:
raise test_support.TestSkipped("No SSL support")
- global CERTFILE
+ global CERTFILE, TESTPORT, SVN_PYTHON_ORG_ROOT_CERT
CERTFILE = os.path.join(os.path.dirname(__file__) or os.curdir,
"keycert.pem")
- if not CERTFILE:
- sys.__stdout__.write("Skipping test_ssl ConnectedTests; "
- "couldn't create a certificate.\n")
+ SVN_PYTHON_ORG_ROOT_CERT = os.path.join(
+ os.path.dirname(__file__) or os.curdir,
+ "https_svn_python_org_root.pem")
+
+ if (not os.path.exists(CERTFILE) or
+ not os.path.exists(SVN_PYTHON_ORG_ROOT_CERT)):
+ raise test_support.TestFailed("Can't read certificate files!")
+ TESTPORT = findtestsocket(10025, 12000)
+ if not TESTPORT:
+ raise test_support.TestFailed("Can't find open port to test servers on!")
tests = [BasicTests]
- server = None
- if CERTFILE and test_support.is_resource_enabled('network'):
- server = ThreadedEchoServer(10024, CERTFILE)
- flag = threading.Event()
- server.start(flag)
- # wait for it to start
- flag.wait()
- tests.append(ConnectedTests)
+ if test_support.is_resource_enabled('network'):
+ tests.append(NetworkTests)
- thread_info = test_support.threading_setup()
+ if _have_threads:
+ thread_info = test_support.threading_setup()
+ if thread_info and test_support.is_resource_enabled('network'):
+ tests.append(ConnectedTests)
- try:
- test_support.run_unittest(*tests)
- finally:
- if server is not None and server.active:
- server.stop()
- # wait for it to stop
- server.join()
+ test_support.run_unittest(*tests)
- test_support.threading_cleanup(*thread_info)
+ if _have_threads:
+ test_support.threading_cleanup(*thread_info)
if __name__ == "__main__":
test_main()
Modified: python/branches/py3k-importlib/Lib/urllib.py
==============================================================================
--- python/branches/py3k-importlib/Lib/urllib.py (original)
+++ python/branches/py3k-importlib/Lib/urllib.py Fri Sep 21 03:17:09 2007
@@ -357,7 +357,9 @@
raise IOError('http protocol error', 0,
'got a bad status line', None)
- if response.status == 200:
+ # According to RFC 2616, "2xx" code indicates that the client's
+ # request was successfully received, understood, and accepted.
+ if not (200 <= response.status < 300):
return addinfourl(response.fp, response.msg, "http:" + url)
else:
return self.http_error(
Modified: python/branches/py3k-importlib/Mac/Modules/cf/_CFmodule.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/cf/_CFmodule.c (original)
+++ python/branches/py3k-importlib/Mac/Modules/cf/_CFmodule.c Fri Sep 21 03:17:09 2007
@@ -1821,6 +1821,7 @@
if (!PyArg_Parse(v, "es", "ascii", &cStr))
return 0;
*p_itself = CFStringCreateWithCString((CFAllocatorRef)NULL, cStr, kCFStringEncodingASCII);
+ PyMem_Free(cStr);
return 1;
}
if (PyUnicode_Check(v)) {
Modified: python/branches/py3k-importlib/Mac/Modules/cf/cfsupport.py
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/cf/cfsupport.py (original)
+++ python/branches/py3k-importlib/Mac/Modules/cf/cfsupport.py Fri Sep 21 03:17:09 2007
@@ -429,6 +429,7 @@
if (!PyArg_Parse(v, "es", "ascii", &cStr))
return NULL;
*p_itself = CFStringCreateWithCString((CFAllocatorRef)NULL, cStr, kCFStringEncodingASCII);
+ PyMem_Free(cStr);
return 1;
}
if (PyUnicode_Check(v)) {
Modified: python/branches/py3k-importlib/Mac/Modules/cf/pycfbridge.c
==============================================================================
--- python/branches/py3k-importlib/Mac/Modules/cf/pycfbridge.c (original)
+++ python/branches/py3k-importlib/Mac/Modules/cf/pycfbridge.c Fri Sep 21 03:17:09 2007
@@ -285,6 +285,7 @@
if (!PyArg_Parse(src, "es", "ascii", &chars))
return 0; /* This error is more descriptive than the general one below */
*dst = CFStringCreateWithCString((CFAllocatorRef)NULL, chars, kCFStringEncodingASCII);
+ PyMem_Free(chars);
return 1;
}
if (PyUnicode_Check(src)) {
Modified: python/branches/py3k-importlib/Modules/_sre.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_sre.c (original)
+++ python/branches/py3k-importlib/Modules/_sre.c Fri Sep 21 03:17:09 2007
@@ -1969,7 +1969,7 @@
#endif
static PyObject*
-join_list(PyObject* list, PyObject* pattern)
+join_list(PyObject* list, PyObject* string)
{
/* join list elements */
@@ -1980,24 +1980,15 @@
#endif
PyObject* result;
- switch (PyList_GET_SIZE(list)) {
- case 0:
- Py_DECREF(list);
- return PySequence_GetSlice(pattern, 0, 0);
- case 1:
- result = PyList_GET_ITEM(list, 0);
- Py_INCREF(result);
- Py_DECREF(list);
- return result;
- }
-
- /* two or more elements: slice out a suitable separator from the
- first member, and use that to join the entire list */
-
- joiner = PySequence_GetSlice(pattern, 0, 0);
+ joiner = PySequence_GetSlice(string, 0, 0);
if (!joiner)
return NULL;
+ if (PyList_GET_SIZE(list) == 0) {
+ Py_DECREF(list);
+ return joiner;
+ }
+
#if PY_VERSION_HEX >= 0x01060000
function = PyObject_GetAttrString(joiner, "join");
if (!function) {
@@ -2433,7 +2424,7 @@
Py_DECREF(filter);
/* convert list to single string (also removes list) */
- item = join_list(list, self->pattern);
+ item = join_list(list, string);
if (!item)
return NULL;
Modified: python/branches/py3k-importlib/Modules/_ssl.c
==============================================================================
--- python/branches/py3k-importlib/Modules/_ssl.c (original)
+++ python/branches/py3k-importlib/Modules/_ssl.c Fri Sep 21 03:17:09 2007
@@ -1,14 +1,38 @@
/* SSL socket module
SSL support based on patches by Brian E Gallew and Laszlo Kovacs.
+ Re-worked a bit by Bill Janssen to add server-side support and
+ certificate decoding.
- This module is imported by socket.py. It should *not* be used
+ This module is imported by ssl.py. It should *not* be used
directly.
+ XXX should partial writes be enabled, SSL_MODE_ENABLE_PARTIAL_WRITE?
+
+ XXX what about SSL_MODE_AUTO_RETRY
*/
#include "Python.h"
+#ifdef WITH_THREAD
+#include "pythread.h"
+#define PySSL_BEGIN_ALLOW_THREADS { \
+ PyThreadState *_save; \
+ if (_ssl_locks_count>0) {_save = PyEval_SaveThread();}
+#define PySSL_BLOCK_THREADS if (_ssl_locks_count>0){PyEval_RestoreThread(_save)};
+#define PySSL_UNBLOCK_THREADS if (_ssl_locks_count>0){_save = PyEval_SaveThread()};
+#define PySSL_END_ALLOW_THREADS if (_ssl_locks_count>0){PyEval_RestoreThread(_save);} \
+ }
+
+#else /* no WITH_THREAD */
+
+#define PySSL_BEGIN_ALLOW_THREADS
+#define PySSL_BLOCK_THREADS
+#define PySSL_UNBLOCK_THREADS
+#define PySSL_END_ALLOW_THREADS
+
+#endif
+
enum py_ssl_error {
/* these mirror ssl.h */
PY_SSL_ERROR_NONE,
@@ -55,6 +79,7 @@
#include "openssl/rsa.h"
#include "openssl/crypto.h"
#include "openssl/x509.h"
+#include "openssl/x509v3.h"
#include "openssl/pem.h"
#include "openssl/ssl.h"
#include "openssl/err.h"
@@ -63,6 +88,15 @@
/* SSL error object */
static PyObject *PySSLErrorObject;
+#ifdef WITH_THREAD
+
+/* serves as a flag to see whether we've initialized the SSL thread support. */
+/* 0 means no, greater than 0 means yes */
+
+static unsigned int _ssl_locks_count = 0;
+
+#endif /* def WITH_THREAD */
+
/* SSL socket object */
#define X509_NAME_MAXLEN 256
@@ -90,8 +124,8 @@
static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args);
static int check_socket_and_wait_for_timeout(PySocketSockObject *s,
int writing);
-static PyObject *PySSL_peercert(PySSLObject *self);
-
+static PyObject *PySSL_peercert(PySSLObject *self, PyObject *args);
+static PyObject *PySSL_cipher(PySSLObject *self);
#define PySSLObject_Check(v) (Py_Type(v) == &PySSL_Type)
@@ -126,7 +160,7 @@
assert(ret <= 0);
- if ((obj != NULL) && (obj->ssl != NULL)) {
+ if (obj->ssl != NULL) {
err = SSL_get_error(obj->ssl, ret);
switch (err) {
@@ -202,6 +236,25 @@
return NULL;
}
+static PyObject *
+_setSSLError (char *errstr, int errcode, char *filename, int lineno) {
+
+ char buf[2048];
+ PyObject *v;
+
+ if (errstr == NULL) {
+ errcode = ERR_peek_last_error();
+ errstr = ERR_error_string(errcode, NULL);
+ }
+ PyOS_snprintf(buf, sizeof(buf), "_ssl.c:%d: %s", lineno, errstr);
+ v = Py_BuildValue("(is)", errcode, buf);
+ if (v != NULL) {
+ PyErr_SetObject(PySSLErrorObject, v);
+ Py_DECREF(v);
+ }
+ return NULL;
+}
+
static PySSLObject *
newPySSLObject(PySocketSockObject *Sock, char *key_file, char *cert_file,
enum py_ssl_server_or_client socket_type,
@@ -226,6 +279,10 @@
self->ctx = NULL;
self->Socket = NULL;
+ /* Make sure the SSL error state is initialized */
+ (void) ERR_get_state();
+ ERR_clear_error();
+
if ((key_file && !cert_file) || (!key_file && cert_file)) {
errstr = ERRSTR("Both the key & certificate files "
"must be specified");
@@ -239,16 +296,16 @@
goto fail;
}
- Py_BEGIN_ALLOW_THREADS
+ PySSL_BEGIN_ALLOW_THREADS
if (proto_version == PY_SSL_VERSION_TLS1)
self->ctx = SSL_CTX_new(TLSv1_method()); /* Set up context */
else if (proto_version == PY_SSL_VERSION_SSL3)
self->ctx = SSL_CTX_new(SSLv3_method()); /* Set up context */
else if (proto_version == PY_SSL_VERSION_SSL2)
self->ctx = SSL_CTX_new(SSLv2_method()); /* Set up context */
- else
+ else if (proto_version == PY_SSL_VERSION_SSL23)
self->ctx = SSL_CTX_new(SSLv23_method()); /* Set up context */
- Py_END_ALLOW_THREADS
+ PySSL_END_ALLOW_THREADS
if (self->ctx == NULL) {
errstr = ERRSTR("Invalid SSL protocol variant specified.");
@@ -261,39 +318,46 @@
"verification of other-side certificates.");
goto fail;
} else {
- Py_BEGIN_ALLOW_THREADS
+ PySSL_BEGIN_ALLOW_THREADS
ret = SSL_CTX_load_verify_locations(self->ctx,
cacerts_file,
NULL);
- Py_END_ALLOW_THREADS
+ PySSL_END_ALLOW_THREADS
if (ret != 1) {
- PySSL_SetError(NULL, 0, __FILE__, __LINE__);
+ _setSSLError(NULL, 0, __FILE__, __LINE__);
goto fail;
}
}
}
if (key_file) {
- Py_BEGIN_ALLOW_THREADS
+ PySSL_BEGIN_ALLOW_THREADS
ret = SSL_CTX_use_PrivateKey_file(self->ctx, key_file,
SSL_FILETYPE_PEM);
- Py_END_ALLOW_THREADS
+ PySSL_END_ALLOW_THREADS
if (ret != 1) {
- PySSL_SetError(NULL, 0, __FILE__, __LINE__);
+ _setSSLError(NULL, ret, __FILE__, __LINE__);
goto fail;
}
- Py_BEGIN_ALLOW_THREADS
+ PySSL_BEGIN_ALLOW_THREADS
ret = SSL_CTX_use_certificate_chain_file(self->ctx,
- cert_file);
- Py_END_ALLOW_THREADS
+ cert_file);
+ PySSL_END_ALLOW_THREADS
if (ret != 1) {
- PySSL_SetError(NULL, 0, __FILE__, __LINE__);
- goto fail;
+ /*
+ fprintf(stderr, "ret is %d, errcode is %lu, %lu, with file \"%s\"\n",
+ ret, ERR_peek_error(), ERR_peek_last_error(), cert_file);
+ */
+ if (ERR_peek_last_error() != 0) {
+ _setSSLError(NULL, ret, __FILE__, __LINE__);
+ goto fail;
+ }
}
- /* ssl compatibility */
- SSL_CTX_set_options(self->ctx, SSL_OP_ALL);
}
+ /* ssl compatibility */
+ SSL_CTX_set_options(self->ctx, SSL_OP_ALL);
+
verification_mode = SSL_VERIFY_NONE;
if (certreq == PY_SSL_CERT_OPTIONAL)
verification_mode = SSL_VERIFY_PEER;
@@ -303,9 +367,9 @@
SSL_CTX_set_verify(self->ctx, verification_mode,
NULL); /* set verify lvl */
- Py_BEGIN_ALLOW_THREADS
+ PySSL_BEGIN_ALLOW_THREADS
self->ssl = SSL_new(self->ctx); /* New ssl struct */
- Py_END_ALLOW_THREADS
+ PySSL_END_ALLOW_THREADS
SSL_set_fd(self->ssl, Sock->sock_fd); /* Set the socket for SSL */
/* If the socket is in non-blocking mode or timeout mode, set the BIO
@@ -317,24 +381,24 @@
BIO_set_nbio(SSL_get_wbio(self->ssl), 1);
}
- Py_BEGIN_ALLOW_THREADS
+ PySSL_BEGIN_ALLOW_THREADS
if (socket_type == PY_SSL_CLIENT)
SSL_set_connect_state(self->ssl);
else
SSL_set_accept_state(self->ssl);
- Py_END_ALLOW_THREADS
+ PySSL_END_ALLOW_THREADS
/* Actually negotiate SSL connection */
/* XXX If SSL_connect() returns 0, it's also a failure. */
sockstate = 0;
do {
- Py_BEGIN_ALLOW_THREADS
+ PySSL_BEGIN_ALLOW_THREADS
if (socket_type == PY_SSL_CLIENT)
ret = SSL_connect(self->ssl);
else
ret = SSL_accept(self->ssl);
err = SSL_get_error(self->ssl, ret);
- Py_END_ALLOW_THREADS
+ PySSL_END_ALLOW_THREADS
if(PyErr_CheckSignals()) {
goto fail;
}
@@ -367,14 +431,14 @@
}
self->ssl->debug = 1;
- Py_BEGIN_ALLOW_THREADS
+ PySSL_BEGIN_ALLOW_THREADS
if ((self->peer_cert = SSL_get_peer_certificate(self->ssl))) {
X509_NAME_oneline(X509_get_subject_name(self->peer_cert),
self->server, X509_NAME_MAXLEN);
X509_NAME_oneline(X509_get_issuer_name(self->peer_cert),
self->issuer, X509_NAME_MAXLEN);
}
- Py_END_ALLOW_THREADS
+ PySSL_END_ALLOW_THREADS
self->Socket = Sock;
Py_INCREF(self->Socket);
return self;
@@ -437,96 +501,313 @@
}
static PyObject *
+_create_tuple_for_attribute (ASN1_OBJECT *name, ASN1_STRING *value) {
+
+ char namebuf[X509_NAME_MAXLEN];
+ int buflen;
+ PyObject *name_obj;
+ PyObject *value_obj;
+ PyObject *attr;
+ unsigned char *valuebuf = NULL;
+
+ buflen = OBJ_obj2txt(namebuf, sizeof(namebuf), name, 0);
+ if (buflen < 0) {
+ _setSSLError(NULL, 0, __FILE__, __LINE__);
+ goto fail;
+ }
+ name_obj = PyString_FromStringAndSize(namebuf, buflen);
+ if (name_obj == NULL)
+ goto fail;
+
+ buflen = ASN1_STRING_to_UTF8(&valuebuf, value);
+ if (buflen < 0) {
+ _setSSLError(NULL, 0, __FILE__, __LINE__);
+ Py_DECREF(name_obj);
+ goto fail;
+ }
+ value_obj = PyUnicode_DecodeUTF8((char *) valuebuf,
+ buflen, "strict");
+ OPENSSL_free(valuebuf);
+ if (value_obj == NULL) {
+ Py_DECREF(name_obj);
+ goto fail;
+ }
+ attr = PyTuple_New(2);
+ if (attr == NULL) {
+ Py_DECREF(name_obj);
+ Py_DECREF(value_obj);
+ goto fail;
+ }
+ PyTuple_SET_ITEM(attr, 0, name_obj);
+ PyTuple_SET_ITEM(attr, 1, value_obj);
+ return attr;
+
+ fail:
+ return NULL;
+}
+
+static PyObject *
_create_tuple_for_X509_NAME (X509_NAME *xname)
{
- PyObject *pt = NULL;
- PyObject *entry_tuple = NULL;
+ PyObject *dn = NULL; /* tuple which represents the "distinguished name" */
+ PyObject *rdn = NULL; /* tuple to hold a "relative distinguished name" */
+ PyObject *rdnt;
+ PyObject *attr = NULL; /* tuple to hold an attribute */
int entry_count = X509_NAME_entry_count(xname);
+ X509_NAME_ENTRY *entry;
+ ASN1_OBJECT *name;
+ ASN1_STRING *value;
int index_counter;
+ int rdn_level = -1;
+ int retcode;
- pt = PyTuple_New(entry_count);
- if (pt == NULL)
+ dn = PyList_New(0);
+ if (dn == NULL)
return NULL;
+ /* now create another tuple to hold the top-level RDN */
+ rdn = PyList_New(0);
+ if (rdn == NULL)
+ goto fail0;
for (index_counter = 0;
- index_counter < X509_NAME_entry_count(xname);
+ index_counter < entry_count;
index_counter++)
{
- char namebuf[X509_NAME_MAXLEN];
- int buflen;
- PyObject *name_obj;
- ASN1_STRING *value;
- PyObject *value_obj;
- unsigned char *valuebuf = NULL;
-
- X509_NAME_ENTRY *entry = X509_NAME_get_entry(xname,
- index_counter);
-
- ASN1_OBJECT *name = X509_NAME_ENTRY_get_object(entry);
- buflen = OBJ_obj2txt(namebuf, sizeof(namebuf), name, 0);
- if (buflen < 0)
- goto fail0;
- name_obj = PyString_FromStringAndSize(namebuf, buflen);
- if (name_obj == NULL)
- goto fail0;
+ entry = X509_NAME_get_entry(xname, index_counter);
+ /* check to see if we've gotten to a new RDN */
+ if (rdn_level >= 0) {
+ if (rdn_level != entry->set) {
+ /* yes, new RDN */
+ /* add old RDN to DN */
+ rdnt = PyList_AsTuple(rdn);
+ Py_DECREF(rdn);
+ if (rdnt == NULL)
+ goto fail0;
+ retcode = PyList_Append(dn, rdnt);
+ Py_DECREF(rdnt);
+ if (retcode < 0)
+ goto fail0;
+ /* create new RDN */
+ rdn = PyList_New(0);
+ if (rdn == NULL)
+ goto fail0;
+ }
+ }
+ rdn_level = entry->set;
+
+ /* now add this attribute to the current RDN */
+ name = X509_NAME_ENTRY_get_object(entry);
value = X509_NAME_ENTRY_get_data(entry);
- buflen = ASN1_STRING_to_UTF8(&valuebuf, value);
- if (buflen < 0) {
- Py_DECREF(name_obj);
+ attr = _create_tuple_for_attribute(name, value);
+ /*
+ fprintf(stderr, "RDN level %d, attribute %s: %s\n",
+ entry->set,
+ PyString_AS_STRING(PyTuple_GET_ITEM(attr, 0)),
+ PyString_AS_STRING(PyTuple_GET_ITEM(attr, 1)));
+ */
+ if (attr == NULL)
+ goto fail1;
+ retcode = PyList_Append(rdn, attr);
+ Py_DECREF(attr);
+ if (retcode < 0)
+ goto fail1;
+ }
+ /* now, there's typically a dangling RDN */
+ if ((rdn != NULL) && (PyList_Size(rdn) > 0)) {
+ rdnt = PyList_AsTuple(rdn);
+ Py_DECREF(rdn);
+ if (rdnt == NULL)
goto fail0;
- }
- value_obj = PyUnicode_DecodeUTF8((char *) valuebuf,
- buflen, "strict");
- OPENSSL_free(valuebuf);
- if (value_obj == NULL) {
- Py_DECREF(name_obj);
+ retcode = PyList_Append(dn, rdnt);
+ Py_DECREF(rdnt);
+ if (retcode < 0)
goto fail0;
+ }
+
+ /* convert list to tuple */
+ rdnt = PyList_AsTuple(dn);
+ Py_DECREF(dn);
+ if (rdnt == NULL)
+ return NULL;
+ return rdnt;
+
+ fail1:
+ Py_XDECREF(rdn);
+
+ fail0:
+ Py_XDECREF(dn);
+ return NULL;
+}
+
+static PyObject *
+_get_peer_alt_names (X509 *certificate) {
+
+ /* this code follows the procedure outlined in
+ OpenSSL's crypto/x509v3/v3_prn.c:X509v3_EXT_print()
+ function to extract the STACK_OF(GENERAL_NAME),
+ then iterates through the stack to add the
+ names. */
+
+ int i, j;
+ PyObject *peer_alt_names = Py_None;
+ PyObject *v, *t;
+ X509_EXTENSION *ext = NULL;
+ GENERAL_NAMES *names = NULL;
+ GENERAL_NAME *name;
+ X509V3_EXT_METHOD *method;
+ BIO *biobuf = NULL;
+ char buf[2048];
+ char *vptr;
+ int len;
+ unsigned char *p;
+
+ if (certificate == NULL)
+ return peer_alt_names;
+
+ /* get a memory buffer */
+ biobuf = BIO_new(BIO_s_mem());
+
+ i = 0;
+ while ((i = X509_get_ext_by_NID(
+ certificate, NID_subject_alt_name, i)) >= 0) {
+
+ if (peer_alt_names == Py_None) {
+ peer_alt_names = PyList_New(0);
+ if (peer_alt_names == NULL)
+ goto fail;
}
- entry_tuple = PyTuple_New(2);
- if (entry_tuple == NULL) {
- Py_DECREF(name_obj);
- Py_DECREF(value_obj);
- goto fail0;
+
+ /* now decode the altName */
+ ext = X509_get_ext(certificate, i);
+ if(!(method = X509V3_EXT_get(ext))) {
+ PyErr_SetString(PySSLErrorObject,
+ ERRSTR("No method for internalizing subjectAltName!"));
+ goto fail;
+ }
+
+ p = ext->value->data;
+ if(method->it)
+ names = (GENERAL_NAMES*) (ASN1_item_d2i(NULL,
+ &p,
+ ext->value->length,
+ ASN1_ITEM_ptr(method->it)));
+ else
+ names = (GENERAL_NAMES*) (method->d2i(NULL,
+ &p,
+ ext->value->length));
+
+ for(j = 0; j < sk_GENERAL_NAME_num(names); j++) {
+
+ /* get a rendering of each name in the set of names */
+
+ name = sk_GENERAL_NAME_value(names, j);
+ if (name->type == GEN_DIRNAME) {
+
+ /* we special-case DirName as a tuple of tuples of attributes */
+
+ t = PyTuple_New(2);
+ if (t == NULL) {
+ goto fail;
+ }
+
+ v = PyString_FromString("DirName");
+ if (v == NULL) {
+ Py_DECREF(t);
+ goto fail;
+ }
+ PyTuple_SET_ITEM(t, 0, v);
+
+ v = _create_tuple_for_X509_NAME (name->d.dirn);
+ if (v == NULL) {
+ Py_DECREF(t);
+ goto fail;
+ }
+ PyTuple_SET_ITEM(t, 1, v);
+
+ } else {
+
+ /* for everything else, we use the OpenSSL print form */
+
+ (void) BIO_reset(biobuf);
+ GENERAL_NAME_print(biobuf, name);
+ len = BIO_gets(biobuf, buf, sizeof(buf)-1);
+ if (len < 0) {
+ _setSSLError(NULL, 0, __FILE__, __LINE__);
+ goto fail;
+ }
+ vptr = strchr(buf, ':');
+ if (vptr == NULL)
+ goto fail;
+ t = PyTuple_New(2);
+ if (t == NULL)
+ goto fail;
+ v = PyString_FromStringAndSize(buf, (vptr - buf));
+ if (v == NULL) {
+ Py_DECREF(t);
+ goto fail;
+ }
+ PyTuple_SET_ITEM(t, 0, v);
+ v = PyString_FromStringAndSize((vptr + 1), (len - (vptr - buf + 1)));
+ if (v == NULL) {
+ Py_DECREF(t);
+ goto fail;
+ }
+ PyTuple_SET_ITEM(t, 1, v);
+ }
+
+ /* and add that rendering to the list */
+
+ if (PyList_Append(peer_alt_names, t) < 0) {
+ Py_DECREF(t);
+ goto fail;
+ }
+ Py_DECREF(t);
}
- PyTuple_SET_ITEM(entry_tuple, 0, name_obj);
- PyTuple_SET_ITEM(entry_tuple, 1, value_obj);
- PyTuple_SET_ITEM(pt, index_counter, entry_tuple);
}
- return pt;
+ BIO_free(biobuf);
+ if (peer_alt_names != Py_None) {
+ v = PyList_AsTuple(peer_alt_names);
+ Py_DECREF(peer_alt_names);
+ return v;
+ } else {
+ return peer_alt_names;
+ }
+
+
+ fail:
+ if (biobuf != NULL)
+ BIO_free(biobuf);
+
+ if (peer_alt_names != Py_None) {
+ Py_XDECREF(peer_alt_names);
+ }
- fail0:
- Py_XDECREF(pt);
return NULL;
}
static PyObject *
-PySSL_peercert(PySSLObject *self)
-{
+_decode_certificate (X509 *certificate, int verbose) {
+
PyObject *retval = NULL;
BIO *biobuf = NULL;
PyObject *peer;
+ PyObject *peer_alt_names = NULL;
PyObject *issuer;
PyObject *version;
+ PyObject *sn_obj;
+ ASN1_INTEGER *serialNumber;
char buf[2048];
int len;
ASN1_TIME *notBefore, *notAfter;
PyObject *pnotBefore, *pnotAfter;
- int verification;
-
- if (!self->peer_cert)
- Py_RETURN_NONE;
retval = PyDict_New();
if (retval == NULL)
return NULL;
- verification = SSL_CTX_get_verify_mode(self->ctx);
- if ((verification & SSL_VERIFY_PEER) == 0)
- return retval;
-
peer = _create_tuple_for_X509_NAME(
- X509_get_subject_name(self->peer_cert));
+ X509_get_subject_name(certificate));
if (peer == NULL)
goto fail0;
if (PyDict_SetItemString(retval, (const char *) "subject", peer) < 0) {
@@ -535,51 +816,98 @@
}
Py_DECREF(peer);
- issuer = _create_tuple_for_X509_NAME(
- X509_get_issuer_name(self->peer_cert));
- if (issuer == NULL)
- goto fail0;
- if (PyDict_SetItemString(retval, (const char *)"issuer", issuer) < 0) {
+ if (verbose) {
+ issuer = _create_tuple_for_X509_NAME(
+ X509_get_issuer_name(certificate));
+ if (issuer == NULL)
+ goto fail0;
+ if (PyDict_SetItemString(retval, (const char *)"issuer", issuer) < 0) {
+ Py_DECREF(issuer);
+ goto fail0;
+ }
Py_DECREF(issuer);
- goto fail0;
- }
- Py_DECREF(issuer);
-
- version = PyInt_FromLong(X509_get_version(self->peer_cert));
- if (PyDict_SetItemString(retval, "version", version) < 0) {
+
+ version = PyInt_FromLong(X509_get_version(certificate) + 1);
+ if (PyDict_SetItemString(retval, "version", version) < 0) {
+ Py_DECREF(version);
+ goto fail0;
+ }
Py_DECREF(version);
- goto fail0;
}
- Py_DECREF(version);
-
+
/* get a memory buffer */
biobuf = BIO_new(BIO_s_mem());
+
+ if (verbose) {
- notBefore = X509_get_notBefore(self->peer_cert);
- ASN1_TIME_print(biobuf, notBefore);
- len = BIO_gets(biobuf, buf, sizeof(buf)-1);
- pnotBefore = PyString_FromStringAndSize(buf, len);
- if (pnotBefore == NULL)
- goto fail1;
- if (PyDict_SetItemString(retval, "notBefore", pnotBefore) < 0) {
+ (void) BIO_reset(biobuf);
+ serialNumber = X509_get_serialNumber(certificate);
+ /* should not exceed 20 octets, 160 bits, so buf is big enough */
+ i2a_ASN1_INTEGER(biobuf, serialNumber);
+ len = BIO_gets(biobuf, buf, sizeof(buf)-1);
+ if (len < 0) {
+ _setSSLError(NULL, 0, __FILE__, __LINE__);
+ goto fail1;
+ }
+ sn_obj = PyString_FromStringAndSize(buf, len);
+ if (sn_obj == NULL)
+ goto fail1;
+ if (PyDict_SetItemString(retval, "serialNumber", sn_obj) < 0) {
+ Py_DECREF(sn_obj);
+ goto fail1;
+ }
+ Py_DECREF(sn_obj);
+
+ (void) BIO_reset(biobuf);
+ notBefore = X509_get_notBefore(certificate);
+ ASN1_TIME_print(biobuf, notBefore);
+ len = BIO_gets(biobuf, buf, sizeof(buf)-1);
+ if (len < 0) {
+ _setSSLError(NULL, 0, __FILE__, __LINE__);
+ goto fail1;
+ }
+ pnotBefore = PyString_FromStringAndSize(buf, len);
+ if (pnotBefore == NULL)
+ goto fail1;
+ if (PyDict_SetItemString(retval, "notBefore", pnotBefore) < 0) {
+ Py_DECREF(pnotBefore);
+ goto fail1;
+ }
Py_DECREF(pnotBefore);
- goto fail1;
}
- Py_DECREF(pnotBefore);
(void) BIO_reset(biobuf);
- notAfter = X509_get_notAfter(self->peer_cert);
+ notAfter = X509_get_notAfter(certificate);
ASN1_TIME_print(biobuf, notAfter);
len = BIO_gets(biobuf, buf, sizeof(buf)-1);
- BIO_free(biobuf);
+ if (len < 0) {
+ _setSSLError(NULL, 0, __FILE__, __LINE__);
+ goto fail1;
+ }
pnotAfter = PyString_FromStringAndSize(buf, len);
if (pnotAfter == NULL)
- goto fail0;
+ goto fail1;
if (PyDict_SetItemString(retval, "notAfter", pnotAfter) < 0) {
Py_DECREF(pnotAfter);
- goto fail0;
+ goto fail1;
}
Py_DECREF(pnotAfter);
+
+ /* Now look for subjectAltName */
+
+ peer_alt_names = _get_peer_alt_names(certificate);
+ if (peer_alt_names == NULL)
+ goto fail1;
+ else if (peer_alt_names != Py_None) {
+ if (PyDict_SetItemString(retval, "subjectAltName",
+ peer_alt_names) < 0) {
+ Py_DECREF(peer_alt_names);
+ goto fail1;
+ }
+ Py_DECREF(peer_alt_names);
+ }
+
+ BIO_free(biobuf);
return retval;
fail1:
@@ -590,6 +918,141 @@
return NULL;
}
+
+static PyObject *
+PySSL_test_decode_certificate (PyObject *mod, PyObject *args) {
+
+ PyObject *retval = NULL;
+ char *filename = NULL;
+ X509 *x=NULL;
+ BIO *cert;
+ int verbose = 1;
+
+ if (!PyArg_ParseTuple(args, "s|i:test_decode_certificate", &filename, &verbose))
+ return NULL;
+
+ if ((cert=BIO_new(BIO_s_file())) == NULL) {
+ PyErr_SetString(PySSLErrorObject, "Can't malloc memory to read file");
+ goto fail0;
+ }
+
+ if (BIO_read_filename(cert,filename) <= 0) {
+ PyErr_SetString(PySSLErrorObject, "Can't open file");
+ goto fail0;
+ }
+
+ x = PEM_read_bio_X509_AUX(cert,NULL, NULL, NULL);
+ if (x == NULL) {
+ PyErr_SetString(PySSLErrorObject, "Error decoding PEM-encoded file");
+ goto fail0;
+ }
+
+ retval = _decode_certificate(x, verbose);
+
+ fail0:
+
+ if (cert != NULL) BIO_free(cert);
+ return retval;
+}
+
+
+static PyObject *
+PySSL_peercert(PySSLObject *self, PyObject *args)
+{
+ PyObject *retval = NULL;
+ int len;
+ int verification;
+ PyObject *binary_mode = Py_None;
+
+ if (!PyArg_ParseTuple(args, "|O:peer_certificate", &binary_mode))
+ return NULL;
+
+ if (!self->peer_cert)
+ Py_RETURN_NONE;
+
+ if (PyObject_IsTrue(binary_mode)) {
+ /* return cert in DER-encoded format */
+
+ unsigned char *bytes_buf = NULL;
+
+ bytes_buf = NULL;
+ len = i2d_X509(self->peer_cert, &bytes_buf);
+ if (len < 0) {
+ PySSL_SetError(self, len, __FILE__, __LINE__);
+ return NULL;
+ }
+ retval = PyString_FromStringAndSize((const char *) bytes_buf, len);
+ OPENSSL_free(bytes_buf);
+ return retval;
+
+ } else {
+
+ verification = SSL_CTX_get_verify_mode(self->ctx);
+ if ((verification & SSL_VERIFY_PEER) == 0)
+ return PyDict_New();
+ else
+ return _decode_certificate (self->peer_cert, 0);
+ }
+}
+
+PyDoc_STRVAR(PySSL_peercert_doc,
+"peer_certificate([der=False]) -> certificate\n\
+\n\
+Returns the certificate for the peer. If no certificate was provided,\n\
+returns None. If a certificate was provided, but not validated, returns\n\
+an empty dictionary. Otherwise returns a dict containing information\n\
+about the peer certificate.\n\
+\n\
+If the optional argument is True, returns a DER-encoded copy of the\n\
+peer certificate, or None if no certificate was provided. This will\n\
+return the certificate even if it wasn't validated.");
+
+static PyObject *PySSL_cipher (PySSLObject *self) {
+
+ PyObject *retval, *v;
+ SSL_CIPHER *current;
+ char *cipher_name;
+ char *cipher_protocol;
+
+ if (self->ssl == NULL)
+ return Py_None;
+ current = SSL_get_current_cipher(self->ssl);
+ if (current == NULL)
+ return Py_None;
+
+ retval = PyTuple_New(3);
+ if (retval == NULL)
+ return NULL;
+
+ cipher_name = (char *) SSL_CIPHER_get_name(current);
+ if (cipher_name == NULL) {
+ PyTuple_SET_ITEM(retval, 0, Py_None);
+ } else {
+ v = PyString_FromString(cipher_name);
+ if (v == NULL)
+ goto fail0;
+ PyTuple_SET_ITEM(retval, 0, v);
+ }
+ cipher_protocol = SSL_CIPHER_get_version(current);
+ if (cipher_protocol == NULL) {
+ PyTuple_SET_ITEM(retval, 1, Py_None);
+ } else {
+ v = PyString_FromString(cipher_protocol);
+ if (v == NULL)
+ goto fail0;
+ PyTuple_SET_ITEM(retval, 1, v);
+ }
+ v = PyInt_FromLong(SSL_CIPHER_get_bits(current, NULL));
+ if (v == NULL)
+ goto fail0;
+ PyTuple_SET_ITEM(retval, 2, v);
+ return retval;
+
+ fail0:
+ Py_DECREF(retval);
+ return NULL;
+}
+
static void PySSL_dealloc(PySSLObject *self)
{
if (self->peer_cert) /* Possible not to have one? */
@@ -636,9 +1099,9 @@
/* s->sock_timeout is in seconds, timeout in ms */
timeout = (int)(s->sock_timeout * 1000 + 0.5);
- Py_BEGIN_ALLOW_THREADS
+ PySSL_BEGIN_ALLOW_THREADS
rc = poll(&pollfd, 1, timeout);
- Py_END_ALLOW_THREADS
+ PySSL_END_ALLOW_THREADS
goto normal_return;
}
@@ -657,12 +1120,12 @@
FD_SET(s->sock_fd, &fds);
/* See if the socket is ready */
- Py_BEGIN_ALLOW_THREADS
+ PySSL_BEGIN_ALLOW_THREADS
if (writing)
rc = select(s->sock_fd+1, NULL, &fds, NULL, &tv);
else
rc = select(s->sock_fd+1, &fds, NULL, NULL, &tv);
- Py_END_ALLOW_THREADS
+ PySSL_END_ALLOW_THREADS
normal_return:
/* Return SOCKET_TIMED_OUT on timeout, SOCKET_OPERATION_OK otherwise
@@ -697,10 +1160,10 @@
}
do {
err = 0;
- Py_BEGIN_ALLOW_THREADS
+ PySSL_BEGIN_ALLOW_THREADS
len = SSL_write(self->ssl, data, count);
err = SSL_get_error(self->ssl, len);
- Py_END_ALLOW_THREADS
+ PySSL_END_ALLOW_THREADS
if(PyErr_CheckSignals()) {
return NULL;
}
@@ -752,9 +1215,9 @@
return NULL;
/* first check if there are bytes ready to be read */
- Py_BEGIN_ALLOW_THREADS
+ PySSL_BEGIN_ALLOW_THREADS
count = SSL_pending(self->ssl);
- Py_END_ALLOW_THREADS
+ PySSL_END_ALLOW_THREADS
if (!count) {
sockstate = check_socket_and_wait_for_timeout(self->Socket, 0);
@@ -769,26 +1232,17 @@
Py_DECREF(buf);
return NULL;
} else if (sockstate == SOCKET_HAS_BEEN_CLOSED) {
- if (SSL_get_shutdown(self->ssl) !=
- SSL_RECEIVED_SHUTDOWN)
- {
- Py_DECREF(buf);
- PyErr_SetString(PySSLErrorObject,
- "Socket closed without SSL shutdown handshake");
- return NULL;
- } else {
- /* should contain a zero-length string */
- _PyString_Resize(&buf, 0);
- return buf;
- }
+ /* should contain a zero-length string */
+ _PyString_Resize(&buf, 0);
+ return buf;
}
}
do {
err = 0;
- Py_BEGIN_ALLOW_THREADS
+ PySSL_BEGIN_ALLOW_THREADS
count = SSL_read(self->ssl, PyBytes_AS_STRING(buf), len);
err = SSL_get_error(self->ssl, count);
- Py_END_ALLOW_THREADS
+ PySSL_END_ALLOW_THREADS
if(PyErr_CheckSignals()) {
Py_DECREF(buf);
return NULL;
@@ -834,49 +1288,16 @@
\n\
Read up to len bytes from the SSL socket.");
-static PyObject *PySSL_SSLshutdown(PySSLObject *self, PyObject *args)
-{
- int err;
-
- /* Guard against closed socket */
- if (self->Socket->sock_fd < 0) {
- PyErr_SetString(PySSLErrorObject,
- "Underlying socket has been closed.");
- return NULL;
- }
-
- Py_BEGIN_ALLOW_THREADS
- err = SSL_shutdown(self->ssl);
- if (err == 0) {
- /* we need to call it again to finish the shutdown */
- err = SSL_shutdown(self->ssl);
- }
- Py_END_ALLOW_THREADS
-
- if (err < 0)
- return PySSL_SetError(self, err, __FILE__, __LINE__);
- else {
- Py_INCREF(self->Socket);
- return (PyObject *) (self->Socket);
- }
-}
-
-PyDoc_STRVAR(PySSL_SSLshutdown_doc,
-"shutdown(s) -> socket\n\
-\n\
-Does the SSL shutdown handshake with the remote end, and returns\n\
-the underlying socket object.");
-
static PyMethodDef PySSLMethods[] = {
{"write", (PyCFunction)PySSL_SSLwrite, METH_VARARGS,
- PySSL_SSLwrite_doc},
+ PySSL_SSLwrite_doc},
{"read", (PyCFunction)PySSL_SSLread, METH_VARARGS,
- PySSL_SSLread_doc},
+ PySSL_SSLread_doc},
{"server", (PyCFunction)PySSL_server, METH_NOARGS},
{"issuer", (PyCFunction)PySSL_issuer, METH_NOARGS},
- {"peer_certificate", (PyCFunction)PySSL_peercert, METH_NOARGS},
- {"shutdown", (PyCFunction)PySSL_SSLshutdown, METH_NOARGS,
- PySSL_SSLshutdown_doc},
+ {"peer_certificate", (PyCFunction)PySSL_peercert, METH_VARARGS,
+ PySSL_peercert_doc},
+ {"cipher", (PyCFunction)PySSL_cipher, METH_NOARGS},
{NULL, NULL}
};
@@ -924,7 +1345,7 @@
"RAND_add(string, entropy)\n\
\n\
Mix string into the OpenSSL PRNG state. entropy (a float) is a lower\n\
-bound on the entropy contained in string.");
+bound on the entropy contained in string. See RFC 1750.");
static PyObject *
PySSL_RAND_status(PyObject *self)
@@ -961,9 +1382,9 @@
PyDoc_STRVAR(PySSL_RAND_egd_doc,
"RAND_egd(path) -> bytes\n\
\n\
-Queries the entropy gather daemon (EGD) on socket path. Returns number\n\
-of bytes read. Raises ssl.sslerror if connection to EGD fails or\n\
-if it does provide enough data to seed PRNG.");
+Queries the entropy gather daemon (EGD) on the socket named by 'path'.\n\
+Returns number of bytes read. Raises SSLError if connection to EGD\n\
+fails or if it does provide enough data to seed PRNG.");
#endif
@@ -972,6 +1393,8 @@
static PyMethodDef PySSL_methods[] = {
{"sslwrap", PySSL_sslwrap,
METH_VARARGS, ssl_doc},
+ {"_test_decode_cert", PySSL_test_decode_certificate,
+ METH_VARARGS},
#ifdef HAVE_OPENSSL_RAND
{"RAND_add", PySSL_RAND_add, METH_VARARGS,
PySSL_RAND_add_doc},
@@ -984,6 +1407,73 @@
};
+#ifdef WITH_THREAD
+
+/* an implementation of OpenSSL threading operations in terms
+ of the Python C thread library */
+
+static PyThread_type_lock *_ssl_locks = NULL;
+
+static unsigned long _ssl_thread_id_function (void) {
+ return PyThread_get_thread_ident();
+}
+
+static void _ssl_thread_locking_function (int mode, int n, const char *file, int line) {
+ /* this function is needed to perform locking on shared data
+ structures. (Note that OpenSSL uses a number of global data
+ structures that will be implicitly shared whenever multiple threads
+ use OpenSSL.) Multi-threaded applications will crash at random if
+ it is not set.
+
+ locking_function() must be able to handle up to CRYPTO_num_locks()
+ different mutex locks. It sets the n-th lock if mode & CRYPTO_LOCK, and
+ releases it otherwise.
+
+ file and line are the file number of the function setting the
+ lock. They can be useful for debugging.
+ */
+
+ if ((_ssl_locks == NULL) ||
+ (n < 0) || (n >= _ssl_locks_count))
+ return;
+
+ if (mode & CRYPTO_LOCK) {
+ PyThread_acquire_lock(_ssl_locks[n], 1);
+ } else {
+ PyThread_release_lock(_ssl_locks[n]);
+ }
+}
+
+static int _setup_ssl_threads(void) {
+
+ int i;
+
+ if (_ssl_locks == NULL) {
+ _ssl_locks_count = CRYPTO_num_locks();
+ _ssl_locks = (PyThread_type_lock *)
+ malloc(sizeof(PyThread_type_lock) * _ssl_locks_count);
+ if (_ssl_locks == NULL)
+ return 0;
+ memset(_ssl_locks, 0, sizeof(PyThread_type_lock) * _ssl_locks_count);
+ for (i = 0; i < _ssl_locks_count; i++) {
+ _ssl_locks[i] = PyThread_allocate_lock();
+ if (_ssl_locks[i] == NULL) {
+ int j;
+ for (j = 0; j < i; j++) {
+ PyThread_free_lock(_ssl_locks[j]);
+ }
+ free(_ssl_locks);
+ return 0;
+ }
+ }
+ CRYPTO_set_locking_callback(_ssl_thread_locking_function);
+ CRYPTO_set_id_callback(_ssl_thread_id_function);
+ }
+ return 1;
+}
+
+#endif /* def HAVE_THREAD */
+
PyDoc_STRVAR(module_doc,
"Implementation module for SSL socket operations. See the socket module\n\
for documentation.");
@@ -1006,15 +1496,21 @@
/* Init OpenSSL */
SSL_load_error_strings();
+#ifdef WITH_THREAD
+ /* note that this will start threading if not already started */
+ if (!_setup_ssl_threads()) {
+ return;
+ }
+#endif
SSLeay_add_ssl_algorithms();
/* Add symbols to module dict */
- PySSLErrorObject = PyErr_NewException("ssl.sslerror",
+ PySSLErrorObject = PyErr_NewException("ssl.SSLError",
PySocketModule.error,
NULL);
if (PySSLErrorObject == NULL)
return;
- if (PyDict_SetItemString(d, "sslerror", PySSLErrorObject) != 0)
+ if (PyDict_SetItemString(d, "SSLError", PySSLErrorObject) != 0)
return;
if (PyDict_SetItemString(d, "SSLType",
(PyObject *)&PySSL_Type) != 0)
Modified: python/branches/py3k-importlib/Modules/bz2module.c
==============================================================================
--- python/branches/py3k-importlib/Modules/bz2module.c (original)
+++ python/branches/py3k-importlib/Modules/bz2module.c Fri Sep 21 03:17:09 2007
@@ -229,6 +229,7 @@
size_t increment; /* amount to increment the buffer */
PyObject *v;
int bzerror;
+ int bytes_read;
total_v_size = n > 0 ? n : 100;
v = PyBytes_FromStringAndSize((char *)NULL, total_v_size);
@@ -241,8 +242,10 @@
for (;;) {
Py_BEGIN_ALLOW_THREADS
do {
- BZ2_bzRead(&bzerror, f->fp, &c, 1);
+ bytes_read = BZ2_bzRead(&bzerror, f->fp, &c, 1);
f->pos++;
+ if (bytes_read == 0)
+ break;
*buf++ = c;
} while (bzerror == BZ_OK && c != '\n' && buf != end);
Py_END_ALLOW_THREADS
Modified: python/branches/py3k-importlib/Objects/dictobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/dictobject.c (original)
+++ python/branches/py3k-importlib/Objects/dictobject.c Fri Sep 21 03:17:09 2007
@@ -149,7 +149,7 @@
/* forward declarations */
static dictentry *
-lookdict_string(dictobject *mp, PyObject *key, long hash);
+lookdict_unicode(dictobject *mp, PyObject *key, long hash);
#ifdef SHOW_CONVERSION_COUNTS
static long created = 0L;
@@ -218,7 +218,7 @@
return NULL;
EMPTY_TO_MINSIZE(mp);
}
- mp->ma_lookup = lookdict_string;
+ mp->ma_lookup = lookdict_unicode;
#ifdef SHOW_CONVERSION_COUNTS
++created;
#endif
@@ -243,7 +243,7 @@
lookdict() is general-purpose, and may return NULL if (and only if) a
comparison raises an exception (this was new in Python 2.5).
-lookdict_string() below is specialized to string keys, comparison of which can
+lookdict_unicode() below is specialized to string keys, comparison of which can
never raise an exception; that function can never return NULL. For both, when
the key isn't found a dictentry* is returned for which the me_value field is
NULL; this is the slot in the dict at which the key would have been found, and
@@ -325,17 +325,37 @@
return 0;
}
+/* Return 1 if two unicode objects are equal, 0 if not. */
+static int
+unicode_eq(PyObject *aa, PyObject *bb)
+{
+ PyUnicodeObject *a = (PyUnicodeObject *)aa;
+ PyUnicodeObject *b = (PyUnicodeObject *)bb;
+
+ if (a->length != b->length)
+ return 0;
+ if (a->length == 0)
+ return 1;
+ if (a->str[0] != b->str[0])
+ return 0;
+ if (a->length == 1)
+ return 1;
+ return memcmp(a->str, b->str, a->length * sizeof(Py_UNICODE)) == 0;
+}
+
+
/*
- * Hacked up version of lookdict which can assume keys are always strings;
- * this assumption allows testing for errors during PyObject_RichCompareBool()
- * to be dropped; string-string comparisons never raise exceptions. This also
- * means we don't need to go through PyObject_RichCompareBool(); we can always
- * use _PyString_Eq() directly.
+ * Hacked up version of lookdict which can assume keys are always
+ * unicodes; this assumption allows testing for errors during
+ * PyObject_RichCompareBool() to be dropped; unicode-unicode
+ * comparisons never raise exceptions. This also means we don't need
+ * to go through PyObject_RichCompareBool(); we can always use
+ * unicode_eq() directly.
*
- * This is valuable because dicts with only string keys are very common.
+ * This is valuable because dicts with only unicode keys are very common.
*/
static dictentry *
-lookdict_string(dictobject *mp, PyObject *key, register long hash)
+lookdict_unicode(dictobject *mp, PyObject *key, register long hash)
{
register size_t i;
register size_t perturb;
@@ -344,11 +364,11 @@
dictentry *ep0 = mp->ma_table;
register dictentry *ep;
- /* Make sure this function doesn't have to handle non-string keys,
+ /* Make sure this function doesn't have to handle non-unicode keys,
including subclasses of str; e.g., one reason to subclass
- strings is to override __eq__, and for speed we don't cater to
+ unicodes is to override __eq__, and for speed we don't cater to
that here. */
- if (!PyString_CheckExact(key)) {
+ if (!PyUnicode_CheckExact(key)) {
#ifdef SHOW_CONVERSION_COUNTS
++converted;
#endif
@@ -362,7 +382,7 @@
if (ep->me_key == dummy)
freeslot = ep;
else {
- if (ep->me_hash == hash && _PyString_Eq(ep->me_key, key))
+ if (ep->me_hash == hash && unicode_eq(ep->me_key, key))
return ep;
freeslot = NULL;
}
@@ -377,7 +397,7 @@
if (ep->me_key == key
|| (ep->me_hash == hash
&& ep->me_key != dummy
- && _PyString_Eq(ep->me_key, key)))
+ && unicode_eq(ep->me_key, key)))
return ep;
if (ep->me_key == dummy && freeslot == NULL)
freeslot = ep;
@@ -615,8 +635,8 @@
PyErr_BadInternalCall();
return NULL;
}
- if (!PyString_CheckExact(key) ||
- (hash = ((PyStringObject *) key)->ob_shash) == -1)
+ if (!PyUnicode_CheckExact(key) ||
+ (hash = ((PyUnicodeObject *) key)->hash) == -1)
{
hash = PyObject_Hash(key);
if (hash == -1) {
@@ -695,8 +715,8 @@
return -1;
}
assert(key);
- if (!PyString_CheckExact(key) ||
- (hash = ((PyStringObject *) key)->ob_shash) == -1) {
+ if (!PyUnicode_CheckExact(key) ||
+ (hash = ((PyUnicodeObject *) key)->hash) == -1) {
hash = PyObject_Hash(key);
if (hash == -1)
return -1;
@@ -975,8 +995,8 @@
long hash;
dictentry *ep;
assert(mp->ma_table != NULL);
- if (!PyString_CheckExact(key) ||
- (hash = ((PyStringObject *) key)->ob_shash) == -1) {
+ if (!PyUnicode_CheckExact(key) ||
+ (hash = ((PyUnicodeObject *) key)->hash) == -1) {
hash = PyObject_Hash(key);
if (hash == -1)
return NULL;
@@ -1547,8 +1567,8 @@
long hash;
dictentry *ep;
- if (!PyString_CheckExact(key) ||
- (hash = ((PyStringObject *) key)->ob_shash) == -1) {
+ if (!PyUnicode_CheckExact(key) ||
+ (hash = ((PyUnicodeObject *) key)->hash) == -1) {
hash = PyObject_Hash(key);
if (hash == -1)
return NULL;
@@ -1571,8 +1591,8 @@
if (!PyArg_UnpackTuple(args, "get", 1, 2, &key, &failobj))
return NULL;
- if (!PyString_CheckExact(key) ||
- (hash = ((PyStringObject *) key)->ob_shash) == -1) {
+ if (!PyUnicode_CheckExact(key) ||
+ (hash = ((PyUnicodeObject *) key)->hash) == -1) {
hash = PyObject_Hash(key);
if (hash == -1)
return NULL;
@@ -1600,8 +1620,8 @@
if (!PyArg_UnpackTuple(args, "setdefault", 1, 2, &key, &failobj))
return NULL;
- if (!PyString_CheckExact(key) ||
- (hash = ((PyStringObject *) key)->ob_shash) == -1) {
+ if (!PyUnicode_CheckExact(key) ||
+ (hash = ((PyUnicodeObject *) key)->hash) == -1) {
hash = PyObject_Hash(key);
if (hash == -1)
return NULL;
@@ -1646,8 +1666,8 @@
"pop(): dictionary is empty");
return NULL;
}
- if (!PyString_CheckExact(key) ||
- (hash = ((PyStringObject *) key)->ob_shash) == -1) {
+ if (!PyUnicode_CheckExact(key) ||
+ (hash = ((PyUnicodeObject *) key)->hash) == -1) {
hash = PyObject_Hash(key);
if (hash == -1)
return NULL;
@@ -1842,8 +1862,8 @@
dictobject *mp = (dictobject *)op;
dictentry *ep;
- if (!PyString_CheckExact(key) ||
- (hash = ((PyStringObject *) key)->ob_shash) == -1) {
+ if (!PyUnicode_CheckExact(key) ||
+ (hash = ((PyUnicodeObject *) key)->hash) == -1) {
hash = PyObject_Hash(key);
if (hash == -1)
return -1;
@@ -1889,7 +1909,7 @@
/* It's guaranteed that tp->alloc zeroed out the struct. */
assert(d->ma_table == NULL && d->ma_fill == 0 && d->ma_used == 0);
INIT_NONZERO_DICT_SLOTS(d);
- d->ma_lookup = lookdict_string;
+ d->ma_lookup = lookdict_unicode;
#ifdef SHOW_CONVERSION_COUNTS
++created;
#endif
Modified: python/branches/py3k-importlib/Objects/genobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/genobject.c (original)
+++ python/branches/py3k-importlib/Objects/genobject.c Fri Sep 21 03:17:09 2007
@@ -252,7 +252,6 @@
Py_INCREF(typ);
}
}
-
else {
/* Not something you can raise. throw() fails. */
PyErr_Format(PyExc_TypeError,
Modified: python/branches/py3k-importlib/Objects/listobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/listobject.c (original)
+++ python/branches/py3k-importlib/Objects/listobject.c Fri Sep 21 03:17:09 2007
@@ -297,7 +297,10 @@
so must refetch the list size on each iteration. */
for (i = 0; i < Py_Size(v); ++i) {
int status;
+ if (Py_EnterRecursiveCall(" while getting the repr of a list"))
+ goto Done;
s = PyObject_Repr(v->ob_item[i]);
+ Py_LeaveRecursiveCall();
if (s == NULL)
goto Done;
status = PyList_Append(pieces, s);
Modified: python/branches/py3k-importlib/Objects/longobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/longobject.c (original)
+++ python/branches/py3k-importlib/Objects/longobject.c Fri Sep 21 03:17:09 2007
@@ -2197,10 +2197,18 @@
i = -(i);
}
#define LONG_BIT_PyLong_SHIFT (8*sizeof(long) - PyLong_SHIFT)
+ /* The following loop produces a C long x such that (unsigned long)x
+ is congruent to the absolute value of v modulo ULONG_MAX. The
+ resulting x is nonzero if and only if v is. */
while (--i >= 0) {
/* Force a native long #-bits (32 or 64) circular shift */
x = ((x << PyLong_SHIFT) & ~PyLong_MASK) | ((x >> LONG_BIT_PyLong_SHIFT) & PyLong_MASK);
x += v->ob_digit[i];
+ /* If the addition above overflowed (thinking of x as
+ unsigned), we compensate by incrementing. This preserves
+ the value modulo ULONG_MAX. */
+ if ((unsigned long)x < v->ob_digit[i])
+ x++;
}
#undef LONG_BIT_PyLong_SHIFT
x = x * sign;
Modified: python/branches/py3k-importlib/Objects/object.c
==============================================================================
--- python/branches/py3k-importlib/Objects/object.c (original)
+++ python/branches/py3k-importlib/Objects/object.c Fri Sep 21 03:17:09 2007
@@ -271,14 +271,18 @@
#endif
clearerr(fp); /* Clear any previous error condition */
if (op == NULL) {
+ Py_BEGIN_ALLOW_THREADS
fprintf(fp, "<nil>");
+ Py_END_ALLOW_THREADS
}
else {
if (op->ob_refcnt <= 0)
/* XXX(twouters) cast refcount to long until %zd is
universally available */
+ Py_BEGIN_ALLOW_THREADS
fprintf(fp, "<refcnt %ld at %p>",
(long)op->ob_refcnt, op);
+ Py_END_ALLOW_THREADS
else {
PyObject *s;
if (flags & Py_PRINT_RAW)
Modified: python/branches/py3k-importlib/Objects/unicodeobject.c
==============================================================================
--- python/branches/py3k-importlib/Objects/unicodeobject.c (original)
+++ python/branches/py3k-importlib/Objects/unicodeobject.c Fri Sep 21 03:17:09 2007
@@ -6587,21 +6587,27 @@
return (PyObject*) PyUnicode_FromUnicode(&self->str[index], 1);
}
+/* Believe it or not, this produces the same value for ASCII strings
+ as string_hash(). */
static long
unicode_hash(PyUnicodeObject *self)
{
- if (self->hash != -1) {
- return self->hash;
- }
- else {
- /* Since Unicode objects compare equal to their UTF-8 string
- counterparts, we hash the UTF-8 string. */
- PyObject *v = _PyUnicode_AsDefaultEncodedString((PyObject*)self, NULL);
- if (v == NULL)
- return -1;
- assert(PyString_CheckExact(v));
- return self->hash = v->ob_type->tp_hash(v);
- }
+ Py_ssize_t len;
+ Py_UNICODE *p;
+ long x;
+
+ if (self->hash != -1)
+ return self->hash;
+ len = Py_Size(self);
+ p = self->str;
+ x = *p << 7;
+ while (--len >= 0)
+ x = (1000003*x) ^ *p++;
+ x ^= Py_Size(self);
+ if (x == -1)
+ x = -2;
+ self->hash = x;
+ return x;
}
PyDoc_STRVAR(index__doc__,
Modified: python/branches/py3k-importlib/Python/ceval.c
==============================================================================
--- python/branches/py3k-importlib/Python/ceval.c (original)
+++ python/branches/py3k-importlib/Python/ceval.c Fri Sep 21 03:17:09 2007
@@ -28,8 +28,9 @@
typedef unsigned long long uint64;
#if defined(__ppc__) /* <- Don't know if this is the correct symbol; this
- section should work for GCC on any PowerPC platform,
- irrespective of OS. POWER? Who knows :-) */
+ section should work for GCC on any PowerPC
+ platform, irrespective of OS.
+ POWER? Who knows :-) */
#define READ_TIMESTAMP(var) ppc_getcounter(&var)
@@ -93,7 +94,8 @@
static PyObject * fast_function(PyObject *, PyObject ***, int, int, int);
static PyObject * do_call(PyObject *, PyObject ***, int, int);
static PyObject * ext_do_call(PyObject *, PyObject ***, int, int, int);
-static PyObject * update_keyword_args(PyObject *, int, PyObject ***,PyObject *);
+static PyObject * update_keyword_args(PyObject *, int, PyObject ***,
+ PyObject *);
static PyObject * update_star_args(int, int, PyObject *, PyObject ***);
static PyObject * load_args(PyObject ***, int);
#define CALL_FLAG_VAR 1
@@ -431,7 +433,7 @@
Py_SetRecursionLimit(int new_limit)
{
recursion_limit = new_limit;
- _Py_CheckRecursionLimit = recursion_limit;
+ _Py_CheckRecursionLimit = recursion_limit;
}
/* the macro Py_EnterRecursiveCall() only calls _Py_CheckRecursiveCall()
@@ -469,7 +471,7 @@
where);
return -1;
}
- _Py_CheckRecursionLimit = recursion_limit;
+ _Py_CheckRecursionLimit = recursion_limit;
return 0;
}
@@ -509,7 +511,8 @@
PyObject *
PyEval_EvalFrame(PyFrameObject *f) {
/* This is for backward compatibility with extension modules that
- used this API; core interpreter code should call PyEval_EvalFrameEx() */
+ used this API; core interpreter code should call
+ PyEval_EvalFrameEx() */
return PyEval_EvalFrameEx(f, 0);
}
@@ -519,7 +522,7 @@
#ifdef DXPAIRS
int lastopcode = 0;
#endif
- register PyObject **stack_pointer; /* Next free slot in value stack */
+ register PyObject **stack_pointer; /* Next free slot in value stack */
register unsigned char *next_instr;
register int opcode; /* Current opcode */
register int oparg; /* Current opcode argument, if any */
@@ -610,10 +613,10 @@
#define JUMPBY(x) (next_instr += (x))
/* OpCode prediction macros
- Some opcodes tend to come in pairs thus making it possible to predict
- the second code when the first is run. For example, COMPARE_OP is often
- followed by JUMP_IF_FALSE or JUMP_IF_TRUE. And, those opcodes are often
- followed by a POP_TOP.
+ Some opcodes tend to come in pairs thus making it possible to
+ predict the second code when the first is run. For example,
+ COMPARE_OP is often followed by JUMP_IF_FALSE or JUMP_IF_TRUE. And,
+ those opcodes are often followed by a POP_TOP.
Verifying the prediction costs a single high-speed test of register
variable against a constant. If the pairing was good, then the
@@ -660,11 +663,13 @@
#define PUSH(v) { (void)(BASIC_PUSH(v), \
lltrace && prtrace(TOP(), "push")); \
assert(STACK_LEVEL() <= co->co_stacksize); }
-#define POP() ((void)(lltrace && prtrace(TOP(), "pop")), BASIC_POP())
+#define POP() ((void)(lltrace && prtrace(TOP(), "pop")), \
+ BASIC_POP())
#define STACKADJ(n) { (void)(BASIC_STACKADJ(n), \
lltrace && prtrace(TOP(), "stackadj")); \
assert(STACK_LEVEL() <= co->co_stacksize); }
-#define EXT_POP(STACK_POINTER) (lltrace && prtrace((STACK_POINTER)[-1], "ext_pop"), *--(STACK_POINTER))
+#define EXT_POP(STACK_POINTER) (lltrace && prtrace((STACK_POINTER)[-1], \
+ "ext_pop"), *--(STACK_POINTER))
#else
#define PUSH(v) BASIC_PUSH(v)
#define POP() BASIC_POP()
@@ -805,11 +810,11 @@
Py_MakePendingCalls() above. */
if (--_Py_Ticker < 0) {
- if (*next_instr == SETUP_FINALLY) {
- /* Make the last opcode before
- a try: finally: block uninterruptable. */
- goto fast_next_opcode;
- }
+ if (*next_instr == SETUP_FINALLY) {
+ /* Make the last opcode before
+ a try: finally: block uninterruptable. */
+ goto fast_next_opcode;
+ }
_Py_Ticker = _Py_CheckInterval;
tstate->tick_counter++;
#ifdef WITH_TSC
@@ -1467,8 +1472,8 @@
case RAISE_VARARGS:
v = w = NULL;
switch (oparg) {
- case 2:
- v = POP(); /* cause */
+ case 2:
+ v = POP(); /* cause */
case 1:
w = POP(); /* exc */
case 0: /* Fallthrough */
@@ -1568,7 +1573,8 @@
if ((x = f->f_locals) != NULL) {
if ((err = PyObject_DelItem(x, w)) != 0)
format_exc_check_arg(PyExc_NameError,
- NAME_ERROR_MSG ,w);
+ NAME_ERROR_MSG,
+ w);
break;
}
PyErr_Format(PyExc_SystemError,
@@ -1579,8 +1585,10 @@
PREDICTED_WITH_ARG(UNPACK_SEQUENCE);
case UNPACK_SEQUENCE:
v = POP();
- if (PyTuple_CheckExact(v) && PyTuple_GET_SIZE(v) == oparg) {
- PyObject **items = ((PyTupleObject *)v)->ob_item;
+ if (PyTuple_CheckExact(v) &&
+ PyTuple_GET_SIZE(v) == oparg) {
+ PyObject **items = \
+ ((PyTupleObject *)v)->ob_item;
while (oparg--) {
w = items[oparg];
Py_INCREF(w);
@@ -1588,15 +1596,17 @@
}
Py_DECREF(v);
continue;
- } else if (PyList_CheckExact(v) && PyList_GET_SIZE(v) == oparg) {
- PyObject **items = ((PyListObject *)v)->ob_item;
+ } else if (PyList_CheckExact(v) &&
+ PyList_GET_SIZE(v) == oparg) {
+ PyObject **items = \
+ ((PyListObject *)v)->ob_item;
while (oparg--) {
w = items[oparg];
Py_INCREF(w);
PUSH(w);
}
} else if (unpack_iterable(v, oparg, -1,
- stack_pointer + oparg)) {
+ stack_pointer + oparg)) {
stack_pointer += oparg;
} else {
/* unpack_iterable() raised an exception */
@@ -1669,7 +1679,8 @@
else {
x = PyObject_GetItem(v, w);
if (x == NULL && PyErr_Occurred()) {
- if (!PyErr_ExceptionMatches(PyExc_KeyError))
+ if (!PyErr_ExceptionMatches(
+ PyExc_KeyError))
break;
PyErr_Clear();
}
@@ -1681,7 +1692,7 @@
if (x == NULL) {
format_exc_check_arg(
PyExc_NameError,
- NAME_ERROR_MSG ,w);
+ NAME_ERROR_MSG, w);
break;
}
}
@@ -1782,13 +1793,10 @@
UNBOUNDLOCAL_ERROR_MSG,
v);
} else {
- v = PyTuple_GET_ITEM(
- co->co_freevars,
- oparg - PyTuple_GET_SIZE(co->co_cellvars));
- format_exc_check_arg(
- PyExc_NameError,
- UNBOUNDFREE_ERROR_MSG,
- v);
+ v = PyTuple_GET_ITEM(co->co_freevars, oparg -
+ PyTuple_GET_SIZE(co->co_cellvars));
+ format_exc_check_arg(PyExc_NameError,
+ UNBOUNDFREE_ERROR_MSG, v);
}
break;
@@ -2046,7 +2054,8 @@
continue;
}
if (PyErr_Occurred()) {
- if (!PyErr_ExceptionMatches(PyExc_StopIteration))
+ if (!PyErr_ExceptionMatches(
+ PyExc_StopIteration))
break;
PyErr_Clear();
}
@@ -2072,9 +2081,10 @@
case SETUP_LOOP:
case SETUP_EXCEPT:
case SETUP_FINALLY:
- /* NOTE: If you add any new block-setup opcodes that are
- not try/except/finally handlers, you may need to
- update the PyGen_NeedsFinalizing() function. */
+ /* NOTE: If you add any new block-setup opcodes that
+ are not try/except/finally handlers, you may need
+ to update the PyGen_NeedsFinalizing() function.
+ */
PyFrame_BlockSetup(f, opcode, INSTR_OFFSET() + oparg,
STACK_LEVEL());
@@ -2500,7 +2510,7 @@
}
/* pop frame */
- exit_eval_frame:
+exit_eval_frame:
Py_LeaveRecursiveCall();
tstate->frame = f->f_back;
@@ -2761,9 +2771,9 @@
return PyGen_New(f);
}
- retval = PyEval_EvalFrameEx(f,0);
+ retval = PyEval_EvalFrameEx(f,0);
- fail: /* Jump here from prelude on failure */
+fail: /* Jump here from prelude on failure */
/* decref'ing the frame can cause __del__ methods to get invoked,
which can call back into Python. While we're done with the
@@ -2772,7 +2782,7 @@
*/
assert(tstate != NULL);
++tstate->recursion_depth;
- Py_DECREF(f);
+ Py_DECREF(f);
--tstate->recursion_depth;
return retval;
}
@@ -2876,7 +2886,7 @@
tstate->exc_type = type;
tstate->exc_value = value;
tstate->exc_traceback = tb;
- PyException_SetTraceback(value, tb);
+ PyException_SetTraceback(value, tb);
Py_XDECREF(tmp_type);
Py_XDECREF(tmp_value);
Py_XDECREF(tmp_tb);
@@ -2927,7 +2937,7 @@
static enum why_code
do_raise(PyObject *exc, PyObject *cause)
{
- PyObject *type = NULL, *value = NULL, *tb = NULL;
+ PyObject *type = NULL, *value = NULL, *tb = NULL;
if (exc == NULL) {
/* Reraise */
@@ -2935,16 +2945,16 @@
type = tstate->exc_type;
value = tstate->exc_value;
tb = tstate->exc_traceback;
- if (type == Py_None) {
- PyErr_SetString(PyExc_RuntimeError,
- "No active exception to reraise");
- return WHY_EXCEPTION;
- }
- Py_XINCREF(type);
+ if (type == Py_None) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "No active exception to reraise");
+ return WHY_EXCEPTION;
+ }
+ Py_XINCREF(type);
Py_XINCREF(value);
Py_XINCREF(tb);
- PyErr_Restore(type, value, tb);
- return WHY_RERAISE;
+ PyErr_Restore(type, value, tb);
+ return WHY_RERAISE;
}
/* We support the following forms of raise:
@@ -2953,11 +2963,11 @@
raise <type> */
if (PyExceptionClass_Check(exc)) {
- type = exc;
- value = PyObject_CallObject(exc, NULL);
+ type = exc;
+ value = PyObject_CallObject(exc, NULL);
if (value == NULL)
- goto raise_error;
- }
+ goto raise_error;
+ }
else if (PyExceptionInstance_Check(exc)) {
value = exc;
type = PyExceptionInstance_Class(exc);
@@ -2966,31 +2976,32 @@
else {
/* Not something you can raise. You get an exception
anyway, just not what you specified :-) */
- Py_DECREF(exc);
+ Py_DECREF(exc);
PyErr_SetString(PyExc_TypeError,
- "exceptions must derive from BaseException");
+ "exceptions must derive from BaseException");
goto raise_error;
}
- tb = PyException_GetTraceback(value);
- if (cause) {
- PyObject *fixed_cause;
- if (PyExceptionClass_Check(cause)) {
- fixed_cause = PyObject_CallObject(cause, NULL);
- if (fixed_cause == NULL)
- goto raise_error;
- Py_DECREF(cause);
- }
- else if (PyExceptionInstance_Check(cause)) {
- fixed_cause = cause;
- }
- else {
- PyErr_SetString(PyExc_TypeError,
- "exception causes must derive from BaseException");
- goto raise_error;
- }
- PyException_SetCause(value, fixed_cause);
- }
+ tb = PyException_GetTraceback(value);
+ if (cause) {
+ PyObject *fixed_cause;
+ if (PyExceptionClass_Check(cause)) {
+ fixed_cause = PyObject_CallObject(cause, NULL);
+ if (fixed_cause == NULL)
+ goto raise_error;
+ Py_DECREF(cause);
+ }
+ else if (PyExceptionInstance_Check(cause)) {
+ fixed_cause = cause;
+ }
+ else {
+ PyErr_SetString(PyExc_TypeError,
+ "exception causes must derive from "
+ "BaseException");
+ goto raise_error;
+ }
+ PyException_SetCause(value, fixed_cause);
+ }
PyErr_Restore(type, value, tb);
return WHY_EXCEPTION;
@@ -3186,18 +3197,18 @@
represents a jump backwards, call the trace function.
*/
if ((frame->f_lasti < *instr_lb || frame->f_lasti >= *instr_ub)) {
- int line;
- PyAddrPair bounds;
+ int line;
+ PyAddrPair bounds;
- line = PyCode_CheckLineNumber(frame->f_code, frame->f_lasti,
- &bounds);
- if (line >= 0) {
+ line = PyCode_CheckLineNumber(frame->f_code, frame->f_lasti,
+ &bounds);
+ if (line >= 0) {
frame->f_lineno = line;
result = call_trace(func, obj, frame,
PyTrace_LINE, Py_None);
- }
- *instr_lb = bounds.ap_lower;
- *instr_ub = bounds.ap_upper;
+ }
+ *instr_lb = bounds.ap_lower;
+ *instr_ub = bounds.ap_upper;
}
else if (frame->f_lasti <= *instr_prev) {
result = call_trace(func, obj, frame, PyTrace_LINE, Py_None);
@@ -3583,9 +3594,9 @@
PyObject *value = EXT_POP(*pp_stack);
PyObject *key = EXT_POP(*pp_stack);
if (PyDict_GetItem(kwdict, key) != NULL) {
- PyErr_Format(PyExc_TypeError,
- "%.200s%s got multiple values "
- "for keyword argument '%.200s'",
+ PyErr_Format(PyExc_TypeError,
+ "%.200s%s got multiple values "
+ "for keyword argument '%.200s'",
PyEval_GetFuncName(func),
PyEval_GetFuncDesc(func),
PyUnicode_AsString(key));
@@ -3675,7 +3686,7 @@
PCALL(PCALL_OTHER);
#endif
result = PyObject_Call(func, callargs, kwdict);
- call_fail:
+call_fail:
Py_XDECREF(callargs);
Py_XDECREF(kwdict);
return result;
@@ -3763,7 +3774,7 @@
PCALL(PCALL_OTHER);
#endif
result = PyObject_Call(func, callargs, kwdict);
- ext_call_fail:
+ext_call_fail:
Py_XDECREF(callargs);
Py_XDECREF(kwdict);
Py_XDECREF(stararg);
@@ -3967,8 +3978,9 @@
if (v->ob_refcnt == 2) {
/* In the common case, there are 2 references to the value
* stored in 'variable' when the += is performed: one on the
- * value stack (in 'v') and one still stored in the 'variable'.
- * We try to delete the variable now to reduce the refcnt to 1.
+ * value stack (in 'v') and one still stored in the
+ * 'variable'. We try to delete the variable now to reduce
+ * the refcnt to 1.
*/
switch (*next_instr) {
case STORE_FAST:
@@ -3981,7 +3993,8 @@
}
case STORE_DEREF:
{
- PyObject **freevars = f->f_localsplus + f->f_code->co_nlocals;
+ PyObject **freevars = (f->f_localsplus +
+ f->f_code->co_nlocals);
PyObject *c = freevars[PEEKARG()];
if (PyCell_GET(c) == v)
PyCell_Set(c, NULL);
@@ -4009,10 +4022,10 @@
*/
if (_PyString_Resize(&v, new_len) != 0) {
/* XXX if _PyString_Resize() fails, 'v' has been
- * deallocated so it cannot be put back into 'variable'.
- * The MemoryError is raised when there is no value in
- * 'variable', which might (very remotely) be a cause
- * of incompatibilities.
+ * deallocated so it cannot be put back into
+ * 'variable'. The MemoryError is raised when there
+ * is no value in 'variable', which might (very
+ * remotely) be a cause of incompatibilities.
*/
return NULL;
}
Modified: python/branches/py3k-importlib/Python/compile.c
==============================================================================
--- python/branches/py3k-importlib/Python/compile.c (original)
+++ python/branches/py3k-importlib/Python/compile.c Fri Sep 21 03:17:09 2007
@@ -1428,7 +1428,7 @@
st = (stmt_ty)asdl_seq_GET(s->v.FunctionDef.body, 0);
docstring = compiler_isdocstring(st);
- if (docstring)
+ if (docstring && Py_OptimizeFlag < 2)
first_const = st->v.Expr.value->v.Str.s;
if (compiler_add_o(c, c->u->u_consts, first_const) < 0) {
compiler_exit_scope(c);
More information about the Python-3000-checkins
mailing list