Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 13 additions & 87 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ env:
GIT_FETCH_JOBS: 8
NET_RETRY_COUNT: 5
DEFAULT_BUILD_VARIANT: debug,release
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true

jobs:
posix:
Expand All @@ -34,34 +33,6 @@ jobs:
fail-fast: false
matrix:
include:
- toolset: gcc-8
cxxstd: "03,11,14,17,2a"
address_model: 32,64
os: ubuntu-latest
container: ubuntu:18.04
install:
- g++-8-multilib
- toolset: gcc-9
cxxstd: "03,11,14,17,2a"
address_model: 32,64
os: ubuntu-latest
container: ubuntu:20.04
install:
- g++-9-multilib
- toolset: gcc-9
cxxstd: "03-gnu,11-gnu,14-gnu,17-gnu,2a-gnu"
address_model: 32,64
os: ubuntu-latest
container: ubuntu:20.04
install:
- g++-9-multilib
- toolset: gcc-10
cxxstd: "03,11,14,17,20"
address_model: 32,64
os: ubuntu-latest
container: ubuntu:20.04
install:
- g++-10-multilib
- toolset: gcc-11
cxxstd: "03,11,14,17,20,23"
address_model: 32
Expand Down Expand Up @@ -145,44 +116,6 @@ jobs:
- g++-14-multilib

# Linux, clang
- toolset: clang
compiler: clang++-6.0
cxxstd: "03,11,14,17"
os: ubuntu-latest
container: ubuntu:18.04
install:
- clang-6.0
- toolset: clang
compiler: clang++-7
cxxstd: "03,11,14,17"
os: ubuntu-latest
container: ubuntu:18.04
install:
- clang-7
# Note: clang-8 does not fully support C++20, so it is not compatible with libstdc++-8 in this mode
- toolset: clang
compiler: clang++-8
cxxstd: "03,11,14,17,2a"
os: ubuntu-latest
container: ubuntu:18.04
install:
- clang-8
- g++-7
gcc_toolchain: 7
- toolset: clang
compiler: clang++-9
cxxstd: "03,11,14,17,2a"
os: ubuntu-latest
container: ubuntu:20.04
install:
- clang-9
- toolset: clang
compiler: clang++-10
cxxstd: "03,11,14,17,20"
os: ubuntu-latest
container: ubuntu:20.04
install:
- clang-10
- toolset: clang
compiler: clang++-11
cxxstd: "03,11,14,17"
Expand Down Expand Up @@ -318,9 +251,6 @@ jobs:
runs-on: ${{matrix.os}}
container:
image: ${{matrix.container}}
volumes:
- /node20217:/node20217:rw,rshared
- ${{ startsWith(matrix.container, 'ubuntu:1') && '/node20217:/__e/node20:ro,rshared' || ' ' }}

