Skip to content

Commit 5ce4052

Browse files
authored
Merge pull request #939 from cppalliance/misc_improvments
Misc doc improvements
2 parents c051bd2 + 77ef2ea commit 5ce4052

File tree

12 files changed

+101
-28
lines changed

12 files changed

+101
-28
lines changed

doc/modules/ROOT/nav.adoc

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
* xref:overview.adoc[]
22
* xref:basics.adoc[]
33
* xref:examples.adoc[]
4+
** xref:examples.adoc#examples_construction[Construction]
5+
** xref:examples.adoc#examples_promotion[Type Promotion]
6+
** xref:examples.adoc#examples_charconv[`<charconv>`]
7+
** xref:examples.adoc#examples_rounding_mode[Rounding Mode]
8+
** xref:examples.adoc#examples_generic_programming[Generic Programming]
9+
** xref:examples.adoc#examples_literals_constants[Literals and Constants]
10+
** xref:examples.adoc#examples_bit_conversions[Bit Conversions]
11+
** xref:examples.adoc#examples_finance[Financial Applications]
12+
** xref:examples.adoc#examples_boost_math[Boost.Math Integration]
413
* xref:api_reference.adoc[]
5-
* xref:generic_decimal.adoc[]
14+
** xref:api_reference.adoc#api_ref_types[Types]
15+
** xref:api_reference.adoc#api_ref_structs[Structs]
16+
** xref:api_reference.adoc#api_ref_enums[Enums]
17+
** xref:api_reference.adoc#api_ref_constants[Constants]
18+
** xref:api_reference.adoc#api_ref_macros[Macros]
19+
* xref:generic_decimal.adoc[IEEE 754 Decimal Types]
620
** xref:decimal32_t.adoc[]
721
** xref:decimal64_t.adoc[]
822
** xref:decimal128_t.adoc[]
9-
* xref:fast_types.adoc[]
23+
* xref:fast_types.adoc[Non-IEEE 754 Decimal Types]
1024
** xref:decimal_fast32_t.adoc[]
1125
** xref:decimal_fast64_t.adoc[]
1226
** xref:decimal_fast128_t.adoc[]
@@ -27,6 +41,9 @@
2741
* xref:limits.adoc[]
2842
* xref:config.adoc[]
2943
* xref:benchmarks.adoc[]
44+
** xref:benchmarks.adoc#comparisons[Comparisons]
45+
** xref:benchmarks.adoc#basic_operations[Add, Sub, Mul, Div]
46+
** xref:benchmarks.adoc#benchmark_charconv[`<charconv>`]
3047
* xref:design.adoc[]
3148
* xref:reference.adoc[]
3249
* xref:copyright.adoc[]

doc/modules/ROOT/pages/api_reference.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ https://www.boost.org/LICENSE_1_0.txt
1111
This section is a complete cross-reference to all the types, structures,
1212
enums, constants and macros that are provided in this library.
1313

