Skip to content

Commit c568bca

Browse files
committed
Add section on literals with note on how they construct
1 parent fc53d45 commit c568bca

File tree

5 files changed

+42
-26
lines changed

5 files changed

+42
-26
lines changed

doc/decimal.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ include::decimal/generic_decimal.adoc[]
2020
include::decimal/decimal32.adoc[]
2121
include::decimal/decimal64.adoc[]
2222
include::decimal/decimal128.adoc[]
23+
include::decimal/literals.adoc[]
2324
include::decimal/numbers.adoc[]
2425
include::decimal/cmath.adoc[]
2526
include::decimal/cstdlib.adoc[]

doc/decimal/decimal128.adoc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,6 @@ explicit constexpr operator std::bfloat16_t() const noexcept;
8383
explicit constexpr operator decimal32() const noexcept;
8484
explicit constexpr operator decimal64() const noexcept;
8585
86-
// Literals
87-
constexpr auto operator "" _DL(const char* str) -> decimal128
88-
constexpr auto operator "" _dl(const char* str) -> decimal128
89-
constexpr auto operator "" _DL(unsigned long long v) -> decimal128
90-
constexpr auto operator "" _dl(unsigned long long v) -> decimal128
91-
BOOST_DECIMAL_CXX20_CONSTEXPR auto operator "" _DL(long double v) -> decimal128
92-
BOOST_DECIMAL_CXX20_CONSTEXPR auto operator "" _dl(long double v) -> decimal128
93-
9486
} //namespace decimal
9587
} //namespace boost
9688

doc/decimal/decimal32.adoc

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,6 @@ explicit constexpr operator std::bfloat16_t() const noexcept;
8383
explicit constexpr operator decimal64() const noexcept;
8484
explicit constexpr operator decimal128() const noexcept;
8585
86-
// Literals
87-
constexpr auto operator "" _DF(const char* str) -> decimal32
88-
constexpr auto operator "" _df(const char* str) -> decimal32
89-
90-
constexpr auto operator "" _DF(unsigned long long v) -> decimal32
91-
constexpr auto operator "" _dF(unsigned long long v) -> decimal32
92-
93-
BOOST_DECIMAL_CXX20_CONSTEXPR auto operator "" _DF(long double v) -> decimal32
94-
BOOST_DECIMAL_CXX20_CONSTEXPR auto operator "" _dF(long double v) -> decimal32
95-
9686
} //namespace decimal
9787
} //namespace boost
9888

doc/decimal/decimal64.adoc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,6 @@ explicit constexpr operator std::bfloat16_t() const noexcept;
8383
explicit constexpr operator decimal32() const noexcept;
8484
explicit constexpr operator decimal128() const noexcept;
8585
86-
// Literals
87-
constexpr auto operator "" _DD(const char* str) -> decimal64
88-
constexpr auto operator "" _dd(const char* str) -> decimal64
89-
constexpr auto operator "" _DD(unsigned long long v) -> decimal64
90-
constexpr auto operator "" _dd(unsigned long long v) -> decimal64
91-
BOOST_DECIMAL_CXX20_CONSTEXPR auto operator "" _DD(long double v) -> decimal64
92-
BOOST_DECIMAL_CXX20_CONSTEXPR auto operator "" _dd(long double v) -> decimal64
93-
9486
} //namespace decimal
9587
} //namespace boost
9688

doc/decimal/literals.adoc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
////
2+
Copyright 2023 Matt Borland
3+
Distributed under the Boost Software License, Version 1.0.
4+
https://www.boost.org/LICENSE_1_0.txt
5+
////
6+
7+
[#literals]
8+
= Literals Support
9+
:idprefix: literals_
10+
11+
The following literals are offered to construct each of the types:
12+
13+
[source, c++]
14+
----
15+
namespace boost {
16+
namespace decimal {
17+
18+
constexpr auto operator "" _DF(const char* str) -> decimal32
19+
constexpr auto operator "" _df(const char* str) -> decimal32
20+
21+
constexpr auto operator "" _DF(unsigned long long v) -> decimal32
22+
constexpr auto operator "" _dF(unsigned long long v) -> decimal32
23+
24+
constexpr auto operator "" _DD(const char* str) -> decimal64
25+
constexpr auto operator "" _dd(const char* str) -> decimal64
26+
27+
constexpr auto operator "" _DD(unsigned long long v) -> decimal64
28+
constexpr auto operator "" _dd(unsigned long long v) -> decimal64
29+
30+
constexpr auto operator "" _DL(const char* str) -> decimal128
31+
constexpr auto operator "" _dl(const char* str) -> decimal128
32+
33+
constexpr auto operator "" _DL(unsigned long long v) -> decimal128
34+
constexpr auto operator "" _dl(unsigned long long v) -> decimal128
35+
36+
} //namespace decimal
37+
} //namespace boost
38+
----
39+
40+
IMPORTANT: `0.2_DF` is equivalent to calling `decimal32{2, -1}`.
41+
These are different from calling `decimal32{0.2}` which converts from a floating-point value which may or may not be exactly represented.

0 commit comments

Comments
 (0)