steps:
- name: Setup environment
Expand All @@ -344,13 +274,9 @@ jobs:
fi
apt-get -o Acquire::Retries=$NET_RETRY_COUNT install -y sudo software-properties-common tzdata wget curl apt-transport-https ca-certificates make build-essential g++ $PYTHON_PACKAGE python3 perl git cmake
fi
if [[ "${{matrix.container}}" == "ubuntu:1"* ]]; then
# Node 20 doesn't work with Ubuntu 16/18 glibc: https://github.com/actions/checkout/issues/1590
curl -sL https://archives.boost.io/misc/node/node-v20.9.0-linux-x64-glibc-217.tar.xz | tar -xJ --strip-components 1 -C /node20217
fi
fi
git config --global pack.threads 0
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Install packages
if: matrix.install
Expand Down Expand Up @@ -559,7 +485,7 @@ jobs:
runs-on: ${{matrix.os}}

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Setup Boost
shell: cmd
Expand Down Expand Up @@ -601,7 +527,7 @@ jobs:
runs-on: ${{matrix.os}}

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Install packages
if: matrix.install
Expand Down Expand Up @@ -648,7 +574,7 @@ jobs:
runs-on: ${{matrix.os}}

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Install packages
if: matrix.install
Expand Down Expand Up @@ -705,7 +631,7 @@ jobs:
runs-on: ${{matrix.os}}

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Install packages
if: matrix.install
Expand Down Expand Up @@ -760,7 +686,7 @@ jobs:
runs-on: ${{matrix.os}}

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Install packages
if: matrix.install
Expand Down Expand Up @@ -818,7 +744,7 @@ jobs:
runs-on: ${{matrix.os}}

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Configure and Install
run: |
Expand Down Expand Up @@ -870,7 +796,7 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Install packages
run: sudo apt install pkg-config
Expand Down Expand Up @@ -950,7 +876,7 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Install packages
run: sudo apt install pkg-config
Expand Down Expand Up @@ -1022,7 +948,7 @@ jobs:
# runs-on: windows-latest
#
# steps:
# - uses: actions/checkout@v4
# - uses: actions/checkout@v6
#
# - name: Setup MSYS2 environment
# uses: msys2/setup-msys2@v2
Expand All @@ -1033,7 +959,7 @@ jobs:
# pacboy: gcc:p cmake:p ninja:p
#
# - name: Fetch Boost.CI
# uses: actions/checkout@v4
# uses: actions/checkout@v6
# with:
# repository: boostorg/boost-ci
# ref: master
Expand Down Expand Up @@ -1063,7 +989,7 @@ jobs:
compiler: [ intel ]
standard: [ 14, 17, 20, 23 ]
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
with:
fetch-depth: '0'

Expand Down Expand Up @@ -1142,7 +1068,7 @@ jobs:
IMPORT_STD_UUID: f35a9ac6-8463-4d38-8eec-5d6008153e7d

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Install toolchain
run: |
Expand Down
28 changes: 20 additions & 8 deletions example/to_from_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@
#include <iomanip>
#include <cstdint>
#include <cstdio>
#include <string>

