Skip to content

Commit d844e8d

Browse files
committed
Add example of the bit conversions
1 parent 2b3bbb1 commit d844e8d

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

examples/bit_conversions.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2024 Matt Borland
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// https://www.boost.org/LICENSE_1_0.txt
4+
5+
#include <boost/decimal.hpp>
6+
#include <iostream>
7+
#include <iomanip>
8+
9+
using namespace boost::decimal;
10+
11+
int main()
12+
{
13+
const decimal32_fast fast_type {5};
14+
const std::uint32_t BID_bits {to_bid(fast_type)};
15+
const std::uint32_t DPD_bits {to_dpd(fast_type)};
16+
17+
std::cout << std::hex
18+
<< "BID format: " << BID_bits << '\n'
19+
<< "DPD format: " << DPD_bits << std::endl;
20+
21+
const decimal32 bid_decimal {from_bid<decimal32>(BID_bits)};
22+
const decimal32 dpd_decimal {from_dpd<decimal32>(DPD_bits)};
23+
24+
return !(bid_decimal == dpd_decimal);
25+
}

test/Jamfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ run test_zeta.cpp ;
148148
# Run the examples too
149149
run ../examples/adl.cpp ;
150150
run ../examples/basic_construction.cpp ;
151+
run ../examples/bit_conversions.cpp ;
151152
run ../examples/charconv.cpp ;
152153
run ../examples/literals.cpp ;
153154
run ../examples/rounding_mode.cpp ;

0 commit comments

Comments
 (0)