Skip to content

Commit 34f7e15

Browse files
committed
Add enum class to docs and remove bools from examples
1 parent b0d3dda commit 34f7e15

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

doc/modules/ROOT/pages/basics.adoc

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,33 @@ Every decimal type can be constructed in a few ways:
1616

1717
[source, c++]
1818
----
19+
namespace boost {
20+
namespace decimal {
21+
22+
enum class construction_sign
23+
{
24+
negative,
25+
positive
26+
};
27+
1928
template <typename UnsignedInteger, typename Integer>
20-
constexpr decimal32_t(UnsignedInteger coefficient, Integer exponent, bool is_negative = false) noexcept;
29+
constexpr decimal32_t(UnsignedInteger coefficient, Integer exponent, construction_sign resultant_sign = construction_sign::positive) noexcept;
2130
2231
template <typename SignedInteger, typename Integer>
2332
constexpr decimal32_t(SignedInteger coefficient, Integer exponent) noexcept;
33+
34+
} // namespace decimal
35+
} // namespace boost
2436
----
2537

2638
As you can see you are either allowed to pass a signed integer, or specify the signedness of the resulting number, but not both.
27-
This is designed to reduce confusion (e.g. what would be the resulting sign of `{-3, 0, true}`?)
39+
This is designed to reduce confusion (e.g. what would be the resulting sign of `{-3, 0, construction_sign::negative}`?)
2840

2941
[souce, c++]
3042
----
3143
boost::decimal::decimal32_t a {1, 1}; // constructs 1e1 = 10
3244
boost::decimal::decimal32_t b {-2, -1}; // constructs -2e-2 or -0.2
33-
boost::decimal::decimal32_t c {2U, -1, true}; // also constructs -2e-1 or -0.2 (Note: The coefficient must be an unsigned type)
45+
boost::decimal::decimal32_t c {2U, -1, construction_sign::negative}; // also constructs -2e-1 or -0.2 (Note: The coefficient must be an unsigned type)
3446
boost::decimal::decimal32_t e {5, 5}; // constructs 5x10^5
3547
boost::decimal::decimal32_t f {1234, -3} // constructs 1.234 or 1234x10^-3
3648
----

doc/modules/ROOT/pages/examples.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int main()
2626
2727
std::cout << sum << std::endl; // prints 0.3
2828
29-
const boost::decimal::decimal32_t neg_a {2, -1, true}; // Constructs the number -0.2
29+
const boost::decimal::decimal32_t neg_a {2, -1, construction_sign::negative}; // Constructs the number -0.2
3030
3131
sum += neg_a;
3232

0 commit comments

Comments
 (0)