PYTHON-1068 - Update Decimal128 for latest spec changes

This commit is contained in:
Bernie Hackett 2016-05-05 16:52:30 -07:00 committed by Bernie Hackett
parent e5984d367c
commit 7933d5a95f
9 changed files with 3722 additions and 188 deletions

View File

@ -12,7 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tools for working with 128-bit IEEE 754-2008 decimal floating point numbers.
"""Tools for working with the BSON decimal128 type.
.. versionadded:: 3.4
.. note:: The Decimal128 BSON type requires MongoDB 3.4+.
"""
import decimal
@ -52,9 +56,9 @@ _UNPACK_64 = struct.Struct("<Q").unpack
_EXPONENT_MASK = 3 << 61
_EXPONENT_BIAS = 6176
_EXPONENT_MAX = 6111
_EXPONENT_MIN = -6176
_MAX_BIT_LENGTH = 113
_EXPONENT_MAX = 6144
_EXPONENT_MIN = -6143
_MAX_DIGITS = 34
_INF = 0x7800000000000000
_NAN = 0x7c00000000000000
@ -68,6 +72,34 @@ _PNAN = (_NAN, 0)
_NSNAN = (_SNAN + _SIGN, 0)
_PSNAN = (_SNAN, 0)
_CTX_OPTIONS = {
'prec': _MAX_DIGITS,
'rounding': decimal.ROUND_HALF_EVEN,
'Emin': _EXPONENT_MIN,
'Emax': _EXPONENT_MAX,
'capitals': 1,
'flags': [],
'traps': [decimal.InvalidOperation,
decimal.Overflow,
decimal.Inexact]
}
if _PY3:
_CTX_OPTIONS['clamp'] = 1
else:
_CTX_OPTIONS['_clamp'] = 1
_DEC128_CTX = decimal.Context(**_CTX_OPTIONS.copy())
def create_decimal128_context():
"""Returns an instance of :class:`decimal.Context` appropriate
for working with IEEE-754 128-bit decimal floating point values.
"""
opts = _CTX_OPTIONS.copy()
opts['traps'] = []
return decimal.Context(**opts)
def _decimal_to_128(value):
"""Converts a decimal.Decimal to BID (high bits, low bits).
@ -75,6 +107,9 @@ def _decimal_to_128(value):
:Parameters:
- `value`: An instance of decimal.Decimal
"""
with decimal.localcontext(_DEC128_CTX) as ctx:
value = ctx.create_decimal(value)
if value.is_infinite():
return _NINF if value.is_signed() else _PINF
@ -89,12 +124,6 @@ def _decimal_to_128(value):
significand = int("".join([str(digit) for digit in digits]))
bit_length = _bit_length(significand)
if exponent > _EXPONENT_MAX or exponent < _EXPONENT_MIN:
raise ValueError("Exponent is out of range for "
"Decimal128 encoding %d" % (exponent,))
if bit_length > _MAX_BIT_LENGTH:
raise ValueError("Unscaled value is out of range for "
"Decimal128 encoding %d" % (significand,))
high = 0
low = 0
@ -135,7 +164,51 @@ class Decimal128(object):
- `value`: An instance of :class:`decimal.Decimal`, string, or tuple of
(high bits, low bits) from Binary Integer Decimal (BID) format.
.. note:: To match the behavior of MongoDB's Decimal128 implementation
.. note:: :class:`~Decimal128` uses an instance of :class:`decimal.Context`
configured for IEEE-754 Decimal128 when validating parameters.
Signals like :class:`decimal.InvalidOperation`, :class:`decimal.Inexact`,
and :class:`decimal.Overflow` are trapped and raised as exceptions::
>>> Decimal128(".13.1")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
...
decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]
>>>
>>> Decimal128("1E-6177")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
...
decimal.Inexact: [<class 'decimal.Inexact'>]
>>>
>>> Decimal128("1E6145")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
...
decimal.Overflow: [<class 'decimal.Overflow'>, <class 'decimal.Rounded'>]
To ensure the result of a calculation can always be stored as BSON
Decimal128 use the context returned by
:func:`create_decimal128_context`::
>>> import decimal
>>> decimal128_ctx = create_decimal128_context()
>>> with decimal.localcontext(decimal128_ctx) as ctx:
... Decimal128(ctx.create_decimal(".13.3"))
...
Decimal128('NaN')
>>>
>>> with decimal.localcontext(decimal128_ctx) as ctx:
... Decimal128(ctx.create_decimal("1E-6177"))
...
Decimal128('0E-6176')
>>>
>>> with decimal.localcontext(DECIMAL128_CTX) as ctx:
... Decimal128(ctx.create_decimal("1E6145"))
...
Decimal128('Infinity')
To match the behavior of MongoDB's Decimal128 implementation
str(Decimal(value)) may not match str(Decimal128(value)) for NaN values::
>>> Decimal128(Decimal('NaN'))
@ -176,16 +249,7 @@ class Decimal128(object):
_type_marker = 19
def __init__(self, value):
if isinstance(value, _string_type):
# Really? decimal.Decimal doesn't care...
if value.startswith(' ') or value.endswith(' '):
raise ValueError("leading or trailing whitespace")
try:
dec = decimal.Decimal(value)
except decimal.InvalidOperation as exc:
raise ValueError(str(exc))
self.__high, self.__low = _decimal_to_128(dec)
elif isinstance(value, decimal.Decimal):
if isinstance(value, (_string_type, decimal.Decimal)):
self.__high, self.__low = _decimal_to_128(value)
elif isinstance(value, (list, tuple)):
if len(value) != 2:
@ -234,7 +298,8 @@ class Decimal128(object):
# Have to convert bytearray to bytes for python 2.6.
digits = [int(digit) for digit in str(_from_bytes(bytes(arr), 'big'))]
return decimal.Decimal((sign, digits, exponent))
with decimal.localcontext(_DEC128_CTX) as ctx:
return ctx.create_decimal((sign, digits, exponent))
@classmethod
def from_bid(cls, value):

View File

@ -339,152 +339,19 @@
"string": "-Infinity",
"to_extjson": false,
"extjson": "{\"d\" : {\"$numberDecimal\" : \"-inF\"}}"
},
{
"description": "Clamped",
"subject": "180000001364000a00000000000000000000000000fe5f00",
"string": "1E6112",
"match_string": "1.0E+6112"
},
{
"description": "Exact rounding",
"subject": "18000000136400000000000a5bc138938d44c64d31cc3700",
"string": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"match_string": "1.000000000000000000000000000000000E+999"
}
],
"parseErrors": [
{
"description": "Too many significand digits",
"subject": "100000000000000000000000000000000000000000000000000000000001"
},
{
"description": "Too many significand digits",
"subject": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"description": "Too many significand digits",
"subject": ".100000000000000000000000000000000000000000000000000000000000"
},
{
"description": "Incomplete Exponent",
"subject": "1e"
},
{
"description": "Exponent at the beginning",
"subject": "E01"
},
{
"description": "Exponent too large",
"subject": "1E6112"
},
{
"description": "Exponent too small",
"subject": "1E-6177"
},
{
"description": "Just a decimal place",
"subject": "."
},
{
"description": "2 decimal places",
"subject": "..3"
},
{
"description": "2 decimal places",
"subject": ".13.3"
},
{
"description": "2 decimal places",
"subject": "1..3"
},
{
"description": "2 decimal places",
"subject": "1.3.4"
},
{
"description": "2 decimal places",
"subject": "1.34."
},
{
"description": "Decimal with no digits",
"subject": ".e"
},
{
"description": "2 signs",
"subject": "+-32.4"
},
{
"description": "2 signs",
"subject": "-+32.4"
},
{
"description": "2 negative signs",
"subject": "--32.4"
},
{
"description": "2 negative signs",
"subject": "-32.-4"
},
{
"description": "End in negative sign",
"subject": "32.0-"
},
{
"description": "2 negative signs",
"subject": "32.4E--21"
},
{
"description": "2 negative signs",
"subject": "32.4E-2-1"
},
{
"description": "2 signs",
"subject": "32.4E+-21"
},
{
"description": "Empty string",
"subject": ""
},
{
"description": "leading white space positive number",
"subject": " 1"
},
{
"description": "leading white space negative number",
"subject": " -1"
},
{
"description": "trailing white space",
"subject": "1 "
},
{
"description": "Invalid",
"subject": "E"
},
{
"description": "Invalid",
"subject": "invalid"
},
{
"description": "Invalid",
"subject": "i"
},
{
"description": "Invalid",
"subject": "in"
},
{
"description": "Invalid",
"subject": "-in"
},
{
"description": "Invalid",
"subject": "Na"
},
{
"description": "Invalid",
"subject": "-Na"
},
{
"description": "Invalid",
"subject": "1.23abc"
},
{
"description": "Invalid",
"subject": "1.23abcE+02"
},
{
"description": "Invalid",
"subject": "1.23E+0aabs2"
}
]
}

