From c59ece15e9546eca0debdc5feb28c89fb3fb0c6e Mon Sep 17 00:00:00 2001 From: Vibe Nuage Agent Date: Tue, 17 Nov 2026 12:07:06 +0000 Subject: [PATCH 1/2] add .clang-format, CI check, and clang-format-off markers around tables - .clang-format tuned to minimize the diff against the current code (measured with clang-format 18.1.8): LLVM base with ColumnLimit: 0, PointerAlignment: Left, cast spacing, no include re-sorting, and one-liner short-block style. - Big generated tables are protected with // clang-format off/on markers placed right around the arrays, inside the files (digit_table.h, d2s_small_table.h, *_full_table.h, generic_128.h, tests/d2fixed_test.cc). Markers are enforced by clang-format itself, so even a manual `clang-format -i` cannot re-pack the tables. - scripts/check-clang-format.sh runs `clang-format --dry-run --Werror` over all C/C++ files under ryu/ (.c/.h/.cc/.cpp/.hh); presubmit gains a clang-format job pinned to clang-format 18.1.8. Co-authored-by: Mistral Vibe Co-authored-by: mbouaziz --- .clang-format | 7 +++++++ .github/workflows/presubmit.yml | 9 +++++++++ ryu/d2fixed_full_table.h | 2 ++ ryu/d2s_full_table.h | 2 ++ ryu/d2s_small_table.h | 2 ++ ryu/digit_table.h | 2 ++ ryu/f2s_full_table.h | 2 ++ ryu/generic_128.h | 2 ++ ryu/tests/d2fixed_test.cc | 2 ++ scripts/check-clang-format.sh | 16 ++++++++++++++++ 10 files changed, 46 insertions(+) create mode 100644 .clang-format create mode 100755 scripts/check-clang-format.sh diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..8fa5646e --- /dev/null +++ b/.clang-format @@ -0,0 +1,7 @@ +BasedOnStyle: LLVM +ColumnLimit: 0 +SpaceAfterCStyleCast: true +AllowShortIfStatementsOnASingleLine: AllIfsAndElse +AllowShortBlocksOnASingleLine: Always +SortIncludes: Never +PointerAlignment: Left diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index e04cb361..31089cc2 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -63,3 +63,12 @@ jobs: bazel run -c opt --copt=-DRYU_OPTIMIZE_SIZE //ryu/benchmark:ryu_printf_benchmark -- -samples=200 bazel run -c opt --copt=-DRYU_OPTIMIZE_SIZE --copt=-DRYU_ONLY_64_BIT_OPS //ryu/benchmark:ryu_benchmark bazel run -c opt --copt=-DRYU_OPTIMIZE_SIZE --copt=-DRYU_ONLY_64_BIT_OPS //ryu/benchmark:ryu_printf_benchmark -- -samples=200 + + clang-format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install clang-format + run: pip install clang-format==18.1.8 + - name: Check formatting + run: ./scripts/check-clang-format.sh diff --git a/ryu/d2fixed_full_table.h b/ryu/d2fixed_full_table.h index 70857652..ac2a2867 100644 --- a/ryu/d2fixed_full_table.h +++ b/ryu/d2fixed_full_table.h @@ -21,6 +21,7 @@ #define TABLE_SIZE 64 +// clang-format off static const uint16_t POW10_OFFSET[TABLE_SIZE] = { 0, 2, 5, 8, 12, 16, 21, 26, 32, 39, 46, 54, 62, 71, 80, 90, 100, 111, 122, 134, @@ -4416,5 +4417,6 @@ static const uint64_t POW10_SPLIT_2[3133][3] = { { 0u, 0u, 241525390625u }, { 0u, 0u, 33000000000u }, }; +// clang-format on #endif // RYU_D2FIXED_FULL_TABLE_H diff --git a/ryu/d2s_full_table.h b/ryu/d2s_full_table.h index c8629eef..fdc5785b 100644 --- a/ryu/d2s_full_table.h +++ b/ryu/d2s_full_table.h @@ -24,6 +24,7 @@ #define DOUBLE_POW5_INV_TABLE_SIZE 342 #define DOUBLE_POW5_TABLE_SIZE 326 +// clang-format off static const uint64_t DOUBLE_POW5_INV_SPLIT[DOUBLE_POW5_INV_TABLE_SIZE][2] = { { 1u, 2305843009213693952u }, { 11068046444225730970u, 1844674407370955161u }, { 5165088340638674453u, 1475739525896764129u }, { 7821419487252849886u, 1180591620717411303u }, @@ -363,5 +364,6 @@ static const uint64_t DOUBLE_POW5_SPLIT[DOUBLE_POW5_TABLE_SIZE][2] = { { 507629346944023544u, 1822780504889099373u }, { 5246222702107417334u, 2278475631111374216u }, { 3278889188817135834u, 1424047269444608885u }, { 8710297504448807696u, 1780059086805761106u } }; +// clang-format on #endif // RYU_D2S_FULL_TABLE_H diff --git a/ryu/d2s_small_table.h b/ryu/d2s_small_table.h index b0a413a3..e0654427 100644 --- a/ryu/d2s_small_table.h +++ b/ryu/d2s_small_table.h @@ -26,6 +26,7 @@ #define DOUBLE_POW5_INV_BITCOUNT 125 #define DOUBLE_POW5_BITCOUNT 125 +// clang-format off static const uint64_t DOUBLE_POW5_INV_SPLIT2[15][2] = { { 1u, 2305843009213693952u }, { 5955668970331000884u, 1784059615882449851u }, @@ -81,6 +82,7 @@ static const uint64_t DOUBLE_POW5_TABLE[POW5_TABLE_SIZE] = { 2384185791015625ull, 11920928955078125ull, 59604644775390625ull, 298023223876953125ull //, 1490116119384765625ull }; +// clang-format on #if defined(HAS_UINT128) diff --git a/ryu/digit_table.h b/ryu/digit_table.h index 02219bc6..fc6b5172 100644 --- a/ryu/digit_table.h +++ b/ryu/digit_table.h @@ -19,6 +19,7 @@ // A table of all two-digit numbers. This is used to speed up decimal digit // generation by copying pairs of digits into the final output. +// clang-format off static const char DIGIT_TABLE[200] = { '0','0','0','1','0','2','0','3','0','4','0','5','0','6','0','7','0','8','0','9', '1','0','1','1','1','2','1','3','1','4','1','5','1','6','1','7','1','8','1','9', @@ -31,5 +32,6 @@ static const char DIGIT_TABLE[200] = { '8','0','8','1','8','2','8','3','8','4','8','5','8','6','8','7','8','8','8','9', '9','0','9','1','9','2','9','3','9','4','9','5','9','6','9','7','9','8','9','9' }; +// clang-format on #endif // RYU_DIGIT_TABLE_H diff --git a/ryu/f2s_full_table.h b/ryu/f2s_full_table.h index 50e59c20..71537bf3 100644 --- a/ryu/f2s_full_table.h +++ b/ryu/f2s_full_table.h @@ -21,6 +21,7 @@ #define FLOAT_POW5_INV_BITCOUNT 59 #define FLOAT_POW5_BITCOUNT 61 +// clang-format off static uint64_t FLOAT_POW5_INV_SPLIT[55] = { 576460752303423489u, 461168601842738791u, 368934881474191033u, 295147905179352826u, 472236648286964522u, 377789318629571618u, 302231454903657294u, 483570327845851670u, @@ -51,5 +52,6 @@ static const uint64_t FLOAT_POW5_SPLIT[47] = { 2117582368135750847u, 1323488980084844279u, 1654361225106055349u, 2067951531382569187u, 1292469707114105741u, 1615587133892632177u, 2019483917365790221u }; +// clang-format on #endif // RYU_F2S_FULL_TABLE_H diff --git a/ryu/generic_128.h b/ryu/generic_128.h index 6f66ba06..095f9905 100644 --- a/ryu/generic_128.h +++ b/ryu/generic_128.h @@ -30,6 +30,7 @@ typedef __uint128_t uint128_t; // There's no way to define 128-bit constants in C, so we use little-endian // pairs of 64-bit constants. +// clang-format off static const uint64_t GENERIC_POW5_TABLE[POW5_TABLE_SIZE][2] = { { 1u, 0u }, { 5u, 0u }, @@ -358,6 +359,7 @@ static const uint64_t POW5_INV_ERRORS[154] = { 0x0010501401051441u, 0x0010501450504401u, 0x4554585440044444u, 0x5155555951450455u, 0x0040000400105555u, 0x0000000000000001u, }; +// clang-format on // Returns e == 0 ? 1 : ceil(log_2(5^e)); requires 0 <= e <= 32768. static inline uint32_t pow5bits(const int32_t e) { diff --git a/ryu/tests/d2fixed_test.cc b/ryu/tests/d2fixed_test.cc index b4a35855..762be13d 100644 --- a/ryu/tests/d2fixed_test.cc +++ b/ryu/tests/d2fixed_test.cc @@ -30,6 +30,7 @@ struct test_case { }; // These values test every power of ten that's within the range of doubles. +// clang-format off const test_case all_powers_of_ten[] = { { 1e-323, @@ -35619,6 +35620,7 @@ const test_case all_binary_exponents[] = { "6195117678217681054268005181200990732288e+308" }, }; +// clang-format on static double int64Bits2Double(uint64_t bits) { double f; diff --git a/scripts/check-clang-format.sh b/scripts/check-clang-format.sh new file mode 100755 index 00000000..9e1cf96b --- /dev/null +++ b/scripts/check-clang-format.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +# Verifies that all ryu C/C++ sources are clang-format clean. +# +# Big generated tables are protected by `// clang-format off/on` markers in +# the files themselves (digit_table.h, d2s_small_table.h, *_full_table.h, +# generic_128.h, tests/d2fixed_test.cc), so every source file under ryu/ is +# checked. .c/.h/.cc/.cpp/.hh are all covered. +# +# Requires clang-format 18.x (CI installs clang-format==18.1.8 via pip). +set -euo pipefail +cd "$(dirname "$0")/.." + +mapfile -t FILES < <(git ls-files | grep -E '^ryu/.*\.(c|h|cc|cpp|hh)$') + +echo "${#FILES[@]} files" +clang-format --dry-run --Werror "${FILES[@]}" From 9cb292b602a2035b91a9e935d3c30e096d1303f1 Mon Sep 17 00:00:00 2001 From: Vibe Nuage Agent Date: Tue, 17 Nov 2026 12:07:07 +0000 Subject: [PATCH 2/2] apply clang-format to all ryu C/C++ sources One-time reformat with the new .clang-format (clang-format 18.1.8). The // clang-format off/on markers keep the big generated tables byte-identical (except the marker lines themselves); the ~190 changed lines elsewhere are almost all cast spacing and brace/indent normalization. No functional changes (make -C ryu test passes 8/8). Co-authored-by: Mistral Vibe Co-authored-by: mbouaziz --- ryu/benchmark/benchmark.cc | 9 +- ryu/benchmark/benchmark_fixed.c | 50 ++-- ryu/benchmark/benchmark_fixed.cc | 12 +- ryu/common.h | 2 +- ryu/d2fixed.c | 50 ++-- ryu/d2s.c | 2 +- ryu/d2s_intrinsics.h | 60 ++--- ryu/d2s_small_table.h | 2 +- ryu/f2s_intrinsics.h | 18 +- ryu/generic_128.c | 7 +- ryu/generic_128.h | 14 +- ryu/ryu_parse.h | 8 +- ryu/s2d.c | 10 +- ryu/s2f.c | 9 +- ryu/tests/common_test.cc | 2 - ryu/tests/d2fixed_test.cc | 378 ++++++++++++++++--------------- ryu/tests/d2s_intrinsics_test.cc | 28 +-- ryu/tests/d2s_table_test.cc | 1 - ryu/tests/d2s_test.cc | 15 +- ryu/tests/f2s_test.cc | 9 +- ryu/tests/generic_128_test.cc | 97 ++++---- ryu/tests/s2d_test.cc | 9 +- ryu/tests/s2f_test.cc | 7 +- 23 files changed, 423 insertions(+), 376 deletions(-) diff --git a/ryu/benchmark/benchmark.cc b/ryu/benchmark/benchmark.cc index 4dc755e3..13e89666 100644 --- a/ryu/benchmark/benchmark.cc +++ b/ryu/benchmark/benchmark.cc @@ -34,15 +34,14 @@ #include "third_party/double-conversion/double-conversion/utils.h" #include "third_party/double-conversion/double-conversion/double-conversion.h" -using double_conversion::StringBuilder; using double_conversion::DoubleToStringConverter; +using double_conversion::StringBuilder; using namespace std::chrono; constexpr int BUFFER_SIZE = 40; static char buffer[BUFFER_SIZE]; static DoubleToStringConverter converter( - DoubleToStringConverter::Flags::EMIT_TRAILING_DECIMAL_POINT - | DoubleToStringConverter::Flags::EMIT_TRAILING_ZERO_AFTER_POINT, + DoubleToStringConverter::Flags::EMIT_TRAILING_DECIMAL_POINT | DoubleToStringConverter::Flags::EMIT_TRAILING_ZERO_AFTER_POINT, "Infinity", "NaN", 'E', @@ -113,7 +112,7 @@ class benchmark_options { bool classic() const { return m_classic; } int small_digits() const { return m_small_digits; } - void parse(const char * const arg) { + void parse(const char* const arg) { if (strcmp(arg, "-32") == 0) { m_run32 = true; m_run64 = false; @@ -144,7 +143,7 @@ class benchmark_options { } private: - void fail(const char * const arg) { + void fail(const char* const arg) { printf("Unrecognized option '%s'.\n", arg); exit(EXIT_FAILURE); } diff --git a/ryu/benchmark/benchmark_fixed.c b/ryu/benchmark/benchmark_fixed.c index f4012961..09b1d492 100644 --- a/ryu/benchmark/benchmark_fixed.c +++ b/ryu/benchmark/benchmark_fixed.c @@ -53,27 +53,27 @@ struct mean_and_variance { typedef struct mean_and_variance mean_and_variance; - void init(mean_and_variance* mv) { - mv->n = 0; - mv->mean = 0; - mv->m2 = 0; - } +void init(mean_and_variance* mv) { + mv->n = 0; + mv->mean = 0; + mv->m2 = 0; +} - void update(mean_and_variance* mv, double x) { - ++mv->n; - double d = x - mv->mean; - mv->mean += d / mv->n; - double d2 = x - mv->mean; - mv->m2 += d * d2; - } +void update(mean_and_variance* mv, double x) { + ++mv->n; + double d = x - mv->mean; + mv->mean += d / mv->n; + double d2 = x - mv->mean; + mv->m2 += d * d2; +} - double variance(mean_and_variance* mv) { - return mv->m2 / (mv->n - 1); - } +double variance(mean_and_variance* mv) { + return mv->m2 / (mv->n - 1); +} - double stddev(mean_and_variance* mv) { - return sqrt(variance(mv)); - } +double stddev(mean_and_variance* mv) { + return sqrt(variance(mv)); +} double generate_double(uint64_t* r) { *r = RandomU64(); @@ -97,7 +97,7 @@ static int bench64_fixed(const uint32_t samples, const uint32_t iterations, cons uint64_t r = 0; const double f = generate_double(&r); -// printf("%f\n", f); + // printf("%f\n", f); clock_t t1 = clock(); for (int j = 0; j < iterations; ++j) { d2fixed_buffered(f, precision, bufferown); @@ -121,7 +121,7 @@ static int bench64_fixed(const uint32_t samples, const uint32_t iterations, cons printf("%s,%" PRIu64 ",%f,%f\n", bufferown, r, delta1, delta2); } -// printf("For %16" PRIX64 " %28s %28s\n", r, bufferown, buffer); + // printf("For %16" PRIX64 " %28s %28s\n", r, bufferown, buffer); if (strcmp(bufferown, buffer) != 0) { printf("For %16" PRIX64 " %28s %28s\n", r, bufferown, buffer); } @@ -150,8 +150,8 @@ static int bench64_exp(const uint32_t samples, const uint32_t iterations, const uint64_t r = 0; const double f = generate_double(&r); -// printf("%.20e\n", f); -// printf("For %16" PRIX64 "\n", r); + // printf("%.20e\n", f); + // printf("For %16" PRIX64 "\n", r); clock_t t1 = clock(); for (int j = 0; j < iterations; ++j) { d2exp_buffered(f, precision, bufferown); @@ -175,7 +175,7 @@ static int bench64_exp(const uint32_t samples, const uint32_t iterations, const printf("%s,%" PRIu64 ",%f,%f\n", bufferown, r, delta1, delta2); } -// printf("For %16" PRIX64 " %28s %28s\n", r, bufferown, buffer); + // printf("For %16" PRIX64 " %28s %28s\n", r, bufferown, buffer); if ((strcmp(bufferown, buffer) != 0) && !verbose) { printf("For %16" PRIX64 " %28s %28s\n", r, bufferown, buffer); } @@ -219,8 +219,8 @@ int main(int argc, char** argv) { } } if (false) { -// double d = int64Bits2Double(0x426E5FDA4A181F94); -// double d = int64Bits2Double(0xC27EF2838AD07A1A); + // double d = int64Bits2Double(0x426E5FDA4A181F94); + // double d = int64Bits2Double(0xC27EF2838AD07A1A); double d = int64Bits2Double(0x426C19FD2EFA7294); printf("%.10f\n", 1043657281728.98681640625); printf("%.10f\n", -2126683614471.63134765625); diff --git a/ryu/benchmark/benchmark_fixed.cc b/ryu/benchmark/benchmark_fixed.cc index 07510843..85fdc0bb 100644 --- a/ryu/benchmark/benchmark_fixed.cc +++ b/ryu/benchmark/benchmark_fixed.cc @@ -80,7 +80,7 @@ class benchmark_options { int small_digits() const { return m_small_digits; } int precision() const { return m_precision; } - void parse(const char * const arg) { + void parse(const char* const arg) { if (strcmp(arg, "-f") == 0) { m_run32 = false; m_run64 = true; @@ -115,7 +115,7 @@ class benchmark_options { } private: - void fail(const char * const arg) { + void fail(const char* const arg) { printf("Unrecognized option '%s'.\n", arg); exit(EXIT_FAILURE); } @@ -176,7 +176,7 @@ static int bench64_fixed(const benchmark_options& options) { uint64_t r = 0; const double f = generate_double(options, mt32, r); -// printf("%f\n", f); + // printf("%f\n", f); auto t1 = steady_clock::now(); for (int j = 0; j < options.iterations(); ++j) { d2fixed_buffered(f, static_cast(precision), bufferown); @@ -206,7 +206,7 @@ static int bench64_fixed(const benchmark_options& options) { } } -// printf("For %16" PRIX64 " %28s %28s\n", r, bufferown, buffer); + // printf("For %16" PRIX64 " %28s %28s\n", r, bufferown, buffer); if (!options.ryu_only() && strcmp(bufferown, buffer) != 0) { printf("For %16" PRIX64 " %28s %28s\n", r, bufferown, buffer); } @@ -234,7 +234,7 @@ static int bench64_exp(const benchmark_options& options) { uint64_t r = 0; const double f = generate_double(options, mt32, r); -// printf("%f\n", f); + // printf("%f\n", f); auto t1 = steady_clock::now(); for (int j = 0; j < options.iterations(); ++j) { d2exp_buffered(f, static_cast(precision), bufferown); @@ -264,7 +264,7 @@ static int bench64_exp(const benchmark_options& options) { } } -// printf("For %16" PRIX64 " %28s %28s\n", r, bufferown, buffer); + // printf("For %16" PRIX64 " %28s %28s\n", r, bufferown, buffer); if (!options.ryu_only() && !options.verbose() && strcmp(bufferown, buffer) != 0) { printf("For %16" PRIX64 " %28s %28s\n", r, bufferown, buffer); } diff --git a/ryu/common.h b/ryu/common.h index 7dc13094..de6b6a99 100644 --- a/ryu/common.h +++ b/ryu/common.h @@ -83,7 +83,7 @@ static inline uint32_t log10Pow5(const int32_t e) { return (((uint32_t) e) * 732923) >> 20; } -static inline int copy_special_str(char * const result, const bool sign, const bool exponent, const bool mantissa) { +static inline int copy_special_str(char* const result, const bool sign, const bool exponent, const bool mantissa) { if (mantissa) { memcpy(result, "NaN", 3); return 3; diff --git a/ryu/d2fixed.c b/ryu/d2fixed.c index 5f479abb..dd19c926 100644 --- a/ryu/d2fixed.c +++ b/ryu/d2fixed.c @@ -49,27 +49,27 @@ #if defined(HAS_UINT128) static inline uint128_t umul256(const uint128_t a, const uint64_t bHi, const uint64_t bLo, uint128_t* const productHi) { - const uint64_t aLo = (uint64_t)a; - const uint64_t aHi = (uint64_t)(a >> 64); + const uint64_t aLo = (uint64_t) a; + const uint64_t aHi = (uint64_t) (a >> 64); - const uint128_t b00 = (uint128_t)aLo * bLo; - const uint128_t b01 = (uint128_t)aLo * bHi; - const uint128_t b10 = (uint128_t)aHi * bLo; - const uint128_t b11 = (uint128_t)aHi * bHi; + const uint128_t b00 = (uint128_t) aLo * bLo; + const uint128_t b01 = (uint128_t) aLo * bHi; + const uint128_t b10 = (uint128_t) aHi * bLo; + const uint128_t b11 = (uint128_t) aHi * bHi; - const uint64_t b00Lo = (uint64_t)b00; - const uint64_t b00Hi = (uint64_t)(b00 >> 64); + const uint64_t b00Lo = (uint64_t) b00; + const uint64_t b00Hi = (uint64_t) (b00 >> 64); const uint128_t mid1 = b10 + b00Hi; - const uint64_t mid1Lo = (uint64_t)(mid1); - const uint64_t mid1Hi = (uint64_t)(mid1 >> 64); + const uint64_t mid1Lo = (uint64_t) (mid1); + const uint64_t mid1Hi = (uint64_t) (mid1 >> 64); const uint128_t mid2 = b01 + mid1Lo; - const uint64_t mid2Lo = (uint64_t)(mid2); - const uint64_t mid2Hi = (uint64_t)(mid2 >> 64); + const uint64_t mid2Lo = (uint64_t) (mid2); + const uint64_t mid2Hi = (uint64_t) (mid2 >> 64); const uint128_t pHi = b11 + mid1Hi + mid2Hi; - const uint128_t pLo = ((uint128_t)mid2Lo << 64) | b00Lo; + const uint128_t pLo = ((uint128_t) mid2Lo << 64) | b00Lo; *productHi = pHi; return pLo; @@ -121,7 +121,7 @@ static inline uint32_t mulShift_mod1e9(const uint64_t m, const uint64_t* const m #if defined(HAS_64_BIT_INTRINSICS) // Returns the low 64 bits of the high 128 bits of the 256-bit product of a and b. static inline uint64_t umul256_hi128_lo64( - const uint64_t aHi, const uint64_t aLo, const uint64_t bHi, const uint64_t bLo) { + const uint64_t aHi, const uint64_t aLo, const uint64_t bHi, const uint64_t bLo) { uint64_t b00Hi; const uint64_t b00Lo = umul128(aLo, bLo, &b00Hi); uint64_t b01Hi; @@ -158,12 +158,12 @@ static inline uint32_t mulShift_mod1e9(const uint64_t m, const uint64_t* const m const uint64_t low1 = umul128(m, mul[1], &high1); // 64 uint64_t high2; // 192 const uint64_t low2 = umul128(m, mul[2], &high2); // 128 - const uint64_t s0low = low0; // 0 - (void) s0low; // unused - const uint64_t s0high = low1 + high0; // 64 + const uint64_t s0low = low0; // 0 + (void) s0low; // unused + const uint64_t s0high = low1 + high0; // 64 const uint32_t c1 = s0high < low1; const uint64_t s1low = low2 + high1 + c1; // 128 - const uint32_t c2 = s1low < low2; // high1 + c1 can't overflow, so compare against low2 + const uint32_t c2 = s1low < low2; // high1 + c1 can't overflow, so compare against low2 const uint64_t s1high = high2 + c2; // 192 #ifdef RYU_DEBUG if (j < 128 || j > 180) { @@ -177,7 +177,7 @@ static inline uint32_t mulShift_mod1e9(const uint64_t m, const uint64_t* const m const uint64_t shiftedhigh = s1high >> dist; const uint64_t shiftedlow = shiftright128(s1low, s1high, dist); return uint128_mod1e9(shiftedhigh, shiftedlow); -#else // HAS_64_BIT_INTRINSICS +#else // HAS_64_BIT_INTRINSICS if (j < 160) { // j: [128, 160) const uint64_t r0 = mod1e9(s1high); const uint64_t r1 = mod1e9((r0 << 32) | (s1low >> 32)); @@ -493,8 +493,7 @@ int d2fixed_buffered_n(double d, uint32_t precision, char* result) { } else { // Is m * 10^(additionalDigits + 1) / 2^(-e2) integer? const int32_t requiredTwos = -e2 - (int32_t) precision - 1; - const bool trailingZeros = requiredTwos <= 0 - || (requiredTwos < 60 && multipleOfPowerOf2(m2, (uint32_t) requiredTwos)); + const bool trailingZeros = requiredTwos <= 0 || (requiredTwos < 60 && multipleOfPowerOf2(m2, (uint32_t) requiredTwos)); roundUp = trailingZeros ? 2 : 1; #ifdef RYU_DEBUG printf("requiredTwos=%d\n", requiredTwos); @@ -555,14 +554,12 @@ void d2fixed_buffered(double d, uint32_t precision, char* result) { } char* d2fixed(double d, uint32_t precision) { - char* const buffer = (char*)malloc(2000); + char* const buffer = (char*) malloc(2000); const int index = d2fixed_buffered_n(d, precision, buffer); buffer[index] = '\0'; return buffer; } - - int d2exp_buffered_n(double d, uint32_t precision, char* result) { const uint64_t bits = double_to_bits(d); #ifdef RYU_DEBUG @@ -730,8 +727,7 @@ int d2exp_buffered_n(double d, uint32_t precision, char* result) { // precision was already increased by 1, so we don't need to write + 1 here. const int32_t rexp = (int32_t) precision - exp; const int32_t requiredTwos = -e2 - rexp; - bool trailingZeros = requiredTwos <= 0 - || (requiredTwos < 60 && multipleOfPowerOf2(m2, (uint32_t) requiredTwos)); + bool trailingZeros = requiredTwos <= 0 || (requiredTwos < 60 && multipleOfPowerOf2(m2, (uint32_t) requiredTwos)); if (rexp < 0) { const int32_t requiredFives = -rexp; trailingZeros = trailingZeros && multipleOfPowerOf5(m2, (uint32_t) requiredFives); @@ -812,7 +808,7 @@ void d2exp_buffered(double d, uint32_t precision, char* result) { } char* d2exp(double d, uint32_t precision) { - char* const buffer = (char*)malloc(2000); + char* const buffer = (char*) malloc(2000); const int index = d2exp_buffered_n(d, precision, buffer); buffer[index] = '\0'; return buffer; diff --git a/ryu/d2s.c b/ryu/d2s.c index 41de8756..2cbb005a 100644 --- a/ryu/d2s.c +++ b/ryu/d2s.c @@ -420,7 +420,7 @@ static inline int to_chars(const floating_decimal_64 v, const bool sign, char* c } static inline bool d2d_small_int(const uint64_t ieeeMantissa, const uint32_t ieeeExponent, - floating_decimal_64* const v) { + floating_decimal_64* const v) { const uint64_t m2 = (1ull << DOUBLE_MANTISSA_BITS) | ieeeMantissa; const int32_t e2 = (int32_t) ieeeExponent - DOUBLE_BIAS - DOUBLE_MANTISSA_BITS; diff --git a/ryu/d2s_intrinsics.h b/ryu/d2s_intrinsics.h index 426ed8f0..0baf6f86 100644 --- a/ryu/d2s_intrinsics.h +++ b/ryu/d2s_intrinsics.h @@ -63,29 +63,29 @@ static inline uint64_t shiftright128(const uint64_t lo, const uint64_t hi, const static inline uint64_t umul128(const uint64_t a, const uint64_t b, uint64_t* const productHi) { // The casts here help MSVC to avoid calls to the __allmul library function. - const uint32_t aLo = (uint32_t)a; - const uint32_t aHi = (uint32_t)(a >> 32); - const uint32_t bLo = (uint32_t)b; - const uint32_t bHi = (uint32_t)(b >> 32); + const uint32_t aLo = (uint32_t) a; + const uint32_t aHi = (uint32_t) (a >> 32); + const uint32_t bLo = (uint32_t) b; + const uint32_t bHi = (uint32_t) (b >> 32); - const uint64_t b00 = (uint64_t)aLo * bLo; - const uint64_t b01 = (uint64_t)aLo * bHi; - const uint64_t b10 = (uint64_t)aHi * bLo; - const uint64_t b11 = (uint64_t)aHi * bHi; + const uint64_t b00 = (uint64_t) aLo * bLo; + const uint64_t b01 = (uint64_t) aLo * bHi; + const uint64_t b10 = (uint64_t) aHi * bLo; + const uint64_t b11 = (uint64_t) aHi * bHi; - const uint32_t b00Lo = (uint32_t)b00; - const uint32_t b00Hi = (uint32_t)(b00 >> 32); + const uint32_t b00Lo = (uint32_t) b00; + const uint32_t b00Hi = (uint32_t) (b00 >> 32); const uint64_t mid1 = b10 + b00Hi; - const uint32_t mid1Lo = (uint32_t)(mid1); - const uint32_t mid1Hi = (uint32_t)(mid1 >> 32); + const uint32_t mid1Lo = (uint32_t) (mid1); + const uint32_t mid1Hi = (uint32_t) (mid1 >> 32); const uint64_t mid2 = b01 + mid1Lo; - const uint32_t mid2Lo = (uint32_t)(mid2); - const uint32_t mid2Hi = (uint32_t)(mid2 >> 32); + const uint32_t mid2Lo = (uint32_t) (mid2); + const uint32_t mid2Hi = (uint32_t) (mid2 >> 32); const uint64_t pHi = b11 + mid1Hi + mid2Hi; - const uint64_t pLo = ((uint64_t)mid2Lo << 32) | b00Lo; + const uint64_t pLo = ((uint64_t) mid2Lo << 32) | b00Lo; *productHi = pHi; return pLo; @@ -263,19 +263,19 @@ static inline uint64_t mulShift64(const uint64_t m, const uint64_t* const mul, c } static inline uint64_t mulShiftAll64(const uint64_t m, const uint64_t* const mul, const int32_t j, - uint64_t* const vp, uint64_t* const vm, const uint32_t mmShift) { -// m <<= 2; -// uint128_t b0 = ((uint128_t) m) * mul[0]; // 0 -// uint128_t b2 = ((uint128_t) m) * mul[1]; // 64 -// -// uint128_t hi = (b0 >> 64) + b2; -// uint128_t lo = b0 & 0xffffffffffffffffull; -// uint128_t factor = (((uint128_t) mul[1]) << 64) + mul[0]; -// uint128_t vpLo = lo + (factor << 1); -// *vp = (uint64_t) ((hi + (vpLo >> 64)) >> (j - 64)); -// uint128_t vmLo = lo - (factor << mmShift); -// *vm = (uint64_t) ((hi + (vmLo >> 64) - (((uint128_t) 1ull) << 64)) >> (j - 64)); -// return (uint64_t) (hi >> (j - 64)); + uint64_t* const vp, uint64_t* const vm, const uint32_t mmShift) { + // m <<= 2; + // uint128_t b0 = ((uint128_t) m) * mul[0]; // 0 + // uint128_t b2 = ((uint128_t) m) * mul[1]; // 64 + // + // uint128_t hi = (b0 >> 64) + b2; + // uint128_t lo = b0 & 0xffffffffffffffffull; + // uint128_t factor = (((uint128_t) mul[1]) << 64) + mul[0]; + // uint128_t vpLo = lo + (factor << 1); + // *vp = (uint64_t) ((hi + (vpLo >> 64)) >> (j - 64)); + // uint128_t vmLo = lo - (factor << mmShift); + // *vm = (uint64_t) ((hi + (vmLo >> 64) - (((uint128_t) 1ull) << 64)) >> (j - 64)); + // return (uint64_t) (hi >> (j - 64)); *vp = mulShift64(4 * m + 2, mul, j); *vm = mulShift64(4 * m - 1 - mmShift, mul, j); return mulShift64(4 * m, mul, j); @@ -297,7 +297,7 @@ static inline uint64_t mulShift64(const uint64_t m, const uint64_t* const mul, c } static inline uint64_t mulShiftAll64(const uint64_t m, const uint64_t* const mul, const int32_t j, - uint64_t* const vp, uint64_t* const vm, const uint32_t mmShift) { + uint64_t* const vp, uint64_t* const vm, const uint32_t mmShift) { *vp = mulShift64(4 * m + 2, mul, j); *vm = mulShift64(4 * m - 1 - mmShift, mul, j); return mulShift64(4 * m, mul, j); @@ -320,7 +320,7 @@ static inline uint64_t mulShift64(const uint64_t m, const uint64_t* const mul, c // This is faster if we don't have a 64x64->128-bit multiplication. static inline uint64_t mulShiftAll64(uint64_t m, const uint64_t* const mul, const int32_t j, - uint64_t* const vp, uint64_t* const vm, const uint32_t mmShift) { + uint64_t* const vp, uint64_t* const vm, const uint32_t mmShift) { m <<= 1; // m is maximum 55 bits uint64_t tmp; diff --git a/ryu/d2s_small_table.h b/ryu/d2s_small_table.h index e0654427..6ad690ba 100644 --- a/ryu/d2s_small_table.h +++ b/ryu/d2s_small_table.h @@ -123,7 +123,7 @@ static inline void double_computeInvPow5(const uint32_t i, uint64_t* const resul const uint32_t delta = pow5bits(base2) - pow5bits(i); assert(i / 16 < sizeof(POW5_INV_OFFSETS) / sizeof(POW5_INV_OFFSETS[0])); const uint128_t shiftedSum = - ((b0 >> delta) + (b2 << (64 - delta))) + 1 + ((POW5_INV_OFFSETS[i / 16] >> ((i % 16) << 1)) & 3); + ((b0 >> delta) + (b2 << (64 - delta))) + 1 + ((POW5_INV_OFFSETS[i / 16] >> ((i % 16) << 1)) & 3); result[0] = (uint64_t) shiftedSum; result[1] = (uint64_t) (shiftedSum >> 64); } diff --git a/ryu/f2s_intrinsics.h b/ryu/f2s_intrinsics.h index bb822c9a..38fdfcdc 100644 --- a/ryu/f2s_intrinsics.h +++ b/ryu/f2s_intrinsics.h @@ -69,28 +69,28 @@ static inline uint32_t mulShift32(const uint32_t m, const uint64_t factor, const // The casts here help MSVC to avoid calls to the __allmul library // function. - const uint32_t factorLo = (uint32_t)(factor); - const uint32_t factorHi = (uint32_t)(factor >> 32); - const uint64_t bits0 = (uint64_t)m * factorLo; - const uint64_t bits1 = (uint64_t)m * factorHi; + const uint32_t factorLo = (uint32_t) (factor); + const uint32_t factorHi = (uint32_t) (factor >> 32); + const uint64_t bits0 = (uint64_t) m * factorLo; + const uint64_t bits1 = (uint64_t) m * factorHi; #if defined(RYU_32_BIT_PLATFORM) // On 32-bit platforms we can avoid a 64-bit shift-right since we only // need the upper 32 bits of the result and the shift value is > 32. - const uint32_t bits0Hi = (uint32_t)(bits0 >> 32); - uint32_t bits1Lo = (uint32_t)(bits1); - uint32_t bits1Hi = (uint32_t)(bits1 >> 32); + const uint32_t bits0Hi = (uint32_t) (bits0 >> 32); + uint32_t bits1Lo = (uint32_t) (bits1); + uint32_t bits1Hi = (uint32_t) (bits1 >> 32); bits1Lo += bits0Hi; bits1Hi += (bits1Lo < bits0Hi); if (shift >= 64) { // s2f can call this with a shift value >= 64, which we have to handle. // This could now be slower than the !defined(RYU_32_BIT_PLATFORM) case. - return (uint32_t)(bits1Hi >> (shift - 64)); + return (uint32_t) (bits1Hi >> (shift - 64)); } else { const int32_t s = shift - 32; return (bits1Hi << (32 - s)) | (bits1Lo >> s); } -#else // RYU_32_BIT_PLATFORM +#else // RYU_32_BIT_PLATFORM const uint64_t sum = (bits0 >> 32) + bits1; const uint64_t shiftedSum = sum >> (shift - 32); assert(shiftedSum <= UINT32_MAX); diff --git a/ryu/generic_128.c b/ryu/generic_128.c index 2bcd9e5d..abd4725c 100644 --- a/ryu/generic_128.c +++ b/ryu/generic_128.c @@ -141,8 +141,7 @@ struct floating_decimal_128 generic_binary_to_decimal( const uint128_t mv = 4 * m2; // Implicit bool -> int conversion. True is 1, false is 0. const uint32_t mmShift = - (ieeeMantissa != (explicitLeadingBit ? ONE << (mantissaBits - 1) : 0)) - || (ieeeExponent == 0); + (ieeeMantissa != (explicitLeadingBit ? ONE << (mantissaBits - 1) : 0)) || (ieeeExponent == 0); // Step 3: Convert to a decimal power base using 128-bit arithmetic. uint128_t vr, vp, vm; @@ -265,7 +264,7 @@ struct floating_decimal_128 generic_binary_to_decimal( } // We need to take vr+1 if vr is outside bounds or we need to round up. output = vr + - ((vr == vm && (!acceptBounds || !vmIsTrailingZeros)) || (lastRemovedDigit >= 5)); + ((vr == vm && (!acceptBounds || !vmIsTrailingZeros)) || (lastRemovedDigit >= 5)); const int32_t exp = e10 + removed; #ifdef RYU_DEBUG @@ -281,7 +280,7 @@ struct floating_decimal_128 generic_binary_to_decimal( return fd; } -static inline int copy_special_str(char * const result, const struct floating_decimal_128 fd) { +static inline int copy_special_str(char* const result, const struct floating_decimal_128 fd) { if (fd.mantissa) { memcpy(result, "NaN", 3); return 3; diff --git a/ryu/generic_128.h b/ryu/generic_128.h index 095f9905..d5bc7e18 100644 --- a/ryu/generic_128.h +++ b/ryu/generic_128.h @@ -389,13 +389,13 @@ static inline void mul_128_256_shift( const uint128_t s3 = b03 + b12; // 196 x const uint128_t c3 = s3 < b03; // 324 x - const uint128_t p0 = s0 + (s1 << 64); // 0 - const uint128_t d0 = p0 < b00; // 128 - const uint128_t q1 = s2 + (s1 >> 64) + (s3 << 64); // 128 - const uint128_t d1 = q1 < s2; // 256 - const uint128_t p1 = q1 + (c1 << 64) + d0; // 128 - const uint128_t d2 = p1 < q1; // 256 - const uint128_t p2 = b13 + (s3 >> 64) + c2 + (c3 << 64) + d1 + d2; // 256 + const uint128_t p0 = s0 + (s1 << 64); // 0 + const uint128_t d0 = p0 < b00; // 128 + const uint128_t q1 = s2 + (s1 >> 64) + (s3 << 64); // 128 + const uint128_t d1 = q1 < s2; // 256 + const uint128_t p1 = q1 + (c1 << 64) + d0; // 128 + const uint128_t d2 = p1 < q1; // 256 + const uint128_t p2 = b13 + (s3 >> 64) + c2 + (c3 << 64) + d1 + d2; // 256 if (shift < 128) { const uint128_t r0 = corr + ((p0 >> shift) | (p1 << (128 - shift))); diff --git a/ryu/ryu_parse.h b/ryu/ryu_parse.h index 9b554e30..4ea8636b 100644 --- a/ryu/ryu_parse.h +++ b/ryu/ryu_parse.h @@ -33,11 +33,11 @@ enum Status { MALFORMED_INPUT }; -enum Status s2d_n(const char * buffer, const int len, double * result); -enum Status s2d(const char * buffer, double * result); +enum Status s2d_n(const char* buffer, const int len, double* result); +enum Status s2d(const char* buffer, double* result); -enum Status s2f_n(const char * buffer, const int len, float * result); -enum Status s2f(const char * buffer, float * result); +enum Status s2f_n(const char* buffer, const int len, float* result); +enum Status s2f(const char* buffer, float* result); #ifdef __cplusplus } diff --git a/ryu/s2d.c b/ryu/s2d.c index 1486910e..43ea081c 100644 --- a/ryu/s2d.c +++ b/ryu/s2d.c @@ -68,7 +68,7 @@ static inline double int64Bits2Double(uint64_t bits) { return f; } -enum Status s2d_n(const char * buffer, const int len, double * result) { +enum Status s2d_n(const char* buffer, const int len, double* result) { if (len == 0) { return INPUT_TOO_SHORT; } @@ -231,7 +231,7 @@ enum Status s2d_n(const char * buffer, const int len, double * result) { printf("ieee_e2 = %d\n", ieee_e2); printf("shift = %d\n", shift); #endif - + // We need to round up if the exact value is more than 0.5 above the value we computed. That's // equivalent to checking if the last removed bit was 1 and either the value was not just // trailing zeros or the result would otherwise be odd. @@ -252,12 +252,12 @@ enum Status s2d_n(const char * buffer, const int len, double * result) { // Due to how the IEEE represents +/-Infinity, we don't need to check for overflow here. ieee_e2++; } - - uint64_t ieee = (((((uint64_t) signedM) << DOUBLE_EXPONENT_BITS) | (uint64_t)ieee_e2) << DOUBLE_MANTISSA_BITS) | ieee_m2; + + uint64_t ieee = (((((uint64_t) signedM) << DOUBLE_EXPONENT_BITS) | (uint64_t) ieee_e2) << DOUBLE_MANTISSA_BITS) | ieee_m2; *result = int64Bits2Double(ieee); return SUCCESS; } -enum Status s2d(const char * buffer, double * result) { +enum Status s2d(const char* buffer, double* result) { return s2d_n(buffer, strlen(buffer), result); } diff --git a/ryu/s2f.c b/ryu/s2f.c index 93cc9357..e2e29e00 100644 --- a/ryu/s2f.c +++ b/ryu/s2f.c @@ -62,7 +62,7 @@ static inline float int32Bits2Float(uint32_t bits) { return f; } -enum Status s2f_n(const char * buffer, const int len, float * result) { +enum Status s2f_n(const char* buffer, const int len, float* result) { if (len == 0) { return INPUT_TOO_SHORT; } @@ -198,8 +198,7 @@ enum Status s2f_n(const char * buffer, const int len, float * result) { // If e2-e10 < 0, we have actually computed [m10 * 2^(e10 e2) / 5^(-e10)] above, // and we need to check whether 5^(-e10) divides (m10 * 2^(e10-e2)), which is the case iff // pow5(m10 * 2^(e10-e2)) = pow5(m10) >= -e10. - trailingZeros = (e2 < e10 || (e2 - e10 < 32 && multipleOfPowerOf2_32(m10, e2 - e10))) - && multipleOfPowerOf5_32(m10, -e10); + trailingZeros = (e2 < e10 || (e2 - e10 < 32 && multipleOfPowerOf2_32(m10, e2 - e10))) && multipleOfPowerOf5_32(m10, -e10); } #ifdef RYU_DEBUG @@ -248,11 +247,11 @@ enum Status s2f_n(const char * buffer, const int len, float * result) { // Due to how the IEEE represents +/-Infinity, we don't need to check for overflow here. ieee_e2++; } - uint32_t ieee = (((((uint32_t) signedM) << FLOAT_EXPONENT_BITS) | (uint32_t)ieee_e2) << FLOAT_MANTISSA_BITS) | ieee_m2; + uint32_t ieee = (((((uint32_t) signedM) << FLOAT_EXPONENT_BITS) | (uint32_t) ieee_e2) << FLOAT_MANTISSA_BITS) | ieee_m2; *result = int32Bits2Float(ieee); return SUCCESS; } -enum Status s2f(const char * buffer, float * result) { +enum Status s2f(const char* buffer, float* result) { return s2f_n(buffer, strlen(buffer), result); } diff --git a/ryu/tests/common_test.cc b/ryu/tests/common_test.cc index 6dfd7b27..900e436a 100644 --- a/ryu/tests/common_test.cc +++ b/ryu/tests/common_test.cc @@ -90,5 +90,3 @@ TEST(CommonTest, double_to_bits) { EXPECT_EQ(0ull, double_to_bits(0.0)); EXPECT_EQ(0x400921FB54442D18ull, double_to_bits(3.1415926535897932384626433)); } - - diff --git a/ryu/tests/d2fixed_test.cc b/ryu/tests/d2fixed_test.cc index 762be13d..c8201a5b 100644 --- a/ryu/tests/d2fixed_test.cc +++ b/ryu/tests/d2fixed_test.cc @@ -35630,46 +35630,53 @@ static double int64Bits2Double(uint64_t bits) { static double ieeeParts2Double(const bool sign, const uint32_t ieeeExponent, const uint64_t ieeeMantissa) { assert(ieeeExponent <= 2047); - assert(ieeeMantissa <= ((uint64_t)1 << 53) - 1); - return int64Bits2Double(((uint64_t)sign << 63) | ((uint64_t)ieeeExponent << 52) | ieeeMantissa); + assert(ieeeMantissa <= ((uint64_t) 1 << 53) - 1); + return int64Bits2Double(((uint64_t) sign << 63) | ((uint64_t) ieeeExponent << 52) | ieeeMantissa); } -#define EXPECT_FIXED(a, b, c) { char* result = d2fixed(a, b); EXPECT_STREQ(c, result); free(result); } while (0); +#define EXPECT_FIXED(a, b, c) \ + { \ + char* result = d2fixed(a, b); \ + EXPECT_STREQ(c, result); \ + free(result); \ + } \ + while (0) \ + ; TEST(D2fixedTest, Basic) { EXPECT_FIXED( - ieeeParts2Double(false, 1234, 99999), 0, - "3291009114715486435425664845573426149758869524108446525879746560"); + ieeeParts2Double(false, 1234, 99999), 0, + "3291009114715486435425664845573426149758869524108446525879746560"); } TEST(D2fixedTest, Zero) { EXPECT_FIXED(0.0, 4, "0.0000"); - EXPECT_FIXED(0.0, 3, "0.000" ); - EXPECT_FIXED(0.0, 2, "0.00" ); - EXPECT_FIXED(0.0, 1, "0.0" ); - EXPECT_FIXED(0.0, 0, "0" ); + EXPECT_FIXED(0.0, 3, "0.000"); + EXPECT_FIXED(0.0, 2, "0.00"); + EXPECT_FIXED(0.0, 1, "0.0"); + EXPECT_FIXED(0.0, 0, "0"); } TEST(D2fixedTest, MinMax) { EXPECT_FIXED(ieeeParts2Double(false, 0, 1), 1074, - "0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" - "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" - "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" - "000000000000000000000000000000000000000000000000000000049406564584124654417656879286822137" - "236505980261432476442558568250067550727020875186529983636163599237979656469544571773092665" - "671035593979639877479601078187812630071319031140452784581716784898210368871863605699873072" - "305000638740915356498438731247339727316961514003171538539807412623856559117102665855668676" - "818703956031062493194527159149245532930545654440112748012970999954193198940908041656332452" - "475714786901472678015935523861155013480352649347201937902681071074917033322268447533357208" - "324319360923828934583680601060115061698097530783422773183292479049825247307763759272478746" - "560847782037344696995336470179726777175851256605511991315048911014510378627381672509558373" - "89733598993664809941164205702637090279242767544565229087538682506419718265533447265625"); + "0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "000000000000000000000000000000000000000000000000000000049406564584124654417656879286822137" + "236505980261432476442558568250067550727020875186529983636163599237979656469544571773092665" + "671035593979639877479601078187812630071319031140452784581716784898210368871863605699873072" + "305000638740915356498438731247339727316961514003171538539807412623856559117102665855668676" + "818703956031062493194527159149245532930545654440112748012970999954193198940908041656332452" + "475714786901472678015935523861155013480352649347201937902681071074917033322268447533357208" + "324319360923828934583680601060115061698097530783422773183292479049825247307763759272478746" + "560847782037344696995336470179726777175851256605511991315048911014510378627381672509558373" + "89733598993664809941164205702637090279242767544565229087538682506419718265533447265625"); EXPECT_FIXED(ieeeParts2Double(false, 2046, 0xFFFFFFFFFFFFFu), 0, - "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558" - "632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245" - "490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168" - "738177180919299881250404026184124858368"); + "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558" + "632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245" + "490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168" + "738177180919299881250404026184124858368"); } TEST(D2fixedTest, AllPowersOfTen) { @@ -35680,35 +35687,35 @@ TEST(D2fixedTest, AllPowersOfTen) { TEST(D2fixedTest, RoundToEven) { EXPECT_FIXED(0.125, 3, "0.125"); - EXPECT_FIXED(0.125, 2, "0.12" ); + EXPECT_FIXED(0.125, 2, "0.12"); EXPECT_FIXED(0.375, 3, "0.375"); - EXPECT_FIXED(0.375, 2, "0.38" ); + EXPECT_FIXED(0.375, 2, "0.38"); } TEST(D2fixedTest, RoundToEvenInteger) { EXPECT_FIXED(2.5, 1, "2.5"); - EXPECT_FIXED(2.5, 0, "2" ); + EXPECT_FIXED(2.5, 0, "2"); EXPECT_FIXED(3.5, 1, "3.5"); - EXPECT_FIXED(3.5, 0, "4" ); + EXPECT_FIXED(3.5, 0, "4"); } TEST(D2fixedTest, NonRoundToEvenScenarios) { EXPECT_FIXED(0.748046875, 3, "0.748"); - EXPECT_FIXED(0.748046875, 2, "0.75" ); - EXPECT_FIXED(0.748046875, 1, "0.7" ); // 0.75 would round to "0.8", but this is smaller + EXPECT_FIXED(0.748046875, 2, "0.75"); + EXPECT_FIXED(0.748046875, 1, "0.7"); // 0.75 would round to "0.8", but this is smaller EXPECT_FIXED(0.2509765625, 3, "0.251"); - EXPECT_FIXED(0.2509765625, 2, "0.25" ); - EXPECT_FIXED(0.2509765625, 1, "0.3" ); // 0.25 would round to "0.2", but this is larger + EXPECT_FIXED(0.2509765625, 2, "0.25"); + EXPECT_FIXED(0.2509765625, 1, "0.3"); // 0.25 would round to "0.2", but this is larger EXPECT_FIXED(ieeeParts2Double(false, 1021, 1), 54, - "0.250000000000000055511151231257827021181583404541015625"); - EXPECT_FIXED(ieeeParts2Double(false, 1021, 1), 3, - "0.250"); - EXPECT_FIXED(ieeeParts2Double(false, 1021, 1), 2, - "0.25" ); - EXPECT_FIXED(ieeeParts2Double(false, 1021, 1), 1, - "0.3" ); // 0.25 would round to "0.2", but this is larger (again) + "0.250000000000000055511151231257827021181583404541015625"); + EXPECT_FIXED(ieeeParts2Double(false, 1021, 1), 3, + "0.250"); + EXPECT_FIXED(ieeeParts2Double(false, 1021, 1), 2, + "0.25"); + EXPECT_FIXED(ieeeParts2Double(false, 1021, 1), 1, + "0.3"); // 0.25 would round to "0.2", but this is larger (again) } TEST(D2fixedTest, VaryingPrecision) { @@ -35750,82 +35757,82 @@ TEST(D2fixedTest, VaryingPrecision) { EXPECT_FIXED(1729.142857142857, 12, "1729.142857142857"); EXPECT_FIXED(1729.142857142857, 11, "1729.14285714286"); EXPECT_FIXED(1729.142857142857, 10, "1729.1428571429"); - EXPECT_FIXED(1729.142857142857, 9, "1729.142857143"); - EXPECT_FIXED(1729.142857142857, 8, "1729.14285714"); - EXPECT_FIXED(1729.142857142857, 7, "1729.1428571"); - EXPECT_FIXED(1729.142857142857, 6, "1729.142857"); - EXPECT_FIXED(1729.142857142857, 5, "1729.14286"); - EXPECT_FIXED(1729.142857142857, 4, "1729.1429"); - EXPECT_FIXED(1729.142857142857, 3, "1729.143"); - EXPECT_FIXED(1729.142857142857, 2, "1729.14"); - EXPECT_FIXED(1729.142857142857, 1, "1729.1"); - EXPECT_FIXED(1729.142857142857, 0, "1729"); + EXPECT_FIXED(1729.142857142857, 9, "1729.142857143"); + EXPECT_FIXED(1729.142857142857, 8, "1729.14285714"); + EXPECT_FIXED(1729.142857142857, 7, "1729.1428571"); + EXPECT_FIXED(1729.142857142857, 6, "1729.142857"); + EXPECT_FIXED(1729.142857142857, 5, "1729.14286"); + EXPECT_FIXED(1729.142857142857, 4, "1729.1429"); + EXPECT_FIXED(1729.142857142857, 3, "1729.143"); + EXPECT_FIXED(1729.142857142857, 2, "1729.14"); + EXPECT_FIXED(1729.142857142857, 1, "1729.1"); + EXPECT_FIXED(1729.142857142857, 0, "1729"); } TEST(D2fixedTest, Carrying) { - EXPECT_FIXED( 0.0009, 4, "0.0009"); - EXPECT_FIXED( 0.0009, 3, "0.001" ); - EXPECT_FIXED( 0.0029, 4, "0.0029"); - EXPECT_FIXED( 0.0029, 3, "0.003" ); - EXPECT_FIXED( 0.0099, 4, "0.0099"); - EXPECT_FIXED( 0.0099, 3, "0.010" ); - EXPECT_FIXED( 0.0299, 4, "0.0299"); - EXPECT_FIXED( 0.0299, 3, "0.030" ); - EXPECT_FIXED( 0.0999, 4, "0.0999"); - EXPECT_FIXED( 0.0999, 3, "0.100" ); - EXPECT_FIXED( 0.2999, 4, "0.2999"); - EXPECT_FIXED( 0.2999, 3, "0.300" ); - EXPECT_FIXED( 0.9999, 4, "0.9999"); - EXPECT_FIXED( 0.9999, 3, "1.000" ); - EXPECT_FIXED( 2.9999, 4, "2.9999"); - EXPECT_FIXED( 2.9999, 3, "3.000" ); - EXPECT_FIXED( 9.9999, 4, "9.9999"); - EXPECT_FIXED( 9.9999, 3, "10.000" ); - EXPECT_FIXED( 29.9999, 4, "29.9999"); - EXPECT_FIXED( 29.9999, 3, "30.000" ); - EXPECT_FIXED( 99.9999, 4, "99.9999"); - EXPECT_FIXED( 99.9999, 3, "100.000" ); + EXPECT_FIXED(0.0009, 4, "0.0009"); + EXPECT_FIXED(0.0009, 3, "0.001"); + EXPECT_FIXED(0.0029, 4, "0.0029"); + EXPECT_FIXED(0.0029, 3, "0.003"); + EXPECT_FIXED(0.0099, 4, "0.0099"); + EXPECT_FIXED(0.0099, 3, "0.010"); + EXPECT_FIXED(0.0299, 4, "0.0299"); + EXPECT_FIXED(0.0299, 3, "0.030"); + EXPECT_FIXED(0.0999, 4, "0.0999"); + EXPECT_FIXED(0.0999, 3, "0.100"); + EXPECT_FIXED(0.2999, 4, "0.2999"); + EXPECT_FIXED(0.2999, 3, "0.300"); + EXPECT_FIXED(0.9999, 4, "0.9999"); + EXPECT_FIXED(0.9999, 3, "1.000"); + EXPECT_FIXED(2.9999, 4, "2.9999"); + EXPECT_FIXED(2.9999, 3, "3.000"); + EXPECT_FIXED(9.9999, 4, "9.9999"); + EXPECT_FIXED(9.9999, 3, "10.000"); + EXPECT_FIXED(29.9999, 4, "29.9999"); + EXPECT_FIXED(29.9999, 3, "30.000"); + EXPECT_FIXED(99.9999, 4, "99.9999"); + EXPECT_FIXED(99.9999, 3, "100.000"); EXPECT_FIXED(299.9999, 4, "299.9999"); - EXPECT_FIXED(299.9999, 3, "300.000" ); + EXPECT_FIXED(299.9999, 3, "300.000"); - EXPECT_FIXED( 0.09, 2, "0.09"); - EXPECT_FIXED( 0.09, 1, "0.1" ); - EXPECT_FIXED( 0.29, 2, "0.29"); - EXPECT_FIXED( 0.29, 1, "0.3" ); - EXPECT_FIXED( 0.99, 2, "0.99"); - EXPECT_FIXED( 0.99, 1, "1.0" ); - EXPECT_FIXED( 2.99, 2, "2.99"); - EXPECT_FIXED( 2.99, 1, "3.0" ); - EXPECT_FIXED( 9.99, 2, "9.99"); - EXPECT_FIXED( 9.99, 1, "10.0" ); - EXPECT_FIXED( 29.99, 2, "29.99"); - EXPECT_FIXED( 29.99, 1, "30.0" ); - EXPECT_FIXED( 99.99, 2, "99.99"); - EXPECT_FIXED( 99.99, 1, "100.0" ); + EXPECT_FIXED(0.09, 2, "0.09"); + EXPECT_FIXED(0.09, 1, "0.1"); + EXPECT_FIXED(0.29, 2, "0.29"); + EXPECT_FIXED(0.29, 1, "0.3"); + EXPECT_FIXED(0.99, 2, "0.99"); + EXPECT_FIXED(0.99, 1, "1.0"); + EXPECT_FIXED(2.99, 2, "2.99"); + EXPECT_FIXED(2.99, 1, "3.0"); + EXPECT_FIXED(9.99, 2, "9.99"); + EXPECT_FIXED(9.99, 1, "10.0"); + EXPECT_FIXED(29.99, 2, "29.99"); + EXPECT_FIXED(29.99, 1, "30.0"); + EXPECT_FIXED(99.99, 2, "99.99"); + EXPECT_FIXED(99.99, 1, "100.0"); EXPECT_FIXED(299.99, 2, "299.99"); - EXPECT_FIXED(299.99, 1, "300.0" ); + EXPECT_FIXED(299.99, 1, "300.0"); - EXPECT_FIXED( 0.9, 1, "0.9"); - EXPECT_FIXED( 0.9, 0, "1" ); - EXPECT_FIXED( 2.9, 1, "2.9"); - EXPECT_FIXED( 2.9, 0, "3" ); - EXPECT_FIXED( 9.9, 1, "9.9"); - EXPECT_FIXED( 9.9, 0, "10" ); - EXPECT_FIXED( 29.9, 1, "29.9"); - EXPECT_FIXED( 29.9, 0, "30" ); - EXPECT_FIXED( 99.9, 1, "99.9"); - EXPECT_FIXED( 99.9, 0, "100" ); + EXPECT_FIXED(0.9, 1, "0.9"); + EXPECT_FIXED(0.9, 0, "1"); + EXPECT_FIXED(2.9, 1, "2.9"); + EXPECT_FIXED(2.9, 0, "3"); + EXPECT_FIXED(9.9, 1, "9.9"); + EXPECT_FIXED(9.9, 0, "10"); + EXPECT_FIXED(29.9, 1, "29.9"); + EXPECT_FIXED(29.9, 0, "30"); + EXPECT_FIXED(99.9, 1, "99.9"); + EXPECT_FIXED(99.9, 0, "100"); EXPECT_FIXED(299.9, 1, "299.9"); - EXPECT_FIXED(299.9, 0, "300" ); + EXPECT_FIXED(299.9, 0, "300"); } TEST(D2fixedTest, RoundingResultZero) { EXPECT_FIXED(0.004, 3, "0.004"); - EXPECT_FIXED(0.004, 2, "0.00" ); + EXPECT_FIXED(0.004, 2, "0.00"); EXPECT_FIXED(0.4, 1, "0.4"); - EXPECT_FIXED(0.4, 0, "0" ); + EXPECT_FIXED(0.4, 0, "0"); EXPECT_FIXED(0.5, 1, "0.5"); - EXPECT_FIXED(0.5, 0, "0" ); + EXPECT_FIXED(0.5, 0, "0"); } TEST(D2fixedTest, AllBinaryExponents) { @@ -35838,38 +35845,45 @@ TEST(D2fixedTest, Regression) { EXPECT_FIXED(7.018232e-82, 6, "0.000000"); } -#define EXPECT_EXP(a, b, c) { char* result = d2exp(a, b); EXPECT_STREQ(c, result); free(result); } while (0); +#define EXPECT_EXP(a, b, c) \ + { \ + char* result = d2exp(a, b); \ + EXPECT_STREQ(c, result); \ + free(result); \ + } \ + while (0) \ + ; TEST(D2expTest, Basic) { EXPECT_EXP(ieeeParts2Double(false, 1234, 99999), 62, - "3.29100911471548643542566484557342614975886952410844652587974656e+63"); + "3.29100911471548643542566484557342614975886952410844652587974656e+63"); } TEST(D2expTest, Zero) { EXPECT_EXP(0.0, 4, "0.0000e+00"); - EXPECT_EXP(0.0, 3, "0.000e+00" ); - EXPECT_EXP(0.0, 2, "0.00e+00" ); - EXPECT_EXP(0.0, 1, "0.0e+00" ); - EXPECT_EXP(0.0, 0, "0e+00" ); + EXPECT_EXP(0.0, 3, "0.000e+00"); + EXPECT_EXP(0.0, 2, "0.00e+00"); + EXPECT_EXP(0.0, 1, "0.0e+00"); + EXPECT_EXP(0.0, 0, "0e+00"); } TEST(D2expTest, MinMax) { EXPECT_EXP(ieeeParts2Double(false, 0, 1), 750, - "4.9406564584124654417656879286822137236505980261432476442558568250067550727020875186529983" - "636163599237979656469544571773092665671035593979639877479601078187812630071319031140452784" - "581716784898210368871863605699873072305000638740915356498438731247339727316961514003171538" - "539807412623856559117102665855668676818703956031062493194527159149245532930545654440112748" - "012970999954193198940908041656332452475714786901472678015935523861155013480352649347201937" - "902681071074917033322268447533357208324319360923828934583680601060115061698097530783422773" - "183292479049825247307763759272478746560847782037344696995336470179726777175851256605511991" - "315048911014510378627381672509558373897335989936648099411642057026370902792427675445652290" - "87538682506419718265533447265625e-324"); + "4.9406564584124654417656879286822137236505980261432476442558568250067550727020875186529983" + "636163599237979656469544571773092665671035593979639877479601078187812630071319031140452784" + "581716784898210368871863605699873072305000638740915356498438731247339727316961514003171538" + "539807412623856559117102665855668676818703956031062493194527159149245532930545654440112748" + "012970999954193198940908041656332452475714786901472678015935523861155013480352649347201937" + "902681071074917033322268447533357208324319360923828934583680601060115061698097530783422773" + "183292479049825247307763759272478746560847782037344696995336470179726777175851256605511991" + "315048911014510378627381672509558373897335989936648099411642057026370902792427675445652290" + "87538682506419718265533447265625e-324"); EXPECT_EXP(ieeeParts2Double(false, 2046, 0xFFFFFFFFFFFFFu), 308, - "1.7976931348623157081452742373170435679807056752584499659891747680315726078002853876058955" - "863276687817154045895351438246423432132688946418276846754670353751698604991057655128207624" - "549009038932894407586850845513394230458323690322294816580855933212334827479782620414472316" - "8738177180919299881250404026184124858368e+308"); + "1.7976931348623157081452742373170435679807056752584499659891747680315726078002853876058955" + "863276687817154045895351438246423432132688946418276846754670353751698604991057655128207624" + "549009038932894407586850845513394230458323690322294816580855933212334827479782620414472316" + "8738177180919299881250404026184124858368e+308"); } TEST(D2expTest, AllPowersOfTen) { @@ -35880,35 +35894,35 @@ TEST(D2expTest, AllPowersOfTen) { TEST(D2expTest, RoundToEven) { EXPECT_EXP(0.125, 2, "1.25e-01"); - EXPECT_EXP(0.125, 1, "1.2e-01" ); + EXPECT_EXP(0.125, 1, "1.2e-01"); EXPECT_EXP(0.375, 2, "3.75e-01"); - EXPECT_EXP(0.375, 1, "3.8e-01" ); + EXPECT_EXP(0.375, 1, "3.8e-01"); } TEST(D2expTest, RoundToEvenInteger) { EXPECT_EXP(2.5, 1, "2.5e+00"); - EXPECT_EXP(2.5, 0, "2e+00" ); + EXPECT_EXP(2.5, 0, "2e+00"); EXPECT_EXP(3.5, 1, "3.5e+00"); - EXPECT_EXP(3.5, 0, "4e+00" ); + EXPECT_EXP(3.5, 0, "4e+00"); } TEST(D2expTest, NonRoundToEvenScenarios) { EXPECT_EXP(0.748046875, 2, "7.48e-01"); - EXPECT_EXP(0.748046875, 1, "7.5e-01" ); - EXPECT_EXP(0.748046875, 0, "7e-01" ); // 0.75 would round to "8e-01", but this is smaller + EXPECT_EXP(0.748046875, 1, "7.5e-01"); + EXPECT_EXP(0.748046875, 0, "7e-01"); // 0.75 would round to "8e-01", but this is smaller EXPECT_EXP(0.2509765625, 2, "2.51e-01"); - EXPECT_EXP(0.2509765625, 1, "2.5e-01" ); - EXPECT_EXP(0.2509765625, 0, "3e-01" ); // 0.25 would round to "2e-01", but this is larger + EXPECT_EXP(0.2509765625, 1, "2.5e-01"); + EXPECT_EXP(0.2509765625, 0, "3e-01"); // 0.25 would round to "2e-01", but this is larger EXPECT_EXP(ieeeParts2Double(false, 1021, 1), 53, - "2.50000000000000055511151231257827021181583404541015625e-01"); - EXPECT_EXP(ieeeParts2Double(false, 1021, 1), 2, - "2.50e-01"); - EXPECT_EXP(ieeeParts2Double(false, 1021, 1), 1, - "2.5e-01" ); - EXPECT_EXP(ieeeParts2Double(false, 1021, 1), 0, - "3e-01" ); // 0.25 would round to "2e-01", but this is larger (again) + "2.50000000000000055511151231257827021181583404541015625e-01"); + EXPECT_EXP(ieeeParts2Double(false, 1021, 1), 2, + "2.50e-01"); + EXPECT_EXP(ieeeParts2Double(false, 1021, 1), 1, + "2.5e-01"); + EXPECT_EXP(ieeeParts2Double(false, 1021, 1), 0, + "3e-01"); // 0.25 would round to "2e-01", but this is larger (again) } TEST(D2expTest, VaryingPrecision) { @@ -35953,74 +35967,74 @@ TEST(D2expTest, VaryingPrecision) { EXPECT_EXP(1729.142857142857, 12, "1.729142857143e+03"); EXPECT_EXP(1729.142857142857, 11, "1.72914285714e+03"); EXPECT_EXP(1729.142857142857, 10, "1.7291428571e+03"); - EXPECT_EXP(1729.142857142857, 9, "1.729142857e+03"); - EXPECT_EXP(1729.142857142857, 8, "1.72914286e+03"); - EXPECT_EXP(1729.142857142857, 7, "1.7291429e+03"); - EXPECT_EXP(1729.142857142857, 6, "1.729143e+03"); - EXPECT_EXP(1729.142857142857, 5, "1.72914e+03"); - EXPECT_EXP(1729.142857142857, 4, "1.7291e+03"); - EXPECT_EXP(1729.142857142857, 3, "1.729e+03"); - EXPECT_EXP(1729.142857142857, 2, "1.73e+03"); - EXPECT_EXP(1729.142857142857, 1, "1.7e+03"); - EXPECT_EXP(1729.142857142857, 0, "2e+03"); + EXPECT_EXP(1729.142857142857, 9, "1.729142857e+03"); + EXPECT_EXP(1729.142857142857, 8, "1.72914286e+03"); + EXPECT_EXP(1729.142857142857, 7, "1.7291429e+03"); + EXPECT_EXP(1729.142857142857, 6, "1.729143e+03"); + EXPECT_EXP(1729.142857142857, 5, "1.72914e+03"); + EXPECT_EXP(1729.142857142857, 4, "1.7291e+03"); + EXPECT_EXP(1729.142857142857, 3, "1.729e+03"); + EXPECT_EXP(1729.142857142857, 2, "1.73e+03"); + EXPECT_EXP(1729.142857142857, 1, "1.7e+03"); + EXPECT_EXP(1729.142857142857, 0, "2e+03"); } TEST(D2expTest, Carrying) { EXPECT_EXP(2.0009, 4, "2.0009e+00"); - EXPECT_EXP(2.0009, 3, "2.001e+00" ); + EXPECT_EXP(2.0009, 3, "2.001e+00"); EXPECT_EXP(2.0029, 4, "2.0029e+00"); - EXPECT_EXP(2.0029, 3, "2.003e+00" ); + EXPECT_EXP(2.0029, 3, "2.003e+00"); EXPECT_EXP(2.0099, 4, "2.0099e+00"); - EXPECT_EXP(2.0099, 3, "2.010e+00" ); + EXPECT_EXP(2.0099, 3, "2.010e+00"); EXPECT_EXP(2.0299, 4, "2.0299e+00"); - EXPECT_EXP(2.0299, 3, "2.030e+00" ); + EXPECT_EXP(2.0299, 3, "2.030e+00"); EXPECT_EXP(2.0999, 4, "2.0999e+00"); - EXPECT_EXP(2.0999, 3, "2.100e+00" ); + EXPECT_EXP(2.0999, 3, "2.100e+00"); EXPECT_EXP(2.2999, 4, "2.2999e+00"); - EXPECT_EXP(2.2999, 3, "2.300e+00" ); + EXPECT_EXP(2.2999, 3, "2.300e+00"); EXPECT_EXP(2.9999, 4, "2.9999e+00"); - EXPECT_EXP(2.9999, 3, "3.000e+00" ); + EXPECT_EXP(2.9999, 3, "3.000e+00"); EXPECT_EXP(9.9999, 4, "9.9999e+00"); - EXPECT_EXP(9.9999, 3, "1.000e+01" ); + EXPECT_EXP(9.9999, 3, "1.000e+01"); EXPECT_EXP(2.09, 2, "2.09e+00"); - EXPECT_EXP(2.09, 1, "2.1e+00" ); + EXPECT_EXP(2.09, 1, "2.1e+00"); EXPECT_EXP(2.29, 2, "2.29e+00"); - EXPECT_EXP(2.29, 1, "2.3e+00" ); + EXPECT_EXP(2.29, 1, "2.3e+00"); EXPECT_EXP(2.99, 2, "2.99e+00"); - EXPECT_EXP(2.99, 1, "3.0e+00" ); + EXPECT_EXP(2.99, 1, "3.0e+00"); EXPECT_EXP(9.99, 2, "9.99e+00"); - EXPECT_EXP(9.99, 1, "1.0e+01" ); + EXPECT_EXP(9.99, 1, "1.0e+01"); EXPECT_EXP(2.9, 1, "2.9e+00"); - EXPECT_EXP(2.9, 0, "3e+00" ); + EXPECT_EXP(2.9, 0, "3e+00"); EXPECT_EXP(9.9, 1, "9.9e+00"); - EXPECT_EXP(9.9, 0, "1e+01" ); + EXPECT_EXP(9.9, 0, "1e+01"); } TEST(D2expTest, Exponents) { EXPECT_EXP(9.99e-100, 2, "9.99e-100"); - EXPECT_EXP(9.99e-99 , 2, "9.99e-99" ); - EXPECT_EXP(9.99e-10 , 2, "9.99e-10" ); - EXPECT_EXP(9.99e-09 , 2, "9.99e-09" ); - EXPECT_EXP(9.99e-01 , 2, "9.99e-01" ); - EXPECT_EXP(9.99e+00 , 2, "9.99e+00" ); - EXPECT_EXP(9.99e+01 , 2, "9.99e+01" ); - EXPECT_EXP(9.99e+09 , 2, "9.99e+09" ); - EXPECT_EXP(9.99e+10 , 2, "9.99e+10" ); - EXPECT_EXP(9.99e+99 , 2, "9.99e+99" ); + EXPECT_EXP(9.99e-99, 2, "9.99e-99"); + EXPECT_EXP(9.99e-10, 2, "9.99e-10"); + EXPECT_EXP(9.99e-09, 2, "9.99e-09"); + EXPECT_EXP(9.99e-01, 2, "9.99e-01"); + EXPECT_EXP(9.99e+00, 2, "9.99e+00"); + EXPECT_EXP(9.99e+01, 2, "9.99e+01"); + EXPECT_EXP(9.99e+09, 2, "9.99e+09"); + EXPECT_EXP(9.99e+10, 2, "9.99e+10"); + EXPECT_EXP(9.99e+99, 2, "9.99e+99"); EXPECT_EXP(9.99e+100, 2, "9.99e+100"); - EXPECT_EXP(9.99e-100, 1, "1.0e-99" ); - EXPECT_EXP(9.99e-99 , 1, "1.0e-98" ); - EXPECT_EXP(9.99e-10 , 1, "1.0e-09" ); - EXPECT_EXP(9.99e-09 , 1, "1.0e-08" ); - EXPECT_EXP(9.99e-01 , 1, "1.0e+00" ); - EXPECT_EXP(9.99e+00 , 1, "1.0e+01" ); - EXPECT_EXP(9.99e+01 , 1, "1.0e+02" ); - EXPECT_EXP(9.99e+09 , 1, "1.0e+10" ); - EXPECT_EXP(9.99e+10 , 1, "1.0e+11" ); - EXPECT_EXP(9.99e+99 , 1, "1.0e+100"); + EXPECT_EXP(9.99e-100, 1, "1.0e-99"); + EXPECT_EXP(9.99e-99, 1, "1.0e-98"); + EXPECT_EXP(9.99e-10, 1, "1.0e-09"); + EXPECT_EXP(9.99e-09, 1, "1.0e-08"); + EXPECT_EXP(9.99e-01, 1, "1.0e+00"); + EXPECT_EXP(9.99e+00, 1, "1.0e+01"); + EXPECT_EXP(9.99e+01, 1, "1.0e+02"); + EXPECT_EXP(9.99e+09, 1, "1.0e+10"); + EXPECT_EXP(9.99e+10, 1, "1.0e+11"); + EXPECT_EXP(9.99e+99, 1, "1.0e+100"); EXPECT_EXP(9.99e+100, 1, "1.0e+101"); } @@ -36032,10 +36046,10 @@ TEST(D2expTest, AllBinaryExponents) { TEST(D2expTest, PrintDecimalPoint) { // These values exercise each codepath. - EXPECT_EXP(1e+54, 0, "1e+54" ); + EXPECT_EXP(1e+54, 0, "1e+54"); EXPECT_EXP(1e+54, 1, "1.0e+54"); - EXPECT_EXP(1e-63, 0, "1e-63" ); + EXPECT_EXP(1e-63, 0, "1e-63"); EXPECT_EXP(1e-63, 1, "1.0e-63"); - EXPECT_EXP(1e+83, 0, "1e+83" ); + EXPECT_EXP(1e+83, 0, "1e+83"); EXPECT_EXP(1e+83, 1, "1.0e+83"); } diff --git a/ryu/tests/d2s_intrinsics_test.cc b/ryu/tests/d2s_intrinsics_test.cc index 8100ac75..78ef4b99 100644 --- a/ryu/tests/d2s_intrinsics_test.cc +++ b/ryu/tests/d2s_intrinsics_test.cc @@ -62,22 +62,22 @@ TEST(D2sIntrinsicsTest, pow5Factor) { EXPECT_EQ(0u, pow5Factor(18ull)); EXPECT_EQ(1u, pow5Factor(20ull)); - EXPECT_EQ(2u, pow5Factor(5*5ull)); - EXPECT_EQ(3u, pow5Factor(5*5*5ull)); - EXPECT_EQ(4u, pow5Factor(5*5*5*5ull)); - EXPECT_EQ(5u, pow5Factor(5*5*5*5*5ull)); - EXPECT_EQ(6u, pow5Factor(5*5*5*5*5*5ull)); - EXPECT_EQ(7u, pow5Factor(5*5*5*5*5*5*5ull)); - EXPECT_EQ(8u, pow5Factor(5*5*5*5*5*5*5*5ull)); - EXPECT_EQ(9u, pow5Factor(5*5*5*5*5*5*5*5*5ull)); - EXPECT_EQ(10u, pow5Factor(5*5*5*5*5*5*5*5*5*5ull)); + EXPECT_EQ(2u, pow5Factor(5 * 5ull)); + EXPECT_EQ(3u, pow5Factor(5 * 5 * 5ull)); + EXPECT_EQ(4u, pow5Factor(5 * 5 * 5 * 5ull)); + EXPECT_EQ(5u, pow5Factor(5 * 5 * 5 * 5 * 5ull)); + EXPECT_EQ(6u, pow5Factor(5 * 5 * 5 * 5 * 5 * 5ull)); + EXPECT_EQ(7u, pow5Factor(5 * 5 * 5 * 5 * 5 * 5 * 5ull)); + EXPECT_EQ(8u, pow5Factor(5 * 5 * 5 * 5 * 5 * 5 * 5 * 5ull)); + EXPECT_EQ(9u, pow5Factor(5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5ull)); + EXPECT_EQ(10u, pow5Factor(5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5ull)); EXPECT_EQ(0u, pow5Factor(42ull)); - EXPECT_EQ(1u, pow5Factor(42*5ull)); - EXPECT_EQ(2u, pow5Factor(42*5*5ull)); - EXPECT_EQ(3u, pow5Factor(42*5*5*5ull)); - EXPECT_EQ(4u, pow5Factor(42*5*5*5*5ull)); - EXPECT_EQ(5u, pow5Factor(42*5*5*5*5*5ull)); + EXPECT_EQ(1u, pow5Factor(42 * 5ull)); + EXPECT_EQ(2u, pow5Factor(42 * 5 * 5ull)); + EXPECT_EQ(3u, pow5Factor(42 * 5 * 5 * 5ull)); + EXPECT_EQ(4u, pow5Factor(42 * 5 * 5 * 5 * 5ull)); + EXPECT_EQ(5u, pow5Factor(42 * 5 * 5 * 5 * 5 * 5ull)); EXPECT_EQ(27u, pow5Factor(7450580596923828125ull)); // 5^27, largest power of 5 < 2^64. EXPECT_EQ(1u, pow5Factor(18446744073709551615ull)); // 2^64 - 1, largest multiple of 5 < 2^64. diff --git a/ryu/tests/d2s_table_test.cc b/ryu/tests/d2s_table_test.cc index d8183cb6..aaafcec3 100644 --- a/ryu/tests/d2s_table_test.cc +++ b/ryu/tests/d2s_table_test.cc @@ -41,4 +41,3 @@ TEST(D2sTableTest, double_computeInvPow5) { EXPECT_EQ(m[1], DOUBLE_POW5_INV_SPLIT[i][1]); } } - diff --git a/ryu/tests/d2s_test.cc b/ryu/tests/d2s_test.cc index 0bf6169b..79cbf002 100644 --- a/ryu/tests/d2s_test.cc +++ b/ryu/tests/d2s_test.cc @@ -28,11 +28,18 @@ static double int64Bits2Double(uint64_t bits) { static double ieeeParts2Double(const bool sign, const uint32_t ieeeExponent, const uint64_t ieeeMantissa) { assert(ieeeExponent <= 2047); - assert(ieeeMantissa <= ((uint64_t)1 << 53) - 1); - return int64Bits2Double(((uint64_t)sign << 63) | ((uint64_t)ieeeExponent << 52) | ieeeMantissa); + assert(ieeeMantissa <= ((uint64_t) 1 << 53) - 1); + return int64Bits2Double(((uint64_t) sign << 63) | ((uint64_t) ieeeExponent << 52) | ieeeMantissa); } -#define ASSERT_D2S(a, b) { char* result = d2s(b); ASSERT_STREQ(a, result); free(result); } while (0); +#define ASSERT_D2S(a, b) \ + { \ + char* result = d2s(b); \ + ASSERT_STREQ(a, result); \ + free(result); \ + } \ + while (0) \ + ; TEST(D2sTest, Basic) { ASSERT_D2S("0E0", 0.0); @@ -106,7 +113,7 @@ TEST(D2sTest, OutputLength) { // Test min, max shift values in shiftright128 TEST(D2sTest, MinMaxShift) { - const uint64_t maxMantissa = ((uint64_t)1 << 53) - 1; + const uint64_t maxMantissa = ((uint64_t) 1 << 53) - 1; // 32-bit opt-size=0: 49 <= dist <= 50 // 32-bit opt-size=1: 30 <= dist <= 50 diff --git a/ryu/tests/f2s_test.cc b/ryu/tests/f2s_test.cc index da4e9dc5..a93781d5 100644 --- a/ryu/tests/f2s_test.cc +++ b/ryu/tests/f2s_test.cc @@ -26,7 +26,14 @@ static float int32Bits2Float(uint32_t bits) { return f; } -#define ASSERT_F2S(a, b) { char* result = f2s(b); ASSERT_STREQ(a, result); free(result); } while (0); +#define ASSERT_F2S(a, b) \ + { \ + char* result = f2s(b); \ + ASSERT_STREQ(a, result); \ + free(result); \ + } \ + while (0) \ + ; TEST(F2sTest, Basic) { ASSERT_F2S("0E0", 0.0); diff --git a/ryu/tests/generic_128_test.cc b/ryu/tests/generic_128_test.cc index ef4282c6..bc9be8fb 100644 --- a/ryu/tests/generic_128_test.cc +++ b/ryu/tests/generic_128_test.cc @@ -23,37 +23,33 @@ // We only test a few entries - we could test the full table instead, but should we? static uint32_t EXACT_POW5_IDS[10] = { - 1, 10, 55, 56, 300, 1000, 2345, 3210, 4968 - 3, 4968 - 1 -}; + 1, 10, 55, 56, 300, 1000, 2345, 3210, 4968 - 3, 4968 - 1}; static uint64_t EXACT_POW5[10][4] = { - { 0u, 0u, 0u, 90071992547409920u }, - { 0u, 0u, 0u, 83886080000000000u }, - { 0u, 15708555500268290048u, 14699724349295723422u, 117549435082228750u }, - { 0u, 5206161169240293376u, 4575641699882439235u, 73468396926392969u }, - { 2042133660145364371u, 9702060195405861314u, 6467325284806654637u, 107597969523956154u }, - { 15128847313296546509u, 11916317791371073891u, 788593023170869613u, 137108429762886488u }, - { 10998857860460266920u, 858411415306315808u, 12732466392391605111u, 136471991906002539u }, - { 5404652432687674341u, 18039986361557197657u, 2228774284272261859u, 94370442653226447u }, - { 15313487127299642753u, 9780770376910163681u, 15213531439620567348u, 93317108016191349u }, - { 7928436552078881485u, 723697829319983520u, 932817143438521969u, 72903990637649492u } -}; + {0u, 0u, 0u, 90071992547409920u}, + {0u, 0u, 0u, 83886080000000000u}, + {0u, 15708555500268290048u, 14699724349295723422u, 117549435082228750u}, + {0u, 5206161169240293376u, 4575641699882439235u, 73468396926392969u}, + {2042133660145364371u, 9702060195405861314u, 6467325284806654637u, 107597969523956154u}, + {15128847313296546509u, 11916317791371073891u, 788593023170869613u, 137108429762886488u}, + {10998857860460266920u, 858411415306315808u, 12732466392391605111u, 136471991906002539u}, + {5404652432687674341u, 18039986361557197657u, 2228774284272261859u, 94370442653226447u}, + {15313487127299642753u, 9780770376910163681u, 15213531439620567348u, 93317108016191349u}, + {7928436552078881485u, 723697829319983520u, 932817143438521969u, 72903990637649492u}}; static uint32_t EXACT_INV_POW5_IDS[9] = { - 10, 55, 56, 300, 1000, 2345, 3210, 4897 - 3, 4897 - 1 -}; + 10, 55, 56, 300, 1000, 2345, 3210, 4897 - 3, 4897 - 1}; static uint64_t EXACT_INV_POW5[10][4] = { - { 13362655651931650467u, 3917988799323120213u, 9037289074543890586u, 123794003928538027u }, - { 983662216614650042u, 15516934687640009097u, 8839031818921249472u, 88342353238919216u }, - { 1573859546583440066u, 2691002611772552616u, 6763753280790178510u, 141347765182270746u }, - { 1607391579053635167u, 943946735193622172u, 10726301928680150504u, 96512915280967053u }, - { 7238603269427345471u, 17319296798264127544u, 14852913523241959878u, 75740009093741608u }, - { 2734564866961569744u, 13277212449690943834u, 17231454566843360565u, 76093223027199785u }, - { 5348945211244460332u, 14119936934335594321u, 15647307321253222579u, 110040743956546595u }, - { 2848579222248330872u, 15087265905644220040u, 4449739884766224405u, 100774177495370196u }, - { 1432572115632717323u, 9719393440895634811u, 3482057763655621045u, 128990947194073851u } -}; + {13362655651931650467u, 3917988799323120213u, 9037289074543890586u, 123794003928538027u}, + {983662216614650042u, 15516934687640009097u, 8839031818921249472u, 88342353238919216u}, + {1573859546583440066u, 2691002611772552616u, 6763753280790178510u, 141347765182270746u}, + {1607391579053635167u, 943946735193622172u, 10726301928680150504u, 96512915280967053u}, + {7238603269427345471u, 17319296798264127544u, 14852913523241959878u, 75740009093741608u}, + {2734564866961569744u, 13277212449690943834u, 17231454566843360565u, 76093223027199785u}, + {5348945211244460332u, 14119936934335594321u, 15647307321253222579u, 110040743956546595u}, + {2848579222248330872u, 15087265905644220040u, 4449739884766224405u, 100774177495370196u}, + {1432572115632717323u, 9719393440895634811u, 3482057763655621045u, 128990947194073851u}}; TEST(Generic128Test, generic_computePow5) { for (int i = 0; i < 10; i++) { @@ -78,35 +74,35 @@ TEST(Generic128Test, generic_computeInvPow5) { } TEST(Generic128Test, multipleOfPowerOf5) { - ASSERT_EQ(true, multipleOfPowerOf5(1, 0)); + ASSERT_EQ(true, multipleOfPowerOf5(1, 0)); ASSERT_EQ(false, multipleOfPowerOf5(1, 1)); - ASSERT_EQ(true, multipleOfPowerOf5(5, 1)); - ASSERT_EQ(true, multipleOfPowerOf5(25, 2)); - ASSERT_EQ(true, multipleOfPowerOf5(75, 2)); - ASSERT_EQ(true, multipleOfPowerOf5(50, 2)); + ASSERT_EQ(true, multipleOfPowerOf5(5, 1)); + ASSERT_EQ(true, multipleOfPowerOf5(25, 2)); + ASSERT_EQ(true, multipleOfPowerOf5(75, 2)); + ASSERT_EQ(true, multipleOfPowerOf5(50, 2)); ASSERT_EQ(false, multipleOfPowerOf5(51, 2)); ASSERT_EQ(false, multipleOfPowerOf5(75, 4)); } TEST(Generic128Test, multipleOfPowerOf2) { - ASSERT_EQ(true, multipleOfPowerOf5(1, 0)); + ASSERT_EQ(true, multipleOfPowerOf5(1, 0)); ASSERT_EQ(false, multipleOfPowerOf5(1, 1)); - ASSERT_EQ(true, multipleOfPowerOf2(2, 1)); - ASSERT_EQ(true, multipleOfPowerOf2(4, 2)); - ASSERT_EQ(true, multipleOfPowerOf2(8, 2)); - ASSERT_EQ(true, multipleOfPowerOf2(12, 2)); + ASSERT_EQ(true, multipleOfPowerOf2(2, 1)); + ASSERT_EQ(true, multipleOfPowerOf2(4, 2)); + ASSERT_EQ(true, multipleOfPowerOf2(8, 2)); + ASSERT_EQ(true, multipleOfPowerOf2(12, 2)); ASSERT_EQ(false, multipleOfPowerOf2(13, 2)); ASSERT_EQ(false, multipleOfPowerOf2(8, 4)); } TEST(Generic128Test, mulShift) { - uint64_t m[4] = { 0, 0, 2, 0 }; + uint64_t m[4] = {0, 0, 2, 0}; ASSERT_EQ(1u, mulShift(1, m, 129)); ASSERT_EQ(12345u, mulShift(12345, m, 129)); } TEST(Generic128Test, mulShiftHuge) { - uint64_t m[4] = { 0, 0, 8, 0 }; + uint64_t m[4] = {0, 0, 8, 0}; uint128_t f = (((uint128_t) 123) << 64) | 321; ASSERT_EQ(f, mulShift(f, m, 131)); } @@ -165,7 +161,14 @@ static char* f2s(float f) { return result; } -#define ASSERT_F2S(a, b) { char* result = f2s(b); ASSERT_STREQ(a, result); free(result); } while (0); +#define ASSERT_F2S(a, b) \ + { \ + char* result = f2s(b); \ + ASSERT_STREQ(a, result); \ + free(result); \ + } \ + while (0) \ + ; static float int32Bits2Float(uint32_t bits) { float f; @@ -254,7 +257,14 @@ static char* d2s(double d) { return result; } -#define ASSERT_D2S(a, b) { char* result = d2s(b); ASSERT_STREQ(a, result); free(result); } while (0); +#define ASSERT_D2S(a, b) \ + { \ + char* result = d2s(b); \ + ASSERT_STREQ(a, result); \ + free(result); \ + } \ + while (0) \ + ; static double int64Bits2Double(uint64_t bits) { double f; @@ -320,7 +330,14 @@ static char* l2s(long double d) { return result; } -#define ASSERT_L2S(a, b) { char* result = l2s(b); ASSERT_STREQ(a, result); free(result); } while (0); +#define ASSERT_L2S(a, b) \ + { \ + char* result = l2s(b); \ + ASSERT_STREQ(a, result); \ + free(result); \ + } \ + while (0) \ + ; TEST(Generic128Test, long_double_to_fd128) { if (sizeof(long double) != 10) { diff --git a/ryu/tests/s2d_test.cc b/ryu/tests/s2d_test.cc index be3a549d..1ebcce32 100644 --- a/ryu/tests/s2d_test.cc +++ b/ryu/tests/s2d_test.cc @@ -20,7 +20,14 @@ #include "ryu/ryu_parse.h" #include "third_party/gtest/gtest.h" -#define EXPECT_S2D(a, b) { double value; EXPECT_EQ(SUCCESS, s2d(b, &value)); EXPECT_EQ(a, value); } while (0); +#define EXPECT_S2D(a, b) \ + { \ + double value; \ + EXPECT_EQ(SUCCESS, s2d(b, &value)); \ + EXPECT_EQ(a, value); \ + } \ + while (0) \ + ; TEST(S2dTest, BadInput) { double value; diff --git a/ryu/tests/s2f_test.cc b/ryu/tests/s2f_test.cc index 36762fc8..29fd228b 100644 --- a/ryu/tests/s2f_test.cc +++ b/ryu/tests/s2f_test.cc @@ -20,7 +20,12 @@ #include "ryu/ryu_parse.h" #include "third_party/gtest/gtest.h" -#define EXPECT_S2F(a, b) do { float value; EXPECT_EQ(SUCCESS, s2f(b, &value)); EXPECT_EQ(a, value); } while (0); +#define EXPECT_S2F(a, b) \ + do { \ + float value; \ + EXPECT_EQ(SUCCESS, s2f(b, &value)); \ + EXPECT_EQ(a, value); \ + } while (0); TEST(S2fTest, Basic) { EXPECT_S2F(0.0f, "0");