Skip to content

Commit 5b42457

Browse files
authored
Merge pull request #1262 from cppalliance/type_ref
Add description of member functions of decimal32_t
2 parents de07d0a + b3e988d commit 5b42457

File tree

1 file changed

+121
-1
lines changed

1 file changed

+121
-1
lines changed

doc/modules/ROOT/pages/decimal32_t.adoc

Lines changed: 121 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public:
4646
// 3.2.2.1 construct/copy/destroy
4747
constexpr decimal32_t() noexcept = default;
4848
49-
// 3.2.2.2 Conversion form floating-point type
49+
// 3.2.2.2 Conversion from floating-point type
5050
template <typename Float>
5151
explicit BOOST_DECIMAL_CXX20_CONSTEXPR decimal32_t(Float val) noexcept;
5252
@@ -114,3 +114,123 @@ explicit constexpr operator decimal128_t() const noexcept;
114114
} //namespace boost
115115
116116
----
117+
118+
== Operator Behavior
119+
120+
=== Construction to and from binary floating-point type
121+
122+
[source, c++]
123+
----
124+
// 3.2.2.2 Conversion from floating-point type
125+
template <typename Float>
126+
explicit BOOST_DECIMAL_CXX20_CONSTEXPR decimal32_t(Float val) noexcept;
127+
128+
// 3.2.6 Conversion to floating-point type
129+
explicit BOOST_DECIMAL_CXX20_CONSTEXPR operator float() const noexcept;
130+
explicit BOOST_DECIMAL_CXX20_CONSTEXPR operator double() const noexcept;
131+
explicit BOOST_DECIMAL_CXX20_CONSTEXPR operator long double() const noexcept;
132+
133+
// If C++23 and <stdfloat> are available
134+
explicit constexpr operator std::float16_t() const noexcept;
135+
explicit constexpr operator std::float32_t() const noexcept;
136+
explicit constexpr operator std::float64_t() const noexcept;
137+
explicit constexpr operator std::bfloat16_t() const noexcept;
138+
----
139+
140+
See: xref:binary_floating_conversions.adoc[]
141+
142+
=== Construction From Integral Type
143+
144+
[source,c++]
145+
----
146+
// 3.2.2.3 Conversion from integral type
147+
template <typename Integer>
148+
explicit constexpr decimal32_t(Integer val) noexcept;
149+
----
150+
151+
Constructs a decimal value subject to the current rounding mode (if necessary).
152+
153+
=== Construction From String
154+
155+
[source,c++]
156+
----
157+
// Extension: Construction from (c)string
158+
explicit constexpr decimal32_t(const char* str);
159+
160+
#ifndef BOOST_DECIMAL_HAS_STD_STRING_VIEW
161+
explicit inline decimal32_t(const std::string& str);
162+
#else
163+
explicit constexpr decimal32_t(std::string_view str);
164+
#endif
165+
----
166+
167+
Constructs a decimal value that matches `str` subject to:
168+
169+
. If `str` is a `nullptr` or of length 0 either:
170+
.. `throw std::runtime_error`
171+
.. Constructs a `QNAN` in a no exception environment
172+
. If `str` is an invalid string either:
173+
.. `throw std::runtime_error`
174+
.. Constructs a `QNAN` in a no exception environment
175+
. On overflow constructs `INF`
176+
. On underflow constructs `0`
177+
. Rounds value represented by `str` according to current rounding mode
178+
179+
=== Conversion to Integral Type
180+
181+
[source,c++]
182+
----
183+
// 3.2.2.4 Conversion to integral type
184+
185+
explicit constexpr operator int() const noexcept;
186+
explicit constexpr operator unsigned() const noexcept;
187+
explicit constexpr operator long() const noexcept;
188+
explicit constexpr operator unsigned long() const noexcept;
189+
explicit constexpr operator long long() const noexcept;
190+
explicit constexpr operator unsigned long long() const noexcept;
191+
----
192+
193+
Constructs an integer representation of the decimal value subject to:
194+
195+
. If the decimal value is `INF` returns `std::numeric_limits<IntegerType>::max()`
196+
. If the decimal value is `NAN` returns `std::numeric_limits<IntegerType>::max()`
197+
. If the decimal value exceeds the range of the `IntegerType` returns `std::numeric_limits<IntegerType>::max()`
198+
199+
=== Increment and Decrement Operators
200+
201+
[source,c++]
202+
----
203+
// 3.2.2.5 increment and decrement operators:
204+
constexpr decimal32_t& operator++();
205+
constexpr decimal32_t operator++(int);
206+
constexpr decimal32_t& operator--();
207+
constexpr decimal32_t operator--(int);
208+
----
209+
210+
Increments/Decrements the decimal value subject to:
211+
212+
. If the decimal value is `NAN` returns `QNAN`
213+
. If the decimal value is `INF` returns `INF`
214+
215+
=== Compound Operators
216+
217+
[source, c++]
218+
----
219+
// 3.2.2.6 compound assignment:
220+
constexpr decimal32_t& operator+=(RHS rhs);
221+
constexpr decimal32_t& operator-=(RHS rhs);
222+
constexpr decimal32_t& operator*=(RHS rhs);
223+
constexpr decimal32_t& operator/=(RHS rhs);
224+
----
225+
226+
Matches the behavior of xref:generic_decimal.adoc#operator_behavior[addition, subtraction, multiplication, and division].
227+
228+
=== Conversion to Other Decimal Types
229+
230+
[source,c++]
231+
----
232+
explicit constexpr operator decimal64_t() const noexcept;
233+
explicit constexpr operator decimal128_t() const noexcept;
234+
----
235+
236+
Losslessly converts the current decimal value to `decimal64_t` or `decimal128_t`.

0 commit comments

Comments
 (0)