View File

@ -0,0 +1,793 @@
{
"description": "Decimal128",
"bson_type": "0x13",
"test_key": "d",
"valid": [
{
"description": "[decq021] Normality",
"subject": "18000000136400F2AF967ED05C82DE3297FF6FDE3C40B000",
"string": "-1234567890123456789012345678901234"
},
{
"description": "[decq823] values around [u]int32 edges (zeros done earlier)",
"subject": "18000000136400010000800000000000000000000040B000",
"string": "-2147483649"
},
{
"description": "[decq822] values around [u]int32 edges (zeros done earlier)",
"subject": "18000000136400000000800000000000000000000040B000",
"string": "-2147483648"
},
{
"description": "[decq821] values around [u]int32 edges (zeros done earlier)",
"subject": "18000000136400FFFFFF7F0000000000000000000040B000",
"string": "-2147483647"
},
{
"description": "[decq820] values around [u]int32 edges (zeros done earlier)",
"subject": "18000000136400FEFFFF7F0000000000000000000040B000",
"string": "-2147483646"
},
{
"description": "[decq152] fold-downs (more below)",
"subject": "18000000136400393000000000000000000000000040B000",
"string": "-12345"
},
{
"description": "[decq154] fold-downs (more below)",
"subject": "18000000136400D20400000000000000000000000040B000",
"string": "-1234"
},
{
"description": "[decq006] derivative canonical plain strings",
"subject": "18000000136400EE0200000000000000000000000040B000",
"string": "-750"
},
{
"description": "[decq164] fold-downs (more below)",
"subject": "1800000013640039300000000000000000000000003CB000",
"string": "-123.45"
},
{
"description": "[decq156] fold-downs (more below)",
"subject": "180000001364007B0000000000000000000000000040B000",
"string": "-123"
},
{
"description": "[decq008] derivative canonical plain strings",
"subject": "18000000136400EE020000000000000000000000003EB000",
"string": "-75.0"
},
{
"description": "[decq158] fold-downs (more below)",
"subject": "180000001364000C0000000000000000000000000040B000",
"string": "-12"
},
{
"description": "[decq122] Nmax and similar",
"subject": "18000000136400FFFFFFFF638E8D37C087ADBE09EDFFDF00",
"string": "-9.999999999999999999999999999999999E+6144"
},
{
"description": "[decq002] (mostly derived from the Strawman 4 document and examples)",
"subject": "18000000136400EE020000000000000000000000003CB000",
"string": "-7.50"
},
{
"description": "[decq004] derivative canonical plain strings",
"subject": "18000000136400EE0200000000000000000000000042B000",
"string": "-7.50E+3"
},
{
"description": "[decq018] derivative canonical plain strings",
"subject": "18000000136400EE020000000000000000000000002EB000",
"string": "-7.50E-7"
},
{
"description": "[decq125] Nmax and similar",
"subject": "18000000136400F2AF967ED05C82DE3297FF6FDE3CFEDF00",
"string": "-1.234567890123456789012345678901234E+6144"
},
{
"description": "[decq131] fold-downs (more below)",
"subject": "18000000136400000000807F1BCF85B27059C8A43CFEDF00",
"string": "-1.230000000000000000000000000000000E+6144"
},
{
"description": "[decq162] fold-downs (more below)",
"subject": "180000001364007B000000000000000000000000003CB000",
"string": "-1.23"
},
{
"description": "[decq176] Nmin and below",
"subject": "18000000136400010000000A5BC138938D44C64D31008000",
"string": "-1.000000000000000000000000000000001E-6143"
},
{
"description": "[decq174] Nmin and below",
"subject": "18000000136400000000000A5BC138938D44C64D31008000",
"string": "-1.000000000000000000000000000000000E-6143"
},
{
"description": "[decq133] fold-downs (more below)",
"subject": "18000000136400000000000A5BC138938D44C64D31FEDF00",
"string": "-1.000000000000000000000000000000000E+6144"
},
{
"description": "[decq160] fold-downs (more below)",
"subject": "18000000136400010000000000000000000000000040B000",
"string": "-1"
},
{
"description": "[decq172] Nmin and below",
"subject": "180000001364000100000000000000000000000000428000",
"string": "-1E-6143"
},
{
"description": "[decq010] derivative canonical plain strings",
"subject": "18000000136400EE020000000000000000000000003AB000",
"string": "-0.750"
},
{
"description": "[decq012] derivative canonical plain strings",
"subject": "18000000136400EE0200000000000000000000000038B000",
"string": "-0.0750"
},
{
"description": "[decq014] derivative canonical plain strings",
"subject": "18000000136400EE0200000000000000000000000034B000",
"string": "-0.000750"
},
{
"description": "[decq016] derivative canonical plain strings",
"subject": "18000000136400EE0200000000000000000000000030B000",
"string": "-0.00000750"
},
{
"description": "[decq404] zeros",
"subject": "180000001364000000000000000000000000000000000000",
"string": "0E-6176"
},
{
"description": "[decq424] negative zeros",
"subject": "180000001364000000000000000000000000000000008000",
"string": "-0E-6176"
},
{
"description": "[decq407] zeros",
"subject": "1800000013640000000000000000000000000000003C3000",
"string": "0.00"
},
{
"description": "[decq427] negative zeros",
"subject": "1800000013640000000000000000000000000000003CB000",
"string": "-0.00"
},
{
"description": "[decq409] zeros",
"subject": "180000001364000000000000000000000000000000403000",
"string": "0"
},
{
"description": "[decq428] negative zeros",
"subject": "18000000136400000000000000000000000000000040B000",
"string": "-0"
},
{
"description": "[decq700] Selected DPD codes",
"subject": "180000001364000000000000000000000000000000403000",
"string": "0"
},
{
"description": "[decq406] zeros",
"subject": "1800000013640000000000000000000000000000003C3000",
"string": "0.00"
},
{
"description": "[decq426] negative zeros",
"subject": "1800000013640000000000000000000000000000003CB000",
"string": "-0.00"
},
{
"description": "[decq410] zeros",
"subject": "180000001364000000000000000000000000000000463000",
"string": "0E+3"
},
{
"description": "[decq431] negative zeros",
"subject": "18000000136400000000000000000000000000000046B000",
"string": "-0E+3"
},
{
"description": "[decq419] clamped zeros...",
"subject": "180000001364000000000000000000000000000000FE5F00",
"string": "0E+6111"
},
{
"description": "[decq432] negative zeros",
"subject": "180000001364000000000000000000000000000000FEDF00",
"string": "-0E+6111"
},
{
"description": "[decq405] zeros",
"subject": "180000001364000000000000000000000000000000000000",
"string": "0E-6176"
},
{
"description": "[decq425] negative zeros",
"subject": "180000001364000000000000000000000000000000008000",
"string": "-0E-6176"
},
{
"description": "[decq508] Specials",
"subject": "180000001364000000000000000000000000000000007800",
"string": "Infinity"
},
{
"description": "[decq528] Specials",
"subject": "18000000136400000000000000000000000000000000F800",
"string": "-Infinity"
},
{
"description": "[decq541] Specials",
"subject": "180000001364000000000000000000000000000000007C00",
"string": "NaN"
},
{
"description": "[decq074] Nmin and below",
"subject": "18000000136400000000000A5BC138938D44C64D31000000",
"string": "1.000000000000000000000000000000000E-6143"
},
{
"description": "[decq602] fold-down full sequence",
"subject": "18000000136400000000000A5BC138938D44C64D31FE5F00",
"string": "1.000000000000000000000000000000000E+6144"
},
{
"description": "[decq604] fold-down full sequence",
"subject": "180000001364000000000081EFAC855B416D2DEE04FE5F00",
"string": "1.00000000000000000000000000000000E+6143"
},
{
"description": "[decq606] fold-down full sequence",
"subject": "1800000013640000000080264B91C02220BE377E00FE5F00",
"string": "1.0000000000000000000000000000000E+6142"
},
{
"description": "[decq608] fold-down full sequence",
"subject": "1800000013640000000040EAED7446D09C2C9F0C00FE5F00",
"string": "1.000000000000000000000000000000E+6141"
},
{
"description": "[decq610] fold-down full sequence",
"subject": "18000000136400000000A0CA17726DAE0F1E430100FE5F00",
"string": "1.00000000000000000000000000000E+6140"
},
{
"description": "[decq612] fold-down full sequence",
"subject": "18000000136400000000106102253E5ECE4F200000FE5F00",
"string": "1.0000000000000000000000000000E+6139"
},
{
"description": "[decq614] fold-down full sequence",
"subject": "18000000136400000000E83C80D09F3C2E3B030000FE5F00",
"string": "1.000000000000000000000000000E+6138"
},
{
"description": "[decq616] fold-down full sequence",
"subject": "18000000136400000000E4D20CC8DCD2B752000000FE5F00",
"string": "1.00000000000000000000000000E+6137"
},
{
"description": "[decq618] fold-down full sequence",
"subject": "180000001364000000004A48011416954508000000FE5F00",
"string": "1.0000000000000000000000000E+6136"
},
{
"description": "[decq620] fold-down full sequence",
"subject": "18000000136400000000A1EDCCCE1BC2D300000000FE5F00",
"string": "1.000000000000000000000000E+6135"
},
{
"description": "[decq622] fold-down full sequence",
"subject": "18000000136400000080F64AE1C7022D1500000000FE5F00",
"string": "1.00000000000000000000000E+6134"
},
{
"description": "[decq624] fold-down full sequence",
"subject": "18000000136400000040B2BAC9E0191E0200000000FE5F00",
"string": "1.0000000000000000000000E+6133"
},
{
"description": "[decq626] fold-down full sequence",
"subject": "180000001364000000A0DEC5ADC935360000000000FE5F00",
"string": "1.000000000000000000000E+6132"
},
{
"description": "[decq628] fold-down full sequence",
"subject": "18000000136400000010632D5EC76B050000000000FE5F00",
"string": "1.00000000000000000000E+6131"
},
{
"description": "[decq630] fold-down full sequence",
"subject": "180000001364000000E8890423C78A000000000000FE5F00",
"string": "1.0000000000000000000E+6130"
},
{
"description": "[decq632] fold-down full sequence",
"subject": "18000000136400000064A7B3B6E00D000000000000FE5F00",
"string": "1.000000000000000000E+6129"
},
{
"description": "[decq634] fold-down full sequence",
"subject": "1800000013640000008A5D78456301000000000000FE5F00",
"string": "1.00000000000000000E+6128"
},
{
"description": "[decq636] fold-down full sequence",
"subject": "180000001364000000C16FF2862300000000000000FE5F00",
"string": "1.0000000000000000E+6127"
},
{
"description": "[decq638] fold-down full sequence",
"subject": "180000001364000080C6A47E8D0300000000000000FE5F00",
"string": "1.000000000000000E+6126"
},
{
"description": "[decq640] fold-down full sequence",
"subject": "1800000013640000407A10F35A0000000000000000FE5F00",
"string": "1.00000000000000E+6125"
},
{
"description": "[decq642] fold-down full sequence",
"subject": "1800000013640000A0724E18090000000000000000FE5F00",
"string": "1.0000000000000E+6124"
},
{
"description": "[decq644] fold-down full sequence",
"subject": "180000001364000010A5D4E8000000000000000000FE5F00",
"string": "1.000000000000E+6123"
},
{
"description": "[decq646] fold-down full sequence",
"subject": "1800000013640000E8764817000000000000000000FE5F00",
"string": "1.00000000000E+6122"
},
{
"description": "[decq648] fold-down full sequence",
"subject": "1800000013640000E40B5402000000000000000000FE5F00",
"string": "1.0000000000E+6121"
},
{
"description": "[decq650] fold-down full sequence",
"subject": "1800000013640000CA9A3B00000000000000000000FE5F00",
"string": "1.000000000E+6120"
},
{
"description": "[decq652] fold-down full sequence",
"subject": "1800000013640000E1F50500000000000000000000FE5F00",
"string": "1.00000000E+6119"
},
{
"description": "[decq654] fold-down full sequence",
"subject": "180000001364008096980000000000000000000000FE5F00",
"string": "1.0000000E+6118"
},
{
"description": "[decq656] fold-down full sequence",
"subject": "1800000013640040420F0000000000000000000000FE5F00",
"string": "1.000000E+6117"
},
{
"description": "[decq658] fold-down full sequence",
"subject": "18000000136400A086010000000000000000000000FE5F00",
"string": "1.00000E+6116"
},
{
"description": "[decq660] fold-down full sequence",
"subject": "180000001364001027000000000000000000000000FE5F00",
"string": "1.0000E+6115"
},
{
"description": "[decq662] fold-down full sequence",
"subject": "18000000136400E803000000000000000000000000FE5F00",
"string": "1.000E+6114"
},
{
"description": "[decq664] fold-down full sequence",
"subject": "180000001364006400000000000000000000000000FE5F00",
"string": "1.00E+6113"
},
{
"description": "[decq666] fold-down full sequence",
"subject": "180000001364000A00000000000000000000000000FE5F00",
"string": "1.0E+6112"
},
{
"description": "[decq060] fold-downs (more below)",
"subject": "180000001364000100000000000000000000000000403000",
"string": "1"
},
{
"description": "[decq670] fold-down full sequence",
"subject": "180000001364000100000000000000000000000000FC5F00",
"string": "1E+6110"
},
{
"description": "[decq668] fold-down full sequence",
"subject": "180000001364000100000000000000000000000000FE5F00",
"string": "1E+6111"
},
{
"description": "[decq072] Nmin and below",
"subject": "180000001364000100000000000000000000000000420000",
"string": "1E-6143"
},
{
"description": "[decq076] Nmin and below",
"subject": "18000000136400010000000A5BC138938D44C64D31000000",
"string": "1.000000000000000000000000000000001E-6143"
},
{
"description": "[decq036] fold-downs (more below)",
"subject": "18000000136400000000807F1BCF85B27059C8A43CFE5F00",
"string": "1.230000000000000000000000000000000E+6144"
},
{
"description": "[decq062] fold-downs (more below)",
"subject": "180000001364007B000000000000000000000000003C3000",
"string": "1.23"
},
{
"description": "[decq034] Nmax and similar",
"subject": "18000000136400F2AF967ED05C82DE3297FF6FDE3CFE5F00",
"string": "1.234567890123456789012345678901234E+6144"
},
{
"description": "[decq441] exponent lengths",
"subject": "180000001364000700000000000000000000000000403000",
"string": "7"
},
{
"description": "[decq449] exponent lengths",
"subject": "1800000013640007000000000000000000000000001E5F00",
"string": "7E+5999"
},
{
"description": "[decq447] exponent lengths",
"subject": "1800000013640007000000000000000000000000000E3800",
"string": "7E+999"
},
{
"description": "[decq445] exponent lengths",
"subject": "180000001364000700000000000000000000000000063100",
"string": "7E+99"
},
{
"description": "[decq443] exponent lengths",
"subject": "180000001364000700000000000000000000000000523000",
"string": "7E+9"
},
{
"description": "[decq842] VG testcase",
"subject": "180000001364000000FED83F4E7C9FE4E269E38A5BCD1700",
"string": "7.049000000000010795488000000000000E-3097"
},
{
"description": "[decq841] VG testcase",
"subject": "180000001364000000203B9DB5056F000000000000002400",
"string": "8.000000000000000000E-1550"
},
{
"description": "[decq840] VG testcase",
"subject": "180000001364003C17258419D710C42F0000000000002400",
"string": "8.81125000000001349436E-1548"
},
{
"description": "[decq701] Selected DPD codes",
"subject": "180000001364000900000000000000000000000000403000",
"string": "9"
},
{
"description": "[decq032] Nmax and similar",
"subject": "18000000136400FFFFFFFF638E8D37C087ADBE09EDFF5F00",
"string": "9.999999999999999999999999999999999E+6144"
},
{
"description": "[decq702] Selected DPD codes",
"subject": "180000001364000A00000000000000000000000000403000",
"string": "10"
},
{
"description": "[decq057] fold-downs (more below)",
"subject": "180000001364000C00000000000000000000000000403000",
"string": "12"
},
{
"description": "[decq703] Selected DPD codes",
"subject": "180000001364001300000000000000000000000000403000",
"string": "19"
},
{
"description": "[decq704] Selected DPD codes",
"subject": "180000001364001400000000000000000000000000403000",
"string": "20"
},
{
"description": "[decq705] Selected DPD codes",
"subject": "180000001364001D00000000000000000000000000403000",
"string": "29"
},
{
"description": "[decq706] Selected DPD codes",
"subject": "180000001364001E00000000000000000000000000403000",
"string": "30"
},
{
"description": "[decq707] Selected DPD codes",
"subject": "180000001364002700000000000000000000000000403000",
"string": "39"
},
{
"description": "[decq708] Selected DPD codes",
"subject": "180000001364002800000000000000000000000000403000",
"string": "40"
},
{
"description": "[decq709] Selected DPD codes",
"subject": "180000001364003100000000000000000000000000403000",
"string": "49"
},
{
"description": "[decq710] Selected DPD codes",
"subject": "180000001364003200000000000000000000000000403000",
"string": "50"
},
{
"description": "[decq711] Selected DPD codes",
"subject": "180000001364003B00000000000000000000000000403000",
"string": "59"
},
{
"description": "[decq712] Selected DPD codes",
"subject": "180000001364003C00000000000000000000000000403000",
"string": "60"
},
{
"description": "[decq713] Selected DPD codes",
"subject": "180000001364004500000000000000000000000000403000",
"string": "69"
},
{
"description": "[decq714] Selected DPD codes",
"subject": "180000001364004600000000000000000000000000403000",
"string": "70"
},
{
"description": "[decq715] Selected DPD codes",
"subject": "180000001364004700000000000000000000000000403000",
"string": "71"
},
{
"description": "[decq716] Selected DPD codes",
"subject": "180000001364004800000000000000000000000000403000",
"string": "72"
},
{
"description": "[decq717] Selected DPD codes",
"subject": "180000001364004900000000000000000000000000403000",
"string": "73"
},
{
"description": "[decq718] Selected DPD codes",
"subject": "180000001364004A00000000000000000000000000403000",
"string": "74"
},
{
"description": "[decq719] Selected DPD codes",
"subject": "180000001364004B00000000000000000000000000403000",
"string": "75"
},
{
"description": "[decq720] Selected DPD codes",
"subject": "180000001364004C00000000000000000000000000403000",
"string": "76"
},
{
"description": "[decq721] Selected DPD codes",
"subject": "180000001364004D00000000000000000000000000403000",
"string": "77"
},
{
"description": "[decq722] Selected DPD codes",
"subject": "180000001364004E00000000000000000000000000403000",
"string": "78"
},
{
"description": "[decq723] Selected DPD codes",
"subject": "180000001364004F00000000000000000000000000403000",
"string": "79"
},
{
"description": "[decq056] fold-downs (more below)",
"subject": "180000001364007B00000000000000000000000000403000",
"string": "123"
},
{
"description": "[decq064] fold-downs (more below)",
"subject": "1800000013640039300000000000000000000000003C3000",
"string": "123.45"
},
{
"description": "[decq732] Selected DPD codes",
"subject": "180000001364000802000000000000000000000000403000",
"string": "520"
},
{
"description": "[decq733] Selected DPD codes",
"subject": "180000001364000902000000000000000000000000403000",
"string": "521"
},
{
"description": "[decq740] DPD: one of each of the huffman groups",
"subject": "180000001364000903000000000000000000000000403000",
"string": "777"
},
{
"description": "[decq741] DPD: one of each of the huffman groups",
"subject": "180000001364000A03000000000000000000000000403000",
"string": "778"
},
{
"description": "[decq742] DPD: one of each of the huffman groups",
"subject": "180000001364001303000000000000000000000000403000",
"string": "787"
},
{
"description": "[decq746] DPD: one of each of the huffman groups",
"subject": "180000001364001F03000000000000000000000000403000",
"string": "799"
},
{
"description": "[decq743] DPD: one of each of the huffman groups",
"subject": "180000001364006D03000000000000000000000000403000",
"string": "877"
},
{
"description": "[decq753] DPD all-highs cases (includes the 24 redundant codes)",
"subject": "180000001364007803000000000000000000000000403000",
"string": "888"
},
{
"description": "[decq754] DPD all-highs cases (includes the 24 redundant codes)",
"subject": "180000001364007903000000000000000000000000403000",
"string": "889"
},
{
"description": "[decq760] DPD all-highs cases (includes the 24 redundant codes)",
"subject": "180000001364008203000000000000000000000000403000",
"string": "898"
},
{
"description": "[decq764] DPD all-highs cases (includes the 24 redundant codes)",
"subject": "180000001364008303000000000000000000000000403000",
"string": "899"
},
{
"description": "[decq745] DPD: one of each of the huffman groups",
"subject": "18000000136400D303000000000000000000000000403000",
"string": "979"
},
{
"description": "[decq770] DPD all-highs cases (includes the 24 redundant codes)",
"subject": "18000000136400DC03000000000000000000000000403000",
"string": "988"
},
{
"description": "[decq774] DPD all-highs cases (includes the 24 redundant codes)",
"subject": "18000000136400DD03000000000000000000000000403000",
"string": "989"
},
{
"description": "[decq730] Selected DPD codes",
"subject": "18000000136400E203000000000000000000000000403000",
"string": "994"
},
{
"description": "[decq731] Selected DPD codes",
"subject": "18000000136400E303000000000000000000000000403000",
"string": "995"
},
{
"description": "[decq744] DPD: one of each of the huffman groups",
"subject": "18000000136400E503000000000000000000000000403000",
"string": "997"
},
{
"description": "[decq780] DPD all-highs cases (includes the 24 redundant codes)",
"subject": "18000000136400E603000000000000000000000000403000",
"string": "998"
},
{
"description": "[decq787] DPD all-highs cases (includes the 24 redundant codes)",
"subject": "18000000136400E703000000000000000000000000403000",
"string": "999"
},
{
"description": "[decq053] fold-downs (more below)",
"subject": "18000000136400D204000000000000000000000000403000",
"string": "1234"
},
{
"description": "[decq052] fold-downs (more below)",
"subject": "180000001364003930000000000000000000000000403000",
"string": "12345"
},
{
"description": "[decq792] Miscellaneous (testers' queries, etc.)",
"subject": "180000001364003075000000000000000000000000403000",
"string": "30000"
},
{
"description": "[decq793] Miscellaneous (testers' queries, etc.)",
"subject": "1800000013640090940D0000000000000000000000403000",
"string": "890000"
},
{
"description": "[decq824] values around [u]int32 edges (zeros done earlier)",
"subject": "18000000136400FEFFFF7F00000000000000000000403000",
"string": "2147483646"
},
{
"description": "[decq825] values around [u]int32 edges (zeros done earlier)",
"subject": "18000000136400FFFFFF7F00000000000000000000403000",
"string": "2147483647"
},
{
"description": "[decq826] values around [u]int32 edges (zeros done earlier)",
"subject": "180000001364000000008000000000000000000000403000",
"string": "2147483648"
},
{
"description": "[decq827] values around [u]int32 edges (zeros done earlier)",
"subject": "180000001364000100008000000000000000000000403000",
"string": "2147483649"
},
{
"description": "[decq828] values around [u]int32 edges (zeros done earlier)",
"subject": "18000000136400FEFFFFFF00000000000000000000403000",
"string": "4294967294"
},
{
"description": "[decq829] values around [u]int32 edges (zeros done earlier)",
"subject": "18000000136400FFFFFFFF00000000000000000000403000",
"string": "4294967295"
},
{
"description": "[decq830] values around [u]int32 edges (zeros done earlier)",
"subject": "180000001364000000000001000000000000000000403000",
"string": "4294967296"
},
{
"description": "[decq831] values around [u]int32 edges (zeros done earlier)",
"subject": "180000001364000100000001000000000000000000403000",
"string": "4294967297"
},
{
"description": "[decq022] Normality",
"subject": "18000000136400C7711CC7B548F377DC80A131C836403000",
"string": "1111111111111111111111111111111111"
},
{
"description": "[decq020] Normality",
"subject": "18000000136400F2AF967ED05C82DE3297FF6FDE3C403000",
"string": "1234567890123456789012345678901234"
},
{
"description": "[decq550] Specials",
"subject": "18000000136400FFFFFFFF638E8D37C087ADBE09ED413000",
"string": "9999999999999999999999999999999999"
}
]
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,165 @@
{
"description": "Decimal128",
"bson_type": "0x13",
"test_key": "d",
"valid": [
{
"description": "[basx023] conform to rules and exponent will be in permitted range).",
"subject": "1800000013640001000000000000000000000000003EB000",
"string": "-0.1"
},
{
"description": "[basx045] strings without E cannot generate E in result",
"subject": "1800000013640003000000000000000000000000003A3000",
"string": "+0.003",
"match_string": "0.003"
},
{
"description": "[basx610] Zeros",
"subject": "1800000013640000000000000000000000000000003E3000",
"string": ".0",
"match_string": "0.0"
},
{
"description": "[basx612] Zeros",
"subject": "1800000013640000000000000000000000000000003EB000",
"string": "-.0",
"match_string": "-0.0"
},
{
"description": "[basx043] strings without E cannot generate E in result",
"subject": "18000000136400FC040000000000000000000000003C3000",
"string": "+12.76",
"match_string": "12.76"
},
{
"description": "[basx055] strings without E cannot generate E in result",
"subject": "180000001364000500000000000000000000000000303000",
"string": "0.00000005",
"match_string": "5E-8"
},
{
"description": "[basx054] strings without E cannot generate E in result",
"subject": "180000001364000500000000000000000000000000323000",
"string": "0.0000005",
"match_string": "5E-7"
},
{
"description": "[basx052] strings without E cannot generate E in result",
"subject": "180000001364000500000000000000000000000000343000",
"string": "0.000005"
},
{
"description": "[basx051] strings without E cannot generate E in result",
"subject": "180000001364000500000000000000000000000000363000",
"string": "00.00005",
"match_string": "0.00005"
},
{
"description": "[basx050] strings without E cannot generate E in result",
"subject": "180000001364000500000000000000000000000000383000",
"string": "0.0005"
},
{
"description": "[basx047] strings without E cannot generate E in result",
"subject": "1800000013640005000000000000000000000000003E3000",
"string": ".5",
"match_string": "0.5"
},
{
"description": "[dqbsr431] check rounding modes heeded (Rounded)",
"subject": "1800000013640099761CC7B548F377DC80A131C836FE2F00",
"string": "1.1111111111111111111111111111123450",
"match_string": "1.111111111111111111111111111112345"
},
{
"description": "OK2",
"subject": "18000000136400000000000A5BC138938D44C64D31FC2F00",
"string": ".100000000000000000000000000000000000000000000000000000000000",
"match_string": "0.1000000000000000000000000000000000"
}
],
"parseErrors": [
{
"description": "[basx564] Near-specials (Conversion_syntax)",
"subject": "Infi"
},
{
"description": "[basx565] Near-specials (Conversion_syntax)",
"subject": "Infin"
},
{
"description": "[basx566] Near-specials (Conversion_syntax)",
"subject": "Infini"
},
{
"description": "[basx567] Near-specials (Conversion_syntax)",
"subject": "Infinit"
},
{
"description": "[basx568] Near-specials (Conversion_syntax)",
"subject": "-Infinit"
},
{
"description": "[basx590] some baddies with dots and Es and dots and specials (Conversion_syntax)",
"subject": ".Infinity"
},
{
"description": "[basx562] Near-specials (Conversion_syntax)",
"subject": "NaNq"
},
{
"description": "[basx563] Near-specials (Conversion_syntax)",
"subject": "NaNs"
},
{
"description": "[dqbas939] overflow results at different rounding modes (Overflow & Inexact & Rounded)",
"subject": "-7e10000"
},
{
"description": "[dqbsr534] negatives (Rounded & Inexact)",
"subject": "-1.11111111111111111111111111111234650"
},
{
"description": "[dqbsr535] negatives (Rounded & Inexact)",
"subject": "-1.11111111111111111111111111111234551"
},
{
"description": "[dqbsr533] negatives (Rounded & Inexact)",
"subject": "-1.11111111111111111111111111111234550"
},
{
"description": "[dqbsr532] negatives (Rounded & Inexact)",
"subject": "-1.11111111111111111111111111111234549"
},
{
"description": "[dqbsr432] check rounding modes heeded (Rounded & Inexact)",
"subject": "1.11111111111111111111111111111234549"
},
{
"description": "[dqbsr433] check rounding modes heeded (Rounded & Inexact)",
"subject": "1.11111111111111111111111111111234550"
},
{
"description": "[dqbsr435] check rounding modes heeded (Rounded & Inexact)",
"subject": "1.11111111111111111111111111111234551"
},
{
"description": "[dqbsr434] check rounding modes heeded (Rounded & Inexact)",
"subject": "1.11111111111111111111111111111234650"
},
{
"description": "[dqbas938] overflow results at different rounding modes (Overflow & Inexact & Rounded)",
"subject": "7e10000"
},
{
"description": "Inexact rounding#1",
"subject": "100000000000000000000000000000000000000000000000000000000001"
},
{
"description": "Inexact rounding#2",
"subject": "1E-6177"
}
]
}

View File

@ -0,0 +1,402 @@
{
"description": "Decimal128",
"bson_type": "0x13",
"test_key": "d",
"valid": [
{
"description": "[decq035] fold-downs (more below) (Clamped)",
"subject": "18000000136400000000807F1BCF85B27059C8A43CFE5F00",
"string": "1.23E+6144",
"match_string": "1.230000000000000000000000000000000E+6144"
},
{
"description": "[decq037] fold-downs (more below) (Clamped)",
"subject": "18000000136400000000000A5BC138938D44C64D31FE5F00",
"string": "1E+6144",
"match_string": "1.000000000000000000000000000000000E+6144"
},
{
"description": "[decq077] Nmin and below (Subnormal)",
"subject": "180000001364000000000081EFAC855B416D2DEE04000000",
"string": "0.100000000000000000000000000000000E-6143",
"match_string": "1.00000000000000000000000000000000E-6144"
},
{
"description": "[decq078] Nmin and below (Subnormal)",
"subject": "180000001364000000000081EFAC855B416D2DEE04000000",
"string": "1.00000000000000000000000000000000E-6144"
},
{
"description": "[decq079] Nmin and below (Subnormal)",
"subject": "180000001364000A00000000000000000000000000000000",
"string": "0.000000000000000000000000000000010E-6143",
"match_string": "1.0E-6175"
},
{
"description": "[decq080] Nmin and below (Subnormal)",
"subject": "180000001364000A00000000000000000000000000000000",
"string": "1.0E-6175"
},
{
"description": "[decq081] Nmin and below (Subnormal)",
"subject": "180000001364000100000000000000000000000000020000",
"string": "0.00000000000000000000000000000001E-6143",
"match_string": "1E-6175"
},
{
"description": "[decq082] Nmin and below (Subnormal)",
"subject": "180000001364000100000000000000000000000000020000",
"string": "1E-6175"
},
{
"description": "[decq083] Nmin and below (Subnormal)",
"subject": "180000001364000100000000000000000000000000000000",
"string": "0.000000000000000000000000000000001E-6143",
"match_string": "1E-6176"
},
{
"description": "[decq084] Nmin and below (Subnormal)",
"subject": "180000001364000100000000000000000000000000000000",
"string": "1E-6176"
},
{
"description": "[decq090] underflows cannot be tested for simple copies, check edge cases (Subnormal)",
"subject": "180000001364000100000000000000000000000000000000",
"string": "1e-6176",
"match_string": "1E-6176"
},
{
"description": "[decq100] underflows cannot be tested for simple copies, check edge cases (Subnormal)",
"subject": "18000000136400FFFFFFFF095BC138938D44C64D31000000",
"string": "999999999999999999999999999999999e-6176",
"match_string": "9.99999999999999999999999999999999E-6144"
},
{
"description": "[decq130] fold-downs (more below) (Clamped)",
"subject": "18000000136400000000807F1BCF85B27059C8A43CFEDF00",
"string": "-1.23E+6144",
"match_string": "-1.230000000000000000000000000000000E+6144"
},
{
"description": "[decq132] fold-downs (more below) (Clamped)",
"subject": "18000000136400000000000A5BC138938D44C64D31FEDF00",
"string": "-1E+6144",
"match_string": "-1.000000000000000000000000000000000E+6144"
},
{
"description": "[decq177] Nmin and below (Subnormal)",
"subject": "180000001364000000000081EFAC855B416D2DEE04008000",
"string": "-0.100000000000000000000000000000000E-6143",
"match_string": "-1.00000000000000000000000000000000E-6144"
},
{
"description": "[decq178] Nmin and below (Subnormal)",
"subject": "180000001364000000000081EFAC855B416D2DEE04008000",
"string": "-1.00000000000000000000000000000000E-6144"
},
{
"description": "[decq179] Nmin and below (Subnormal)",
"subject": "180000001364000A00000000000000000000000000008000",
"string": "-0.000000000000000000000000000000010E-6143",
"match_string": "-1.0E-6175"
},
{
"description": "[decq180] Nmin and below (Subnormal)",
"subject": "180000001364000A00000000000000000000000000008000",
"string": "-1.0E-6175"
},
{
"description": "[decq181] Nmin and below (Subnormal)",
"subject": "180000001364000100000000000000000000000000028000",
"string": "-0.00000000000000000000000000000001E-6143",
"match_string": "-1E-6175"
},
{
"description": "[decq182] Nmin and below (Subnormal)",
"subject": "180000001364000100000000000000000000000000028000",
"string": "-1E-6175"
},
{
"description": "[decq183] Nmin and below (Subnormal)",
"subject": "180000001364000100000000000000000000000000008000",
"string": "-0.000000000000000000000000000000001E-6143",
"match_string": "-1E-6176"
},
{
"description": "[decq184] Nmin and below (Subnormal)",
"subject": "180000001364000100000000000000000000000000008000",
"string": "-1E-6176"
},
{
"description": "[decq190] underflow edge cases (Subnormal)",
"subject": "180000001364000100000000000000000000000000008000",
"string": "-1e-6176",
"match_string": "-1E-6176"
},
{
"description": "[decq200] underflow edge cases (Subnormal)",
"subject": "18000000136400FFFFFFFF095BC138938D44C64D31008000",
"string": "-999999999999999999999999999999999e-6176",
"match_string": "-9.99999999999999999999999999999999E-6144"
},
{
"description": "[decq400] zeros (Clamped)",
"subject": "180000001364000000000000000000000000000000000000",
"string": "0E-8000",
"match_string": "0E-6176"
},
{
"description": "[decq401] zeros (Clamped)",
"subject": "180000001364000000000000000000000000000000000000",
"string": "0E-6177",
"match_string": "0E-6176"
},
{
"description": "[decq414] clamped zeros... (Clamped)",
"subject": "180000001364000000000000000000000000000000FE5F00",
"string": "0E+6112",
"match_string": "0E+6111"
},
{
"description": "[decq416] clamped zeros... (Clamped)",
"subject": "180000001364000000000000000000000000000000FE5F00",
"string": "0E+6144",
"match_string": "0E+6111"
},
{
"description": "[decq418] clamped zeros... (Clamped)",
"subject": "180000001364000000000000000000000000000000FE5F00",
"string": "0E+8000",
"match_string": "0E+6111"
},
{
"description": "[decq420] negative zeros (Clamped)",
"subject": "180000001364000000000000000000000000000000008000",
"string": "-0E-8000",
"match_string": "-0E-6176"
},
{
"description": "[decq421] negative zeros (Clamped)",
"subject": "180000001364000000000000000000000000000000008000",
"string": "-0E-6177",
"match_string": "-0E-6176"
},
{
"description": "[decq434] clamped zeros... (Clamped)",
"subject": "180000001364000000000000000000000000000000FEDF00",
"string": "-0E+6112",
"match_string": "-0E+6111"
},
{
"description": "[decq436] clamped zeros... (Clamped)",
"subject": "180000001364000000000000000000000000000000FEDF00",
"string": "-0E+6144",
"match_string": "-0E+6111"
},
{
"description": "[decq438] clamped zeros... (Clamped)",
"subject": "180000001364000000000000000000000000000000FEDF00",
"string": "-0E+8000",
"match_string": "-0E+6111"
},
{
"description": "[decq601] fold-down full sequence (Clamped)",
"subject": "18000000136400000000000A5BC138938D44C64D31FE5F00",
"string": "1E+6144",
"match_string": "1.000000000000000000000000000000000E+6144"
},
{
"description": "[decq603] fold-down full sequence (Clamped)",
"subject": "180000001364000000000081EFAC855B416D2DEE04FE5F00",
"string": "1E+6143",
"match_string": "1.00000000000000000000000000000000E+6143"
},
{
"description": "[decq605] fold-down full sequence (Clamped)",
"subject": "1800000013640000000080264B91C02220BE377E00FE5F00",
"string": "1E+6142",
"match_string": "1.0000000000000000000000000000000E+6142"
},
{
"description": "[decq607] fold-down full sequence (Clamped)",
"subject": "1800000013640000000040EAED7446D09C2C9F0C00FE5F00",
"string": "1E+6141",
"match_string": "1.000000000000000000000000000000E+6141"
},
{
"description": "[decq609] fold-down full sequence (Clamped)",
"subject": "18000000136400000000A0CA17726DAE0F1E430100FE5F00",
"string": "1E+6140",
"match_string": "1.00000000000000000000000000000E+6140"
},
{
"description": "[decq611] fold-down full sequence (Clamped)",
"subject": "18000000136400000000106102253E5ECE4F200000FE5F00",
"string": "1E+6139",
"match_string": "1.0000000000000000000000000000E+6139"
},
{
"description": "[decq613] fold-down full sequence (Clamped)",
"subject": "18000000136400000000E83C80D09F3C2E3B030000FE5F00",
"string": "1E+6138",
"match_string": "1.000000000000000000000000000E+6138"
},
{
"description": "[decq615] fold-down full sequence (Clamped)",
"subject": "18000000136400000000E4D20CC8DCD2B752000000FE5F00",
"string": "1E+6137",
"match_string": "1.00000000000000000000000000E+6137"
},
{
"description": "[decq617] fold-down full sequence (Clamped)",
"subject": "180000001364000000004A48011416954508000000FE5F00",
"string": "1E+6136",
"match_string": "1.0000000000000000000000000E+6136"
},
{
"description": "[decq619] fold-down full sequence (Clamped)",
"subject": "18000000136400000000A1EDCCCE1BC2D300000000FE5F00",
"string": "1E+6135",
"match_string": "1.000000000000000000000000E+6135"
},
{
"description": "[decq621] fold-down full sequence (Clamped)",
"subject": "18000000136400000080F64AE1C7022D1500000000FE5F00",
"string": "1E+6134",
"match_string": "1.00000000000000000000000E+6134"
},
{
"description": "[decq623] fold-down full sequence (Clamped)",
"subject": "18000000136400000040B2BAC9E0191E0200000000FE5F00",
"string": "1E+6133",
"match_string": "1.0000000000000000000000E+6133"
},
{
"description": "[decq625] fold-down full sequence (Clamped)",
"subject": "180000001364000000A0DEC5ADC935360000000000FE5F00",
"string": "1E+6132",
"match_string": "1.000000000000000000000E+6132"
},
{
"description": "[decq627] fold-down full sequence (Clamped)",
"subject": "18000000136400000010632D5EC76B050000000000FE5F00",
"string": "1E+6131",
"match_string": "1.00000000000000000000E+6131"
},
{
"description": "[decq629] fold-down full sequence (Clamped)",
"subject": "180000001364000000E8890423C78A000000000000FE5F00",
"string": "1E+6130",
"match_string": "1.0000000000000000000E+6130"
},
{
"description": "[decq631] fold-down full sequence (Clamped)",
"subject": "18000000136400000064A7B3B6E00D000000000000FE5F00",
"string": "1E+6129",
"match_string": "1.000000000000000000E+6129"
},
{
"description": "[decq633] fold-down full sequence (Clamped)",
"subject": "1800000013640000008A5D78456301000000000000FE5F00",
"string": "1E+6128",
"match_string": "1.00000000000000000E+6128"
},
{
"description": "[decq635] fold-down full sequence (Clamped)",
"subject": "180000001364000000C16FF2862300000000000000FE5F00",
"string": "1E+6127",
"match_string": "1.0000000000000000E+6127"
},
{
"description": "[decq637] fold-down full sequence (Clamped)",
"subject": "180000001364000080C6A47E8D0300000000000000FE5F00",
"string": "1E+6126",
"match_string": "1.000000000000000E+6126"
},
{
"description": "[decq639] fold-down full sequence (Clamped)",
"subject": "1800000013640000407A10F35A0000000000000000FE5F00",
"string": "1E+6125",
"match_string": "1.00000000000000E+6125"
},
{
"description": "[decq641] fold-down full sequence (Clamped)",
"subject": "1800000013640000A0724E18090000000000000000FE5F00",
"string": "1E+6124",
"match_string": "1.0000000000000E+6124"
},
{
"description": "[decq643] fold-down full sequence (Clamped)",
"subject": "180000001364000010A5D4E8000000000000000000FE5F00",
"string": "1E+6123",
"match_string": "1.000000000000E+6123"
},
{
"description": "[decq645] fold-down full sequence (Clamped)",
"subject": "1800000013640000E8764817000000000000000000FE5F00",
"string": "1E+6122",
"match_string": "1.00000000000E+6122"
},
{
"description": "[decq647] fold-down full sequence (Clamped)",
"subject": "1800000013640000E40B5402000000000000000000FE5F00",
"string": "1E+6121",
"match_string": "1.0000000000E+6121"
},
{
"description": "[decq649] fold-down full sequence (Clamped)",
"subject": "1800000013640000CA9A3B00000000000000000000FE5F00",
"string": "1E+6120",
"match_string": "1.000000000E+6120"
},
{
"description": "[decq651] fold-down full sequence (Clamped)",
"subject": "1800000013640000E1F50500000000000000000000FE5F00",
"string": "1E+6119",
"match_string": "1.00000000E+6119"
},
{
"description": "[decq653] fold-down full sequence (Clamped)",
"subject": "180000001364008096980000000000000000000000FE5F00",
"string": "1E+6118",
"match_string": "1.0000000E+6118"
},
{
"description": "[decq655] fold-down full sequence (Clamped)",
"subject": "1800000013640040420F0000000000000000000000FE5F00",
"string": "1E+6117",
"match_string": "1.000000E+6117"
},
{
"description": "[decq657] fold-down full sequence (Clamped)",
"subject": "18000000136400A086010000000000000000000000FE5F00",
"string": "1E+6116",
"match_string": "1.00000E+6116"
},
{
"description": "[decq659] fold-down full sequence (Clamped)",
"subject": "180000001364001027000000000000000000000000FE5F00",
"string": "1E+6115",
"match_string": "1.0000E+6115"
},
{
"description": "[decq661] fold-down full sequence (Clamped)",
"subject": "18000000136400E803000000000000000000000000FE5F00",
"string": "1E+6114",
"match_string": "1.000E+6114"
},
{
"description": "[decq663] fold-down full sequence (Clamped)",
"subject": "180000001364006400000000000000000000000000FE5F00",
"string": "1E+6113",
"match_string": "1.00E+6113"
},
{
"description": "[decq665] fold-down full sequence (Clamped)",
"subject": "180000001364000A00000000000000000000000000FE5F00",
"string": "1E+6112",
"match_string": "1.0E+6112"
}
]
}

View File

@ -0,0 +1,131 @@
{
"description": "Decimal128",
"bson_type": "0x13",
"test_key": "d",
"parseErrors": [
{
"description": "Incomplete Exponent",
"subject": "1e"
},
{
"description": "Exponent at the beginning",
"subject": "E01"
},
{
"description": "Just a decimal place",
"subject": "."
},
{
"description": "2 decimal places",
"subject": "..3"
},
{
"description": "2 decimal places",
"subject": ".13.3"
},
{
"description": "2 decimal places",
"subject": "1..3"
},
{
"description": "2 decimal places",
"subject": "1.3.4"
},
{
"description": "2 decimal places",
"subject": "1.34."
},
{
"description": "Decimal with no digits",
"subject": ".e"
},
{
"description": "2 signs",
"subject": "+-32.4"
},
{
"description": "2 signs",
"subject": "-+32.4"
},
{
"description": "2 negative signs",
"subject": "--32.4"
},
{
"description": "2 negative signs",
"subject": "-32.-4"
},
{
"description": "End in negative sign",
"subject": "32.0-"
},
{
"description": "2 negative signs",
"subject": "32.4E--21"
},
{
"description": "2 negative signs",
"subject": "32.4E-2-1"
},
{
"description": "2 signs",
"subject": "32.4E+-21"
},
{
"description": "Empty string",
"subject": ""
},
{
"description": "leading white space positive number",
"subject": " 1"
},
{
"description": "leading white space negative number",
"subject": " -1"
},
{
"description": "trailing white space",
"subject": "1 "
},
{
"description": "Invalid",
"subject": "E"
},
{
"description": "Invalid",
"subject": "invalid"
},
{
"description": "Invalid",
"subject": "i"
},
{
"description": "Invalid",
"subject": "in"
},
{
"description": "Invalid",
"subject": "-in"
},
{
"description": "Invalid",
"subject": "Na"
},
{
"description": "Invalid",
"subject": "-Na"
},
{
"description": "Invalid",
"subject": "1.23abc"
},
{
"description": "Invalid",
"subject": "1.23abcE+02"
},
{
"description": "Invalid",
"subject": "1.23E+0aabs2"
}
]
}

View File

@ -0,0 +1,327 @@
{
"description": "Decimal128",
"bson_type": "0x13",
"test_key": "d",
"parseErrors": [
{
"description": "[basx572] Near-specials (Conversion_syntax)",
"subject": "-9Inf"
},
{
"description": "[basx516] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "-1-"
},
{
"description": "[basx533] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "0000.."
},
{
"description": "[basx534] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": ".0000."
},
{
"description": "[basx535] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "00..00"
},
{
"description": "[basx569] Near-specials (Conversion_syntax)",
"subject": "0Inf"
},
{
"description": "[basx571] Near-specials (Conversion_syntax)",
"subject": "-0Inf"
},
{
"description": "[basx575] Near-specials (Conversion_syntax)",
"subject": "0sNaN"
},
{
"description": "[basx503] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "++1"
},
{
"description": "[basx504] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "--1"
},
{
"description": "[basx505] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "-+1"
},
{
"description": "[basx506] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "+-1"
},
{
"description": "[basx510] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": " +1"
},
{
"description": "[basx513] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": " + 1"
},
{
"description": "[basx514] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": " - 1"
},
{
"description": "[basx501] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "."
},
{
"description": "[basx502] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": ".."
},
{
"description": "[basx519] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": ""
},
{
"description": "[basx525] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "e100"
},
{
"description": "[basx549] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "e+1"
},
{
"description": "[basx577] some baddies with dots and Es and dots and specials (Conversion_syntax)",
"subject": ".e+1"
},
{
"description": "[basx578] some baddies with dots and Es and dots and specials (Conversion_syntax)",
"subject": "+.e+1"
},
{
"description": "[basx581] some baddies with dots and Es and dots and specials (Conversion_syntax)",
"subject": "E+1"
},
{
"description": "[basx582] some baddies with dots and Es and dots and specials (Conversion_syntax)",
"subject": ".E+1"
},
{
"description": "[basx583] some baddies with dots and Es and dots and specials (Conversion_syntax)",
"subject": "+.E+1"
},
{
"description": "[basx579] some baddies with dots and Es and dots and specials (Conversion_syntax)",
"subject": "-.e+"
},
{
"description": "[basx580] some baddies with dots and Es and dots and specials (Conversion_syntax)",
"subject": "-.e"
},
{
"description": "[basx584] some baddies with dots and Es and dots and specials (Conversion_syntax)",
"subject": "-.E+"
},
{
"description": "[basx585] some baddies with dots and Es and dots and specials (Conversion_syntax)",
"subject": "-.E"
},
{
"description": "[basx589] some baddies with dots and Es and dots and specials (Conversion_syntax)",
"subject": "+.Inf"
},
{
"description": "[basx586] some baddies with dots and Es and dots and specials (Conversion_syntax)",
"subject": ".NaN"
},
{
"description": "[basx587] some baddies with dots and Es and dots and specials (Conversion_syntax)",
"subject": "-.NaN"
},
{
"description": "[basx545] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "ONE"
},
{
"description": "[basx561] Near-specials (Conversion_syntax)",
"subject": "qNaN"
},
{
"description": "[basx573] Near-specials (Conversion_syntax)",
"subject": "-sNa"
},
{
"description": "[basx588] some baddies with dots and Es and dots and specials (Conversion_syntax)",
"subject": "+.sNaN"
},
{
"description": "[basx544] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "ten"
},
{
"description": "[basx527] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "u0b65"
},
{
"description": "[basx526] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "u0e5a"
},
{
"description": "[basx515] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "x"
},
{
"description": "[basx574] Near-specials (Conversion_syntax)",
"subject": "xNaN"
},
{
"description": "[basx530] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": ".123.5"
},
{
"description": "[basx500] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "1..2"
},
{
"description": "[basx542] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "1e1.0"
},
{
"description": "[basx553] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "1E+1.2.3"
},
{
"description": "[basx543] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "1e123e"
},
{
"description": "[basx552] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "1E+1.2"
},
{
"description": "[basx546] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "1e.1"
},
{
"description": "[basx547] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "1e1."
},
{
"description": "[basx554] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "1E++1"
},
{
"description": "[basx555] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "1E--1"
},
{
"description": "[basx556] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "1E+-1"
},
{
"description": "[basx557] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "1E-+1"
},
{
"description": "[basx558] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "1E'1"
},
{
"description": "[basx559] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "1E\"1"
},
{
"description": "[basx520] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "1e-"
},
{
"description": "[basx560] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "1E"
},
{
"description": "[basx548] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "1ee"
},
{
"description": "[basx551] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "1.2.1"
},
{
"description": "[basx550] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "1.23.4"
},
{
"description": "[basx529] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "1.34.5"
},
{
"description": "[basx531] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "01.35."
},
{
"description": "[basx532] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "01.35-"
},
{
"description": "[basx518] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "3+"
},
{
"description": "[basx521] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "7e99999a"
},
{
"description": "[basx570] Near-specials (Conversion_syntax)",
"subject": "9Inf"
},
{
"description": "[basx512] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "12 "
},
{
"description": "[basx517] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "12-"
},
{
"description": "[basx507] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "12e"
},
{
"description": "[basx508] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "12e++"
},
{
"description": "[basx509] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "12f4"
},
{
"description": "[basx536] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "111e*123"
},
{
"description": "[basx537] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "111e123-"
},
{
"description": "[basx540] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "111e1*23"
},
{
"description": "[basx538] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "111e+12+"
},
{
"description": "[basx539] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "111e1-3-"
},
{
"description": "[basx541] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "111E1e+3"
},
{
"description": "[basx528] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "123,65"
},
{
"description": "[basx523] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "7e12356789012x"
},
{
"description": "[basx522] The 'baddies' tests from DiagBigDecimal, plus some new ones (Conversion_syntax)",
"subject": "7e123567890x"
}
]
}

View File

@ -15,18 +15,19 @@
"""Tests for Decimal128."""
import codecs
import glob
import json
import os.path
import pickle
import sys
from binascii import unhexlify
from decimal import Decimal
from decimal import Decimal, DecimalException
sys.path[0:0] = [""]
from bson import BSON
from bson.decimal128 import Decimal128
from bson.decimal128 import Decimal128, create_decimal128_context
from bson.json_util import dumps, loads
from bson.py3compat import b
from test import client_context, unittest
@ -68,28 +69,40 @@ class TestDecimal128(unittest.TestCase):
self.assertEqual(str(dsnan), str(dsnan128.to_decimal()))
self.assertEqual(str(dnsnan), str(dnsnan128.to_decimal()))
def test_decimal128_context(self):
ctx = create_decimal128_context()
self.assertEqual("NaN", str(ctx.copy().create_decimal(".13.1")))
self.assertEqual("Infinity", str(ctx.copy().create_decimal("1E6145")))
self.assertEqual("0E-6176", str(ctx.copy().create_decimal("1E-6177")))
def test_spec(self):
path = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'decimal',
'decimal128.json')
with codecs.open(path, 'r', 'utf-8-sig') as fp:
suite = json.load(fp)
for path in glob.glob(os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'decimal',
'decimal128*')):
with codecs.open(path, 'r', 'utf-8-sig') as fp:
suite = json.load(fp)
for test in suite['valid']:
subject = unhexlify(b(test['subject']))
doc = BSON(subject).decode()
self.assertEqual(BSON.encode(doc), subject)
for test in suite.get('valid', []):
subject = unhexlify(b(test['subject']))
doc = BSON(subject).decode()
self.assertEqual(BSON.encode(doc), subject)
self.assertEqual(str(doc['d']), test['string'])
if 'match_string' in test:
self.assertEqual(
str(Decimal128(test['string'])), test['match_string'])
else:
self.assertEqual(str(doc['d']), test['string'])
if test.get('from_extjson', True):
self.assertEqual(doc, loads(test['extjson']))
if 'extjson' in test:
if test.get('from_extjson', True):
self.assertEqual(doc, loads(test['extjson']))
if test.get('to_extjson', True):
extjson = test['extjson'].replace(' ', '')
self.assertEqual(extjson, dumps(doc).replace(' ', ''))
if test.get('to_extjson', True):
extjson = test['extjson'].replace(' ', '')
self.assertEqual(extjson, dumps(doc).replace(' ', ''))
for test in suite['parseErrors']:
self.assertRaises(ValueError, Decimal128, test['subject'])
for test in suite.get('parseErrors', []):
self.assertRaises(
DecimalException, Decimal128, test['subject'])