Skip to content

Commit 86724dc

Browse files
committed
Add section on fundamental operations to basics
1 parent 0fd5a38 commit 86724dc

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

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>`.

0 commit comments

Comments
 (0)