Skip to content

Commit f66a652

Browse files
committed
Update example
1 parent ea6c77b commit f66a652

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

doc/modules/ROOT/pages/conversions.adoc

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,40 +121,47 @@ The following example is copied and pasted from the examples/ folder of the libr
121121

122122
[source, c++]
123123
----
124-
#include "test.hpp"
125124
#include <boost/decimal/decimal32_t.hpp>
126-
#include <boost/decimal/decimal_fast32_t.hpp>
127125
#include <boost/decimal/dpd_conversion.hpp>
128126
#include <boost/decimal/bid_conversion.hpp>
129127
#include <iostream>
130128
131129
int main()
132130
{
133131
using boost::decimal::decimal32_t;
134-
using boost::decimal::decimal_fast32_t;
135132
using boost::decimal::from_bid;
136133
using boost::decimal::from_dpd;
137134
using boost::decimal::to_bid;
138135
using boost::decimal::to_dpd;
139136
140-
const decimal_fast32_t fast_type {5};
141-
const std::uint32_t BID_bits {to_bid(fast_type)};
142-
const std::uint32_t DPD_bits {to_dpd(fast_type)};
137+
// First we construct a decimal value and then convert it into both BID and DPD encoded bits
138+
const decimal32_t decimal_value {5};
139+
const std::uint32_t BID_bits {to_bid(decimal_value)};
140+
const std::uint32_t DPD_bits {to_dpd(decimal_value)};
143141
142+
// Display the difference between the hex values of both bit encodings
144143
std::cout << std::hex
145144
<< "BID format: " << BID_bits << '\n'
146145
<< "DPD format: " << DPD_bits << std::endl;
147146
147+
// Recover the original value by encoding two new decimals using the from_bid and from_dpd functions
148148
const decimal32_t bid_decimal {from_bid<decimal32_t>(BID_bits)};
149149
const decimal32_t dpd_decimal {from_dpd<decimal32_t>(DPD_bits)};
150150
151-
BOOST_DECIMAL_TEST_NE(bid_decimal, dpd_decimal);
152-
153-
return boost::decimal::test::report_errors();
151+
if (bid_decimal == dpd_decimal)
152+
{
153+
// These should both have recovered the original value of 5
154+
return 0;
155+
}
156+
else
157+
{
158+
// Something has gone wrong recovering the decimal values
159+
return 1;
160+
}
154161
}
155162
----
156163
Output:
157164
----
158-
BID format: 31fc4b40
159-
DPD format: 35f00000
165+
BID format: 32800005
166+
DPD format: 22500005
160167
----

0 commit comments

Comments
 (0)