Skip to content

Commit c4eab90

Browse files
committed
Add additional comments on underflow, overflow, and non-finite values
1 parent 460fde2 commit c4eab90

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

doc/modules/ROOT/pages/basics.adoc

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,19 @@ This is designed to reduce confusion (e.g. what would be the resulting sign of `
2828

2929
[souce, c++]
3030
----
31-
boost::decimal::decimal32_t a {1, 1}; // constructs 1e1 = 10
32-
boost::decimal::decimal32_t b {-2, -1}; // constructs -2e-2 or -0.2
33-
boost::decimal::decimal32_t c {2, -1, true}; // also constructs -2e-1 or -0.2
34-
boost::decimal::decimal32_t e {5, 5}; // constructs 5x10^5
35-
boost::decimal::decimal32_t f {1234, -3} // constructs 1.234 or 1234x10^-3
31+
boost::decimal::decimal32_t a {1, 1}; // constructs 1e1 = 10
32+
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)
34+
boost::decimal::decimal32_t e {5, 5}; // constructs 5x10^5
35+
boost::decimal::decimal32_t f {1234, -3} // constructs 1.234 or 1234x10^-3
36+
----
37+
38+
Overflow and underflow are handled the same way that they are with binary floating point numbers i.e. they will construct an infinity or a zero.
39+
40+
[source, c++]
41+
----
42+
boost::decimal::decimal64_t oveflow_value {100, 10000}; // Constructs +infinity
43+
boost::decimal::decimal64_t underflow_value {100, -10000}; // Constructs 0
3644
----
3745

3846
=== Construction from Integer
@@ -56,6 +64,9 @@ For example:
5664
boost::decimal::decimal128_t pi {3.14};
5765
----
5866

67+
Construction from non-finite values (e.g. `std::numeric_limits<double>::quiet_NaN()`) will yield the same non-finite value in the resulting decimal value.
68+
Overflow or underflow will construct infinity or 0.
69+
5970
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
6071

6172
== Fundamental Operations

0 commit comments

Comments
 (0)