summaryrefslogtreecommitdiff
path: root/jstests/decimal/decimal128_test1.js
blob: b38e6ec7c0b95f48235ced5a968bcfca30f58d37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**
 * Derived from test cases at https://github.com/mongodb/specifications
 */

(function() {
"use strict";

var testData = [
    {"description": "Special - Canonical NaN", "input": "NaN"},
    {"description": "Special - Negative NaN", "input": "NaN", "lossy": true},
    {"description": "Special - Negative NaN", "expected": "NaN", "input": "-NaN", "lossy": true},
    {"description": "Special - Canonical SNaN", "input": "NaN", "lossy": true},
    {"description": "Special - Negative SNaN", "input": "NaN", "lossy": true},
    {"description": "Special - NaN with a payload", "input": "NaN", "lossy": true},
    {"description": "Special - Canonical Positive Infinity", "input": "Infinity"},
    {"description": "Special - Canonical Negative Infinity", "input": "-Infinity"},
    {"description": "Special - Invalid representation treated as 0", "input": "0", "lossy": true},
    {"description": "Special - Invalid representation treated as -0", "input": "-0", "lossy": true},
    {
        "description": "Special - Invalid representation treated as 0E3",
        "input": "0E+3",
        "lossy": true
    },
    {
        "description": "Regular - Adjusted Exponent Limit",
        "input": "0.000001234567890123456789012345678901234"
    },
    {"description": "Regular - Smallest", "input": "0.001234"},
    {"description": "Regular - Smallest with Trailing Zeros", "input": "0.00123400000"},
    {"description": "Regular - 0.1", "input": "0.1"},
    {
        "description": "Regular - 0.1234567890123456789012345678901234",
        "input": "0.1234567890123456789012345678901234"
    },
    {"description": "Regular - 0", "input": "0"},
    {"description": "Regular - -0", "input": "-0"},
    {"description": "Regular - -0.0", "input": "-0.0"},
    {"description": "Regular - 2", "input": "2"},
    {"description": "Regular - 2.000", "input": "2.000"},
    {"description": "Regular - Largest", "input": "1234567890123456789012345678901234"},
    {"description": "Scientific - Tiniest", "input": "9.999999999999999999999999999999999E-6143"},
    {"description": "Scientific - Tiny", "input": "1E-6176"},
    {"description": "Scientific - Negative Tiny", "input": "-1E-6176"},
    {
        "description": "Scientific - Adjusted Exponent Limit",
        "input": "1.234567890123456789012345678901234E-7"
    },
    {"description": "Scientific - Fractional", "input": "-1.00E-8"},
    {"description": "Scientific - 0 with Exponent", "input": "0E+6000"},
    {"description": "Scientific - 0 with Negative Exponent", "input": "0E-611"},
    {"description": "Scientific - No Decimal with Signed Exponent", "input": "1E+3"},
    {"description": "Scientific - Trailing Zero", "input": "1.050E+4"},
    {"description": "Scientific - With Decimal", "input": "1.05E+3"},
    {"description": "Scientific - Full", "input": "5192296858534827628530496329220095"},
    {"description": "Scientific - Large", "input": "1.000000000000000000000000000000000E+6144"},
    {"description": "Scientific - Largest", "input": "9.999999999999999999999999999999999E+6144"},
    {
        "description": "Non-Canonical Parsing - Exponent Normalization",
        "input": "-100E-10",
        "expected": "-1.00E-8"
    },
    {
        "description": "Non-Canonical Parsing - Unsigned Positive Exponent",
        "input": "1E3",
        "expected": "1E+3"
    },
    {
        "description": "Non-Canonical Parsing - Lowercase Exponent Identifier",
        "input": "1e+3",
        "expected": "1E+3"
    },
    {
        "description": "Non-Canonical Parsing - Long Significand with Exponent",
        "input": "12345689012345789012345E+12",
        "expected": "1.2345689012345789012345E+34"
    },
    {
        "description": "Non-Canonical Parsing - Positive Sign",
        "input": "+1234567890123456789012345678901234",
        "expected": "1234567890123456789012345678901234"
    },
    {
        "description": "Non-Canonical Parsing - Long Decimal String",
        "input":
            ".0000000000000000000000000000000000000000000000000000000000000000000000000000000" +
            "00000000000000000000000000000000000000000000000000000000000000000000000000000000" +
            "00000000000000000000000000000000000000000000000000000000000000000000000000000000" +
            "00000000000000000000000000000000000000000000000000000000000000000000000000000000" +
            "00000000000000000000000000000000000000000000000000000000000000000000000000000000" +
            "00000000000000000000000000000000000000000000000000000000000000000000000000000000" +
            "00000000000000000000000000000000000000000000000000000000000000000000000000000000" +
            "00000000000000000000000000000000000000000000000000000000000000000000000000000000" +
            "00000000000000000000000000000000000000000000000000000000000000000000000000000000" +
            "00000000000000000000000000000000000000000000000000000000000000000000000000000000" +
            "00000000000000000000000000000000000000000000000000000000000000000000000000000000" +
            "00000000000000000000000000000000000000000000000000000000000000000000000000000000" +
            "0000000000000000000000000000000000000001",
        "expected": "1E-999"
    },
    {"description": "Non-Canonical Parsing - nan", "input": "nan", "expected": "NaN"},
    {"description": "Non-Canonical Parsing - nAn", "input": "nAn", "expected": "NaN"},
    {
        "description": "Non-Canonical Parsing - +infinity",
        "input": "+infinity",
        "expected": "Infinity"
    },
    {
        "description": "Non-Canonical Parsing - infinity",
        "input": "infinity",
        "expected": "Infinity"
    },
    {
        "description": "Non-Canonical Parsing - infiniTY",
        "input": "infiniTY",
        "expected": "Infinity"
    },
    {"description": "Non-Canonical Parsing - inf", "input": "inf", "expected": "Infinity"},
    {"description": "Non-Canonical Parsing - inF", "input": "inF", "expected": "Infinity"},
    {
        "description": "Non-Canonical Parsing - -infinity",
        "input": "-infinity",
        "expected": "-Infinity"
    },
    {
        "description": "Non-Canonical Parsing - -infiniTy",
        "input": "-infiniTy",
        "expected": "-Infinity"
    },
    {"description": "Non-Canonical Parsing - -Inf", "input": "-Infinity", "expected": "-Infinity"},
    {"description": "Non-Canonical Parsing - -inf", "input": "-inf", "expected": "-Infinity"},
    {"description": "Non-Canonical Parsing - -inF", "input": "-inF", "expected": "-Infinity"},
    {"description": "Rounded Subnormal number", "input": "10E-6177", "expected": "1E-6176"},
    {"description": "Clamped", "input": "1E6112", "expected": "1.0E+6112"},
    {
        "description": "Exact rounding",
        "input":
            "100000000000000000000000000000000000000000000000000000000000000000000000000000000" +
            "000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
            "000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
            "000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
            "000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
            "000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
            "000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
            "000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
            "000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
            "000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
            "000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
            "000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
            "0000000000000000000000000000",
        "expected": "1.000000000000000000000000000000000E+999"
    }
];

testData.forEach(function(testCase) {
    print(`Test - ${testCase.description}`);
    var output = NumberDecimal(testCase.input).toString();
    if (testCase.expected) {
        assert.eq(output, `NumberDecimal("${testCase.expected}")`);
    } else {
        assert.eq(output, `NumberDecimal("${testCase.input}")`);
    }
});
}());