1 // Copyright 2018 Ulf Adams
3 // The contents of this file may be used under the terms of the Apache License,
6 // (See accompanying file LICENSE-Apache or copy at
7 // http://www.apache.org/licenses/LICENSE-2.0)
9 // Alternatively, the contents of this file may be used under the terms of
10 // the Boost Software License, Version 1.0.
11 // (See accompanying file LICENSE-Boost or copy at
12 // https://www.boost.org/LICENSE_1_0.txt)
14 // Unless required by applicable law or agreed to in writing, this software
15 // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 // KIND, either express or implied.
19 This is a derivative work
22 #if defined(__SIZEOF_INT128__) && !defined(_MSC_VER) && !defined(RYU_ONLY_64_BIT_OPS)
23 #define BOOST_JSON_RYU_HAS_UINT128
24 #elif defined(_MSC_VER) && !defined(RYU_ONLY_64_BIT_OPS) && defined(_M_X64) \
25 && !defined(__clang__) // https://bugs.llvm.org/show_bug.cgi?id=37755
26 #define BOOST_JSON_RYU_HAS_64_BIT_INTRINSICS
29 // We want to test the size-optimized case here.
30 #if !defined(BOOST_JSON_RYU_OPTIMIZE_SIZE)
31 #define BOOST_JSON_RYU_OPTIMIZE_SIZE
33 #include <boost/json/detail/ryu/detail/d2s.hpp>
34 #include <boost/json/detail/ryu/detail/d2s_full_table.hpp>
45 TEST(D2sTableTest
, double_computePow5
) {
46 for (int i
= 0; i
< 326; i
++) {
48 double_computePow5(i
, m
);
49 ASSERT_EQ(m
[0], DOUBLE_POW5_SPLIT()[i
][0]);
50 ASSERT_EQ(m
[1], DOUBLE_POW5_SPLIT()[i
][1]);
54 TEST(D2sTableTest
, compute_offsets_for_double_computePow5
) {
55 uint32_t totalErrors
= 0;
56 uint32_t offsets
[13] = {0};
57 for (int i
= 0; i
< 326; i
++) {
59 double_computePow5(i
, m
);
60 if (m
[0] != DOUBLE_POW5_SPLIT()[i
][0]) {
61 offsets
[i
/ POW5_TABLE_SIZE
] |= 1 << (i
% POW5_TABLE_SIZE
);
65 if (totalErrors
!= 0) {
66 for (int i
= 0; i
< 13; i
++) {
67 printf("0x%08x,\n", offsets
[i
]);
70 ASSERT_EQ(totalErrors
, 0);
73 TEST(D2sTableTest
, double_computeInvPow5
) {
74 for (int i
= 0; i
< 292; i
++) {
76 double_computeInvPow5(i
, m
);
77 ASSERT_EQ(m
[0], DOUBLE_POW5_INV_SPLIT()[i
][0]);
78 ASSERT_EQ(m
[1], DOUBLE_POW5_INV_SPLIT()[i
][1]);
82 TEST(D2sTableTest
, compute_offsets_for_double_computeInvPow5
) {
83 uint32_t totalErrors
= 0;
84 uint32_t offsets
[20] = {0};
85 for (int i
= 0; i
< 292; i
++) {
87 double_computeInvPow5(i
, m
);
88 if (m
[0] != DOUBLE_POW5_INV_SPLIT()[i
][0]) {
89 offsets
[i
/ 16] |= ((DOUBLE_POW5_INV_SPLIT()[i
][0] - m
[0]) & 3) << ((i
% 16) << 1);
93 if (totalErrors
!= 0) {
94 for (int i
= 0; i
< 20; i
++) {
95 printf("0x%08x,\n", offsets
[i
]);
98 ASSERT_EQ(totalErrors
, 0);