Skip to content

Commit bdf1cd2

Browse files
authored
Merge pull request #1249 from cppalliance/1188
Add new page on binary floating point conversions
2 parents ae9076b + c6b4c49 commit bdf1cd2

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

doc/modules/ROOT/nav.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
** xref:decimal_fast32_t.adoc[]
2828
** xref:decimal_fast64_t.adoc[]
2929
** xref:decimal_fast128_t.adoc[]
30+
* xref:binary_floating_conversions.adoc[]
3031
* xref:cohorts.adoc[]
3132
* xref:conversions.adoc[]
3233
* xref:literals.adoc[]

doc/modules/ROOT/pages/basics.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ For more information see: xref:cfenv.adoc[]
119119
The entire library can be accessed using the convenience header `<boost/decimal.hpp>`.
120120
A short example of the basic usage:
121121

122+
[#first_example]
122123
.This https://github.com/cppalliance/decimal/blob/develop/examples/first_example.cpp[example] shows the very basics on how to make a complete and working program using the decimal library
123124
====
124125
[source, c++]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
////
2+
Copyright 2025 Matt Borland
3+
Distributed under the Boost Software License, Version 1.0.
4+
https://www.boost.org/LICENSE_1_0.txt
5+
////
6+
7+
[#bin_float]
8+
= Conversion from Binary Floating Point
9+
:idprefix: bin_float_
10+
11+
The library deliberately does not contain any operations between a binary floating point type and the decimal floating point types.
12+
The rationale is similar to that of the library in the first place in that you may end up with surprising results.
13+
As shown in our xref:basics.adoc#first_example[first example] `0.1 + 0.2 != 0.3` when using `double`, so you could end up with a decimal value that does not represent exactly what you expect.
14+
To offer minimal and explicit interoperability with types `float`, `double`, and `long double` each decimal type has an explicit constructor and conversion operator as discussed on the type specific documentation pages like xref:decimal32_t.adoc[`decimal32_t`]:
15+
16+
[source, c++]
17+
----
18+
namespace boost {
19+
namespace decimal {
20+
21+
class decimal32_t
22+
{
23+
template <typename Float>
24+
explicit decimal32_t(Float x) noexcept;
25+
26+
template <typename Float>
27+
explicit operator Float() const noexcept;
28+
};
29+
30+
} // namespace decimal
31+
} // namespace boost
32+
----
33+
34+
*No additional support is planned* to deter use of these conversions.
35+
If you have existing floating point values that need to be converted into decimals it is recommended to write them to string, validate the string, and then utilize the string constructors provided by this library.

doc/modules/ROOT/pages/design.adoc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ This allows Boost.Decimal to better emulate the functionality a built-in type wo
2020
Boost.Math requires C++14 as the minimum language standard for the library.
2121
By meeting this requirement, and Boost.Math's conceptual requirements for a user-defined type we are able to provide the statistics, interpolation, quadrature, etc. out of the box.
2222

23-
== No Binary Floating Point Operations
24-
The library deliberately does not contain any operations between a binary floating point type and the decimal floating point types.
25-
The rationale is similar to that of the library in the first place in that you may end up with surprising results.
26-
Conversion operators and constructors are available for all decimal types should the user want to explicit cast one side of the operation to conduct the operation.
27-
2823
== IEEE Deviations
2924

3025
=== `<cmath>` Functions Do Not Meet the Definition of Correctly Rounded

0 commit comments

Comments
 (0)