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>
46 TEST(D2sTableTest
, double_computePow5
) {
47 for (int i
= 0; i
< 326; i
++) {
49 double_computePow5(i
, m
);
50 ASSERT_EQ(m
[0], DOUBLE_POW5_SPLIT()[i
][0]);
51 ASSERT_EQ(m
[1], DOUBLE_POW5_SPLIT()[i
][1]);
55 TEST(D2sTableTest
, compute_offsets_for_double_computePow5
) {
56 uint32_t totalErrors
= 0;
57 uint32_t offsets
[13] = {0};
58 for (int i
= 0; i
< 326; i
++) {
60 double_computePow5(i
, m
);
61 if (m
[0] != DOUBLE_POW5_SPLIT()[i
][0]) {
62 offsets
[i
/ POW5_TABLE_SIZE
] |= 1 << (i
% POW5_TABLE_SIZE
);
66 if (totalErrors
!= 0) {
67 for (int i
= 0; i
< 13; i
++) {
68 printf("0x%08x,\n", offsets
[i
]);
71 ASSERT_EQ(totalErrors
, 0);
74 TEST(D2sTableTest
, double_computeInvPow5
) {
75 for (int i
= 0; i
< 292; i
++) {
77 double_computeInvPow5(i
, m
);
78 ASSERT_EQ(m
[0], DOUBLE_POW5_INV_SPLIT()[i
][0]);
79 ASSERT_EQ(m
[1], DOUBLE_POW5_INV_SPLIT()[i
][1]);
83 TEST(D2sTableTest
, compute_offsets_for_double_computeInvPow5
) {
84 uint32_t totalErrors
= 0;
85 uint32_t offsets
[20] = {0};
86 for (int i
= 0; i
< 292; i
++) {
88 double_computeInvPow5(i
, m
);
89 if (m
[0] != DOUBLE_POW5_INV_SPLIT()[i
][0]) {
90 offsets
[i
/ 16] |= ((DOUBLE_POW5_INV_SPLIT()[i
][0] - m
[0]) & 3) << ((i
% 16) << 1);
94 if (totalErrors
!= 0) {
95 for (int i
= 0; i
< 20; i
++) {
96 printf("0x%08x,\n", offsets
[i
]);
99 ASSERT_EQ(totalErrors
, 0);