int main()
int main(int argc, char* argv[])
{
using boost::decimal::decimal32_t; // The type decimal32_t

// The name comes from the executable, because the test harness runs every build of this
// example from one directory. The standard allows argc to be 0, so a literal stands in then
const std::string file_name {(argc > 0 ? std::string(argv[0]) : std::string("to_from_file")) + "_values.txt"};

// First we need to generate some values that we will use for further usage
// This constructs a decimal32_t from random significand and exponent within the domain of decimal32_t
std::mt19937_64 rng {42};
Expand All @@ -38,7 +43,7 @@ int main()
// It is more efficient than writing the string to file with to_chars,
// and then recovering via the string constructor or from_chars

std::ofstream file("example_values.txt");
std::ofstream file(file_name, std::ios::binary);
if (!file.is_open())
{
std::cerr << "Failed to open file for writing" << std::endl;
Expand All @@ -55,10 +60,15 @@ int main()
file.write(reinterpret_cast<char*>(&bid_value), sizeof(bid_value));
}
file.close();
if (!file)
{
std::cerr << "Failed to write the file" << std::endl;
return 1;
}

// Now that we have written all the values to file we will read them in,
// and then convert them back them to the decimal values using from_bid
std::ifstream read_file("example_values.txt", std::ios::binary);
std::ifstream read_file(file_name, std::ios::binary);
if (!read_file.is_open())
{
std::cerr << "Failed to open file for reading" << std::endl;
Expand All @@ -68,19 +78,20 @@ int main()
std::array<decimal32_t, 10> recovered_values;
for (auto& value : recovered_values)
{
std::uint32_t bid_value;
std::uint32_t bid_value {};
read_file.read(reinterpret_cast<char*>(&bid_value), sizeof(bid_value));
value = boost::decimal::from_bid(bid_value);
}

const bool read_ok {static_cast<bool>(read_file)};
read_file.close();
if (std::remove("example_values.txt"))
if (std::remove(file_name.c_str()))
{
std::cerr << "Failed to remove file" << std::endl;
}

// Verify that we recovered the same values
bool success {true};
// Verify that we read every value, and that we recovered the same values
bool success {read_ok};
for (std::size_t i {}; i < values.size(); ++i)
{
if (values[i] != recovered_values[i])
Expand All @@ -96,7 +107,8 @@ int main()
}
else
{
std::cout << "Warning: Some values did not match after recovery" << std::endl;
std::cout << "Error: Some values did not match after recovery" << std::endl;
return 1;
}

return 0;
Expand Down
24 changes: 15 additions & 9 deletions include/boost/decimal/bid_conversion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ namespace decimal {
# pragma GCC diagnostic ignored "-Wconversion"
#endif

// from_bid picks the fast type by overload, not by an explicit specialization, because clang 15 to 18
// drop an explicit specialization of a constrained template which comes from a precompiled header

BOOST_DECIMAL_EXPORT BOOST_DECIMAL_CUDA_CONSTEXPR auto to_bid_d32(const decimal32_t val) noexcept -> std::uint32_t
{
return val.bits_;
Expand Down Expand Up @@ -200,39 +203,42 @@ BOOST_DECIMAL_CUDA_CONSTEXPR auto to_bid(const T val) noexcept

BOOST_DECIMAL_EXPORT template <typename T = decimal32_t>
BOOST_DECIMAL_CUDA_CONSTEXPR auto from_bid(const std::uint32_t bits) noexcept
BOOST_DECIMAL_REQUIRES(detail::is_decimal_floating_point_v, T)
BOOST_DECIMAL_REQUIRES(detail::is_ieee_type_v, T)
{
return from_bid_d32(bits);
}

template <>
BOOST_DECIMAL_CUDA_CONSTEXPR auto from_bid<decimal_fast32_t>(const std::uint32_t bits) noexcept -> decimal_fast32_t
BOOST_DECIMAL_EXPORT template <typename T>
BOOST_DECIMAL_CUDA_CONSTEXPR auto from_bid(const std::uint32_t bits) noexcept
BOOST_DECIMAL_REQUIRES_TWO_RETURN(detail::is_decimal_floating_point_v, T, detail::is_fast_type_v, T, T)
{
return from_bid_d32f(bits);
}

BOOST_DECIMAL_EXPORT template <typename T = decimal64_t>
BOOST_DECIMAL_CUDA_CONSTEXPR auto from_bid(const std::uint64_t bits) noexcept
BOOST_DECIMAL_REQUIRES(detail::is_decimal_floating_point_v, T)
BOOST_DECIMAL_REQUIRES(detail::is_ieee_type_v, T)
{
return from_bid_d64(bits);
}

template <>
BOOST_DECIMAL_CUDA_CONSTEXPR auto from_bid<decimal_fast64_t>(const std::uint64_t bits) noexcept -> decimal_fast64_t
BOOST_DECIMAL_EXPORT template <typename T>
BOOST_DECIMAL_CUDA_CONSTEXPR auto from_bid(const std::uint64_t bits) noexcept
BOOST_DECIMAL_REQUIRES_TWO_RETURN(detail::is_decimal_floating_point_v, T, detail::is_fast_type_v, T, T)
{
return from_bid_d64f(bits);
}

BOOST_DECIMAL_EXPORT template <typename T = decimal128_t>
BOOST_DECIMAL_CUDA_CONSTEXPR auto from_bid(const int128::uint128_t bits) noexcept
BOOST_DECIMAL_REQUIRES(detail::is_decimal_floating_point_v, T)
BOOST_DECIMAL_REQUIRES(detail::is_ieee_type_v, T)
{
return from_bid_d128(bits);
}

template <>
BOOST_DECIMAL_CUDA_CONSTEXPR auto from_bid<decimal_fast128_t>(const int128::uint128_t bits) noexcept -> decimal_fast128_t
BOOST_DECIMAL_EXPORT template <typename T>
BOOST_DECIMAL_CUDA_CONSTEXPR auto from_bid(const int128::uint128_t bits) noexcept
BOOST_DECIMAL_REQUIRES_TWO_RETURN(detail::is_decimal_floating_point_v, T, detail::is_fast_type_v, T, T)
{
return from_bid_d128f(bits);
}
Expand Down
Loading
Loading