14+
[#api_ref_types]
1415
== Types
1516

1617
=== IEEE 754 Compliant Types
@@ -25,20 +26,24 @@ enums, constants and macros that are provided in this library.
2526
- xref:decimal_fast64_t.adoc[decimal_fast64_t]
2627
- xref:decimal_fast128_t.adoc[decimal_fast128_t]
2728

29+
[#api_ref_structs]
2830
== Structures
2931

3032
- xref:charconv.adoc#to_chars_result[to_chars_result]
3133
- xref:charconv.adoc#from_chars_result[from_chars_result]
3234

35+
[#api_ref_enums]
3336
== Enums
3437

3538
- xref:charconv.adoc#chars_format[chars_format]
3639

40+
[#api_ref_constants]
3741
== Constants
3842

3943
- xref:charconv.adoc#charconv_limits[limits]
4044
- xref:numbers.adoc[numbers]
4145

46+
[#api_ref_macros]
4247
== Macros
4348

4449
See: xref:config.adoc[configuration]

doc/modules/ROOT/pages/basics.adoc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,33 @@ boost::decimal::decimal128_t pi {3.14};
5858

5959
NOTE: Due to the differences in decimal and binary floating point numbers there may be a difference in the resulting representation in decimal format, and thus it is not recommended to construct from binary floating point numbers
6060

61+
== Fundamental Operations
62+
63+
The fundamental operations of numerical type (e.g. `>`, `==`, `+`, etc.) are overloaded.
64+
65+
[source, c++]
66+
----
67+
#include <boost/decimal.hpp>
68+
#include <cassert>
69+
70+
int main()
71+
{
72+
constexpr boost::decimal::decimal32_t lhs {5};
73+
constexpr boost::decimal::decimal32_t rhs {1, -1};
74+
75+
assert(lhs > rhs);
76+
assert(lhs != rhs);
77+
assert(lhs + rhs > lhs);
78+
79+
auto new_lhs {lhs}; // Using auto is safe when constructring from existing decimal values
80+
new_lhs += lhs;
81+
82+
assert(lhs < new_lhs);
83+
84+
return 0;
85+
}
86+
----
87+
6188
== Using the Library
6289

6390
The entire library can be accessed using the convenience header `<boost/decimal.hpp>`.

doc/modules/ROOT/pages/benchmarks.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ IMPORTANT: On nearly all platforms there is hardware support for binary floating
2020
To run the benchmarks yourself, navigate to the test folder and define `BOOST_DECIMAL_RUN_BENCHMARKS` when running the tests.
2121
An example on Linux with b2: `../../../b2 cxxstd=20 toolset=gcc-13 define=BOOST_DECIMAL_RUN_BENCHMARKS benchmarks -a release` .
2222

23+
[#comparisons]
2324
== Comparisons
2425

2526
The benchmark for comparisons generates a random vector containing 20,000,000 elements and does operations `>`, `>=`, `<`, `\<=`, `==`, and `!=` between `vec[i] and vec[i + 1]`.
@@ -130,6 +131,7 @@ Run using a Macbook pro with M4 Max chipset running macOS Sequoia 15.5 and homeb
130131
| 11.563
131132
|===
132133

134+
[#basic_operations]
133135
== Basic Operations
134136

135137
The benchmark for these operations generates a random vector containing 20,000,000 elements and does operations `+`, `-`, `*`, `/` between `vec[i] and vec[i + 1]`.
@@ -547,6 +549,7 @@ Run using a Macbook pro with M4 Max chipset running macOS Sequoia 15.5 and homeb
547549
| 458.320
548550
|===
549551

552+
[#benchmark_charconv]
550553
== `<charconv>`
551554

552555
Parsing and serializing number exactly is one of the key features of decimal floating point types, so we must compare the performance of `<charconv>`. For all the following the results compare against STL provided `<charconv>` for 20,000,000 conversions.

doc/modules/ROOT/pages/cfenv.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ https://www.boost.org/LICENSE_1_0.txt
1010

1111
== <cfenv>
1212

13-
As opposed to binary floating point types IEEE 754 defined 5 rounding modes instead of 4. They are:
13+
IEEE 754 defines 5 rounding modes for Decimal Floating Point Types.
1414

1515
1. Downward
1616
2. To nearest
1717
3. To nearest from zero
1818
4. Toward zero
1919
5. Upward
2020

21-
The default rounding mode is to nearest from zero.
21+
NOTE: The default rounding mode is to nearest from zero (#3).
2222

23-
IMPORTANT: The rounding mode can only be changed at runtime. All constexpr calculations will use the default of to nearest from zero.
23+
IMPORTANT: The rounding mode can only be changed at runtime. All `constexpr` calculations will use the default of to nearest from zero.
2424

2525
[source, c++]
2626
----

doc/modules/ROOT/pages/cfloat.adoc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ The following macros analogous to those from `<cfloat>` for the decimal floating
1414
----
1515
1616
// Number of digits in the coefficient
17-
#define BOOST_DECIMAL_DEC32_MANT_DIG 7
18-
#define BOOST_DECIMAL_DEC64_MANT_DIG 16
19-
#define BOOST_DECIMAL_DEC128_MANT_DIG 34
17+
#define BOOST_DECIMAL_DEC32_MANT_DIG std::numeric_limits<boost::decimal::decimal32_t>:digits10
18+
#define BOOST_DECIMAL_DEC64_MANT_DIG std::numeric_limits<boost::decimal::decimal64_t>:digits10
19+
#define BOOST_DECIMAL_DEC128_MANT_DIG std::numeric_limits<boost::decimal::decimal128_t>:digits10
2020
2121
// Minimum exponent
22-
#define BOOST_DECIMAL_DEC32_MIN_EXP -94
23-
#define BOOST_DECIMAL_DEC64_MIN_EXP -382
24-
#define BOOST_DECIMAL_DEC128_MIN_EXP -6142
22+
#define BOOST_DECIMAL_DEC32_MIN_EXP std::numeric_limits<boost::decimal::decimal32_t>:min_exponent
23+
#define BOOST_DECIMAL_DEC64_MIN_EXP std::numeric_limits<boost::decimal::decimal64_t>:min_exponent
24+
#define BOOST_DECIMAL_DEC128_MIN_EXP std::numeric_limits<boost::decimal::decimal128_t>:min_exponent
2525
2626
// Maximum exponent
27-
#define BOOST_DECIMAL_DEC32_MAX_EXP 97
28-
#define BOOST_DECIMAL_DEC64_MAX_EXP 385
29-
#define BOOST_DECIMAL_DEC128_MAX_EXP 6145
27+
#define BOOST_DECIMAL_DEC32_MAX_EXP std::numeric_limits<boost::decimal::decimal32_t>:max_exponent
28+
#define BOOST_DECIMAL_DEC64_MAX_EXP std::numeric_limits<boost::decimal::decimal64_t>:max_exponent
29+
#define BOOST_DECIMAL_DEC128_MAX_EXP std::numeric_limits<boost::decimal::decimal128_t>:max_exponent
3030
3131
// Maximum Finite Value
3232
#define BOOST_DECIMAL_DEC32_MAX std::numeric_limits<boost::decimal::decimal32_t>::max()

doc/modules/ROOT/pages/config.adoc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,24 @@ This option is not recommended, but can be useful if you want to use specific fu
2323

2424
[source, c++]
2525
----
26+
#define BOOST_DECIMAL_ALLOW_IMPLICIT_CONVERSIONS
27+
#include <boost/decimal.hpp>
28+
#include <complex>
29+
2630
constexpr decimal64_t half {5, -1};
2731
std::complex<decimal64_t> test_val {half, half};
2832
const auto res = std::acos(test_val);
2933
----
3034

3135
- `BOOST_DECIMAL_FAST_MATH` performs optimizations similar to that of the `-ffast-math` compiler flag such as removing all checks for non-finite values.
3236
This flag increases the performance of the basis operations (e.g. add, sub, mul, div, and comparisons) by up to 20%.
37+
Again, it must be defined before inclusion of decimal headers like so:
38+
39+
[source, c++]
40+
----
41+
#define BOOST_DECIMAL_FAST_MATH
42+
#include <boost/decimal.hpp>
43+
----
3344

3445
- `BOOST_DECIMAL_DEC_EVAL_METHOD`: See <cfloat> section for explanation
3546

doc/modules/ROOT/pages/conversions.adoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ namespace decimal {
1919
2020
namespace detail {
2121
22-
struct uint128
22+
struct uint128_t
2323
{
24-
std::uint64_t hi;
25-
std::uint64_t lo;
24+
std::uint64_t high;
25+
std::uint64_t low;
2626
};
2727
2828
} // namespace detail
@@ -56,9 +56,9 @@ constexpr decimal128_t from_bid_d128(unsigned __int128 bits) noexcept;
5656
5757
#endif // BOOST_DECIMAL_HAS_INT128
5858
59-
constexpr detail::uint128 to_bid_d128f(decimal_fast128_t val) noexcept;
59+
constexpr detail::uint128_t to_bid_d128f(decimal_fast128_t val) noexcept;
6060
61-
constexpr decimal128_t from_bid_d128f(detail::uint128 bits) noexcept;
61+
constexpr decimal128_t from_bid_d128f(detail::uint128_t bits) noexcept;
6262
6363
#ifdef BOOST_DECIMAL_HAS_INT128
6464

doc/modules/ROOT/pages/copyright.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ https://www.boost.org/LICENSE_1_0.txt
88
= Copyright and License
99
:idprefix: license_
1010

11-
This documentation is copyright 2023 Matt Borland and is distributed under
11+
This documentation is copyright 2023 - 2025 Matt Borland and Chris Kormanyos, and is distributed under
1212
the http://www.boost.org/LICENSE_1_0.txt[Boost Software License, Version 1.0].

doc/modules/ROOT/pages/cstdio.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ int printf(const char* format, Dec... values) noexcept;
2828
} //namespace boost
2929
----
3030

31-
=== Type Modifiers
31+
== Type Modifiers
3232

3333
The type modifiers to be used are:
3434

@@ -45,10 +45,10 @@ The remaining specifications of cstdio are the same as usual:
4545

4646
NOTE: The uppercase format will return with all applicable values in uppercase (e.g. 3.14E+02 vs 3.14e+02)
4747

48-
=== Examples
48+
== Examples
4949

5050
Here are some example formats:
5151

5252
- "%Hg" will print a `decimal32_t` in general format
53-
- "%.3De" will print a `decimal64_t` in scientific format with 3 digits of precision
54-
- "%.5DDA" will print a `decimal128_t` in hex format with 5 digits of precision and all letters will be capitalized (e.g. 1.F2CP+2 vs 1.f2cp+2)
53+
- "%.3De" will print a `decimal64_t` in scientific format with 3 digits of precision (e.g. 1.234e+05)
54+
- "%.5DDA" will print a `decimal128_t` in hex format with 5 digits of precision and all letters will be capitalized (e.g. 1.F2C34P+02 vs 1.f2c34p+02)

0 commit comments

Comments
 (0)