Skip to content

Commit

Permalink
Fixes from merge request review
Browse files Browse the repository at this point in the history
Explicit base template parameter on num_digits in set_precision function.
Also change all instances of `std::to_char` to the correct spelling
`std::to_chars`.
  • Loading branch information
CrustyAuklet committed May 2, 2024
1 parent dea6d07 commit 4096a6c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ set(SNITCH_WITH_MULTITHREADING ON CACHE BOOL "Make the testing fram
set(SNITCH_WITH_TIMINGS ON CACHE BOOL "Measure the time taken by each test case -- disable to speed up tests.")
set(SNITCH_WITH_SHORTHAND_MACROS ON CACHE BOOL "Use short names for test macros -- disable if this causes conflicts.")
set(SNITCH_CONSTEXPR_FLOAT_USE_BITCAST ON CACHE BOOL "Use std::bit_cast if available to implement exact constexpr float-to-string conversion.")
set(SNITCH_APPEND_TO_CHARS ON CACHE BOOL "Use std::to_char for string conversions -- disable for greater compatability with a slight performance cost.")
set(SNITCH_APPEND_TO_CHARS ON CACHE BOOL "Use std::to_chars for string conversions -- disable for greater compatability with a slight performance cost.")
set(SNITCH_DEFAULT_WITH_COLOR ON CACHE BOOL "Enable terminal colors by default -- can also be controlled by command line interface.")
set(SNITCH_DECOMPOSE_SUCCESSFUL_ASSERTIONS OFF CACHE BOOL "Enable expression decomposition even for successful assertions -- more expensive.")
set(SNITCH_WITH_ALL_REPORTERS ON CACHE BOOL "Allow all built-in reporters to be selected from the command line -- disable for faster compilation.")
Expand Down
2 changes: 1 addition & 1 deletion include/snitch/snitch_append.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ set_precision(signed_fixed_data fd, std::size_t p) noexcept {
base_digits -= 1u;
} else {
fd.digits = round_half_to_even(fd.digits, only_zero);
base_digits = num_digits(static_cast<large_uint_t>(fd.digits));
base_digits = num_digits<10>(static_cast<large_uint_t>(fd.digits));
}

fd.exponent += 1;
Expand Down
2 changes: 1 addition & 1 deletion meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ option('with_multithreading' ,type: 'boolean', value: true, descript
option('with_timings' ,type: 'boolean' ,value: true, description: 'Measure the time taken by each test case -- disable to speed up tests.')
option('with_shorthand_macros' ,type: 'boolean' ,value: true, description: 'Use short names for test macros -- disable if this causes conflicts.')
option('constexpr_float_use_bitcast' ,type: 'boolean' ,value: true, description: 'Use std::bit_cast if available to implement exact constexpr float-to-string conversion.')
option('snitch_append_to_chars' ,type: 'boolean' ,value: true, description: 'Use std::to_char for string conversions -- disable for greater compatability with a slight performance cost.')
option('snitch_append_to_chars' ,type: 'boolean' ,value: true, description: 'Use std::to_chars for string conversions -- disable for greater compatability with a slight performance cost.')
option('default_with_color' ,type: 'boolean' ,value: true, description: 'Enable terminal colors by default -- can also be controlled by command line interface.')
option('decompose_successful_assertions' ,type: 'boolean' ,value: true, description: 'Enable expression decomposition even for successful assertions -- more expensive.')
option('with_all_reporters' ,type: 'boolean' ,value: true, description: 'Allow all built-in reporters to be selected from the command line -- disable for faster compilation.')
Expand Down
10 changes: 5 additions & 5 deletions tests/runtime_tests/string_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ TEST_CASE("append ints", "[utility]") {
TEST_CASE("append floats", "[utility]") {
using ae = append_test::append_expected;
#if !SNITCH_CONSTEXPR_FLOAT_USE_BITCAST && SNITCH_APPEND_TO_CHARS
// answers will be different only if no bitcast AND we do have runtime to_char
// answers will be different only if no bitcast AND we do have runtime to_chars
// otherwise append_constexpr will be used at runtime
using aed = append_test::append_expected_diff;
#endif
Expand All @@ -356,14 +356,14 @@ TEST_CASE("append floats", "[utility]") {

CONSTEXPR_CHECK(a(0.0f) == ae{"0.000000e+00"sv, true});
#if SNITCH_CONSTEXPR_FLOAT_USE_BITCAST
// std::bit_cast is enabled, and will match the output of std::to_char if used at runtime
// std::bit_cast is enabled, and will match the output of std::to_chars if used at runtime
CONSTEXPR_CHECK(a(-0.0f) == ae{"-0.000000e+00"sv, true});
#elif SNITCH_APPEND_TO_CHARS
// Without std::bit_cast (or C++23), we are unable to tell the difference between -0.0f and
// +0.0f in constexpr expressions. Therefore -0.0f in constexpr gets displayed as +0.0f.
CONSTEXPR_CHECK(a(-0.0f) == aed{{"0.000000e+00"sv, true}, {"-0.000000e+00"sv, true}});
#else
// No std::bit_cast, but also no std::to_char. append_constexpr will be used
// No std::bit_cast, but also no std::to_chars. append_constexpr will be used
// for runtime and match the compile time results
CONSTEXPR_CHECK(a(-0.0f) == ae{"0.000000e+00"sv, true});
#endif
Expand Down Expand Up @@ -472,15 +472,15 @@ TEST_CASE("append doubles", "[utility]") {

CONSTEXPR_CHECK(a(0.0) == ae{"0.000000000000000e+00"sv, true});
#if SNITCH_CONSTEXPR_FLOAT_USE_BITCAST
// std::bit_cast is enabled, and will match the output of std::to_char if used at runtime
// std::bit_cast is enabled, and will match the output of std::to_chars if used at runtime
CONSTEXPR_CHECK(a(-0.0) == ae{"-0.000000000000000e+00"sv, true});
#elif SNITCH_APPEND_TO_CHARS
// Without std::bit_cast (or C++23), we are unable to tell the difference between -0.0f and
// +0.0f in constexpr expressions. Therefore -0.0f in constexpr gets displayed as +0.0f.
CONSTEXPR_CHECK(
a(-0.0) == aed{{"0.000000000000000e+00"sv, true}, {"-0.000000000000000e+00"sv, true}});
#else
// No std::bit_cast, but also no std::to_char. append_constexpr will be used for
// No std::bit_cast, but also no std::to_chars. append_constexpr will be used for
// runtime and match the compile time results
CONSTEXPR_CHECK(a(-0.0) == ae{"0.000000000000000e+00"sv, true});
#endif
Expand Down

0 comments on commit 4096a6c

Please sign in to comment.