Fix floating point conversions

This commit is contained in:
Krystian Stasiowski
2020-02-02 22:35:14 -05:00
parent f73658f09f
commit eea293034c
2 changed files with 42 additions and 15 deletions

View File

@ -190,7 +190,8 @@ jobs:
- { os: "linux", env: [ "B2_TOOLSET=clang-6.0", "B2_CXXSTD=14,17" ], addons: *clang-6 } - { os: "linux", env: [ "B2_TOOLSET=clang-6.0", "B2_CXXSTD=14,17" ], addons: *clang-6 }
- { os: "linux", env: [ "B2_TOOLSET=clang-7", "B2_CXXSTD=17" ], addons: *clang-7 } - { os: "linux", env: [ "B2_TOOLSET=clang-7", "B2_CXXSTD=17" ], addons: *clang-7 }
- os: "linux" - os: "linux"
env: ["B2_TOOLSET=clang-9", "B2_CXXSTD=17", "B2_CXXFLAGS=-stdlib=libstdc++"] env: ["B2_TOOLSET=clang-9", "B2_CXXSTD=11,14,17"]
addons:
apt: apt:
sources: sources:
- ubuntu-toolchain-r-test - ubuntu-toolchain-r-test
@ -198,7 +199,9 @@ jobs:
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
packages: packages:
- clang-9 - clang-9
- libc6-dbg
- libc++-dev
- libstdc++-8-dev
- { os: "linux", env: [ "B2_TOOLSET=clang-8", "B2_CXXSTD=17" ], addons: *clang-8 } - { os: "linux", env: [ "B2_TOOLSET=clang-8", "B2_CXXSTD=17" ], addons: *clang-8 }
# libc++ # libc++

View File

@ -257,11 +257,11 @@ public:
term_impl() noexcept { } term_impl() noexcept { }
private: private:
static constexpr CharT null_{}; static constexpr const CharT null_{};
}; };
template<typename CharT, typename Traits> template<typename CharT, typename Traits>
constexpr CharT static_string_base_zero<0, CharT, Traits>::null_; constexpr const CharT static_string_base_zero<0, CharT, Traits>::null_;
#ifdef BOOST_STATIC_STRING_NULL_OPTIMIZATION #ifdef BOOST_STATIC_STRING_NULL_OPTIMIZATION
// Optimization for storing the size in the last element // Optimization for storing the size in the last element
@ -502,10 +502,22 @@ to_static_wstring_int_impl(Integer value) noexcept
return static_wstring<N>(digits_begin, std::distance(digits_begin, digits_end)); return static_wstring<N>(digits_begin, std::distance(digits_begin, digits_end));
} }
template<std::size_t N, typename Floating> template<std::size_t N>
inline inline
static_string<N> static_string<N>
to_static_string_float_impl(Floating value) noexcept to_static_string_float_impl(double value) noexcept
{
// extra one needed for null terminator
char buffer[N + 1];
std::sprintf(buffer, "%f", value);
// this will not throw
return static_string<N>(buffer);
}
template<std::size_t N>
inline
static_string<N>
to_static_string_float_impl(long double value) noexcept
{ {
// extra one needed for null terminator // extra one needed for null terminator
char buffer[N + 1]; char buffer[N + 1];
@ -514,10 +526,22 @@ to_static_string_float_impl(Floating value) noexcept
return static_string<N>(buffer); return static_string<N>(buffer);
} }
template<std::size_t N, typename Floating> template<std::size_t N>
inline inline
static_wstring<N> static_wstring<N>
to_static_wstring_float_impl(Floating value) noexcept to_static_wstring_float_impl(double value) noexcept
{
// extra one needed for null terminator
wchar_t buffer[N + 1];
std::swprintf(buffer, N + 1, L"%f", value);
// this will not throw
return static_wstring<N>(buffer);
}
template<std::size_t N>
inline
static_wstring<N>
to_static_wstring_float_impl(long double value) noexcept
{ {
// extra one needed for null terminator // extra one needed for null terminator
wchar_t buffer[N + 1]; wchar_t buffer[N + 1];