Skip to content

Commit 6d23474

Browse files
author
John McFarlane
committed
Fix incorrect use of exponent as fractional digits
- Only true when Radis is binary (2) - Add test of to_chars_static of elastic_scaled_integer
1 parent fba5a8e commit 6d23474

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

include/cnl/_impl/scaled_integer/num_traits.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ namespace cnl {
7171
// scaled_integer specializations of scaled_integer-specific templates
7272

7373
namespace _impl {
74-
template<typename Rep, int Exponent, int Radix>
75-
struct fractional_digits<scaled_integer<Rep, power<Exponent, Radix>>> : std::integral_constant<int, -Exponent> {
74+
template<typename Rep, int Exponent>
75+
struct fractional_digits<scaled_integer<Rep, power<Exponent, 2>>> : std::integral_constant<int, -Exponent> {
7676
};
7777
}
7878
}

include/cnl/_impl/scaled_integer/to_chars_capacity.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ namespace cnl::_impl {
5858
constexpr auto radix{Scale::radix};
5959

6060
// This number is a little pessemistic in the case that radix != 2.
61-
auto const fractional_digits =
62-
std::max(cnl::_impl::fractional_digits_v<type>, 0);
61+
auto const fractional_digits = std::max(-exponent, 0);
6362

6463
auto const sign_chars = static_cast<int>(cnl::numbers::signedness_v<type>);
6564
auto const num_significant_integer_bits{cnl::digits_v<type> - fractional_digits};

0 commit comments

Comments
 (0)