Skip to content

Commit de07d0a

Browse files
authored
Merge pull request #1261 from cppalliance/api_ref
Add behavior of individual operators
2 parents 593bfb4 + 675c4f8 commit de07d0a

File tree

2 files changed

+174
-1
lines changed

2 files changed

+174
-1
lines changed

doc/modules/ROOT/pages/fast_types.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ https://www.boost.org/LICENSE_1_0.txt
99
:idprefix: fast_types_
1010

1111
Now that we have seen the three basic types as specified in IEEE-754 there are three additional adjacent types: `decimal_fast32_t`, `decimal_fast64_t`, and `decimal_fast128_t`.
12-
These types yield identical computational results but with faster performance.
12+
These types yield similar computational results but with faster performance.
1313
These types make the classic tradeoff of space for time as they require more storage width than the IEEE 754 conformant type.
1414
For example `decimal32_t` is fundamentally:
1515

@@ -48,3 +48,5 @@ assert(a == b);
4848

4949
In this example `a` and `b` both have different encodings (cohorts), so they must be normalized before comparison.
5050
`decimal_fast32_t` and the other fast types store the significand and exponent in a normalized fashion, so once again we can skip that step for every operation.
51+
52+
For behavior of the individual operators see the xref:generic_decimal.adoc#operator_behavior[reference section] for the IEEE decimal types.

doc/modules/ROOT/pages/generic_decimal.adoc

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,174 @@ In the event of binary arithmetic between two decimal types the result will be t
164164
== 3.2.10 Note
165165

166166
xref:design.adoc#non-finite-deviation[Non-finite values are supported]
167+
168+
[#operator_behavior]
169+
== Operator Behaviors
170+
171+
=== Unary Plus
172+
173+
[source,c++]
174+
----
175+
// 3.2.7 unary arithmetic operators:
176+
constexpr decimal32_t operator+(decimal32_t rhs) noexcept;
177+
constexpr decimal64_t operator+(decimal64_t rhs) noexcept;
178+
constexpr decimal128_t operator+(decimal128_t rhs) noexcept;
179+
----
180+
181+
Returns `rhs` unmodified in all cases.
182+
183+
=== Unary Minus
184+
185+
[source,c++]
186+
----
187+
constexpr decimal32_t operator-(decimal32_t rhs) noexcept;
188+
constexpr decimal64_t operator-(decimal64_t rhs) noexcept;
189+
constexpr decimal128_t operator-(decimal128_t rhs) noexcept;
190+
----
191+
192+
Returns negated `rhs` in all cases.
193+
194+
=== Addition
195+
196+
[source,c++]
197+
----
198+
// 3.2.8 binary arithmetic operators:
199+
// LHS and RHS can be any integer or decimal type
200+
201+
constexpr /* see 3.2.8 */ operator+(LHS lhs, decimal32_t rhs) noexcept;
202+
constexpr /* see 3.2.8 */ operator+(LHS lhs, decimal64_t rhs) noexcept;
203+
constexpr /* see 3.2.8 */ operator+(LHS lhs, decimal128_t rhs) noexcept;
204+
constexpr /* see 3.2.8 */ operator+(decimal32_t lhs, RHS rhs) noexcept;
205+
constexpr /* see 3.2.8 */ operator+(decimal64_t lhs, RHS rhs) noexcept;
206+
constexpr /* see 3.2.8 */ operator+(decimal128_t lhs, RHS rhs) noexcept;
207+
----
208+
209+
Returns the result of `lhs + rhs` subject to:
210+
211+
. If either `lhs` or `rhs` are `NAN`, returns `QNAN`
212+
. If `lhs` and `rhs` are `INF` of opposite sign, returns `QNAN`
213+
. If either `lhs` or `rhs` are `INF`, returns `INF` of same sign
214+
. If `lhs + rhs` overflows, returns `INF`
215+
. If `lhs + rhs` underflows, returns `0`
216+
217+
=== Subtraction
218+
219+
[source,c++]
220+
----
221+
// 3.2.8 binary arithmetic operators:
222+
// LHS and RHS can be any integer or decimal type
223+
224+
constexpr /* see 3.2.8 */ operator-(LHS lhs, decimal32_t rhs) noexcept;
225+
constexpr /* see 3.2.8 */ operator-(LHS lhs, decimal64_t rhs) noexcept;
226+
constexpr /* see 3.2.8 */ operator-(LHS lhs, decimal128_t rhs) noexcept;
227+
constexpr /* see 3.2.8 */ operator-(decimal32_t lhs, RHS rhs) noexcept;
228+
constexpr /* see 3.2.8 */ operator-(decimal64_t lhs, RHS rhs) noexcept;
229+
constexpr /* see 3.2.8 */ operator-(decimal128_t lhs, RHS rhs) noexcept;
230+
----
231+
232+
Returns the result of `lhs - rhs` subject to:
233+
234+
. If either `lhs` or `rhs` are `NAN`, returns `QNAN`
235+
. If `lhs` and `rhs` are `INF` of opposite sign, returns `QNAN`
236+
. If either `lhs` or `rhs` are `INF`, returns `INF` of same sign
237+
. If `lhs - rhs` overflows, returns `INF`
238+
. If `lhs - rhs` underflows, returns `0`
239+
240+
=== Multiplication
241+
242+
[source,c++]
243+
----
244+
// 3.2.8 binary arithmetic operators:
245+
// LHS and RHS can be any integer or decimal type
246+
247+
constexpr /* see 3.2.8 */ operator*(LHS lhs, decimal32_t rhs) noexcept;
248+
constexpr /* see 3.2.8 */ operator*(LHS lhs, decimal64_t rhs) noexcept;
249+
constexpr /* see 3.2.8 */ operator*(LHS lhs, decimal128_t rhs) noexcept;
250+
constexpr /* see 3.2.8 */ operator*(decimal32_t lhs, RHS rhs) noexcept;
251+
constexpr /* see 3.2.8 */ operator*(decimal64_t lhs, RHS rhs) noexcept;
252+
constexpr /* see 3.2.8 */ operator*(decimal128_t lhs, RHS rhs) noexcept;
253+
----
254+
255+
Returns the result of `lhs * rhs` subject to:
256+
257+
. If either `lhs` or `rhs` are `NAN`, returns `QNAN`
258+
. If either `lhs` or `rhs` are `INF` and the other is `0`, returns `QNAN`
259+
. If either `lhs` or `rhs` are `INF`, returns `INF` of same sign
260+
. If `lhs * rhs` overflows, returns `INF`
261+
. If `lhs * rhs` underflows, returns `0`
262+
263+
=== Division
264+
265+
[source,c++]
266+
----
267+
// 3.2.8 binary arithmetic operators:
268+
// LHS and RHS can be any integer or decimal type
269+
270+
constexpr /* see 3.2.8 */ operator/(LHS lhs, decimal32_t rhs) noexcept;
271+
constexpr /* see 3.2.8 */ operator/(LHS lhs, decimal64_t rhs) noexcept;
272+
constexpr /* see 3.2.8 */ operator/(LHS lhs, decimal128_t rhs) noexcept;
273+
constexpr /* see 3.2.8 */ operator/(decimal32_t lhs, RHS rhs) noexcept;
274+
constexpr /* see 3.2.8 */ operator/(decimal64_t lhs, RHS rhs) noexcept;
275+
constexpr /* see 3.2.8 */ operator/(decimal128_t lhs, RHS rhs) noexcept;
276+
----
277+
278+
Returns the result of `lhs / rhs` subject to:
279+
280+
. If either `lhs` or `rhs` are `NAN`, returns `QNAN`
281+
. If `lhs` is `INF`:
282+
.. Returns `QNAN` if `rhs` is `INF`
283+
.. Returns `INF` if `rhs` is not `INF`
284+
. If `rhs` is `0` returns `INF`
285+
. If `rhs` is `INF` returns `0`
286+
. If `lhs / rhs` overflows, returns `INF`
287+
. If `lhs / rhs` underflows, returns `0`
288+
289+
=== Comparison Operators
290+
291+
[source, c++]
292+
----
293+
// 3.2.9 comparison operators:
294+
// LHS and RHS can be any integer or decimal type
295+
296+
constexpr bool operator==(LHS lhs, decimal32_t rhs) noexcept;
297+
constexpr bool operator==(LHS lhs, decimal64_t rhs) noexcept;
298+
constexpr bool operator==(LHS lhs, decimal128_t rhs) noexcept;
299+
constexpr bool operator==(decimal32_t lhs, RHS rhs) noexcept;
300+
constexpr bool operator==(decimal64_t lhs, RHS rhs) noexcept;
301+
constexpr bool operator==(decimal128_t lhs, RHS rhs) noexcept;
302+
constexpr bool operator!=(LHS lhs, decimal32_t rhs) noexcept;
303+
constexpr bool operator!=(LHS lhs, decimal64_t rhs) noexcept;
304+
constexpr bool operator!=(LHS lhs, decimal128_t rhs) noexcept;
305+
constexpr bool operator!=(decimal32_t lhs, RHS rhs) noexcept;
306+
constexpr bool operator!=(decimal64_t lhs, RHS rhs) noexcept;
307+
constexpr bool operator!=(decimal128_t lhs, RHS rhs) noexcept;
308+
constexpr bool operator<(LHS lhs, decimal32_t rhs) noexcept;
309+
constexpr bool operator<(LHS lhs, decimal64_t rhs) noexcept;
310+
constexpr bool operator<(LHS lhs, decimal128_t rhs) noexcept;
311+
constexpr bool operator<(decimal32_t lhs, RHS rhs) noexcept;
312+
constexpr bool operator<(decimal64_t lhs, RHS rhs) noexcept;
313+
constexpr bool operator<(decimal128_t lhs, RHS rhs) noexcept;
314+
constexpr bool operator<=(LHS lhs, decimal32_t rhs) noexcept;
315+
constexpr bool operator<=(LHS lhs, decimal64_t rhs) noexcept;
316+
constexpr bool operator<=(LHS lhs, decimal128_t rhs) noexcept;
317+
constexpr bool operator<=(decimal32_t lhs, RHS rhs) noexcept;
318+
constexpr bool operator<=(decimal64_t lhs, RHS rhs) noexcept;
319+
constexpr bool operator<=(decimal128_t lhs, RHS rhs) noexcept;
320+
constexpr bool operator>(LHS lhs, decimal32_t rhs) noexcept;
321+
constexpr bool operator>(LHS lhs, decimal64_t rhs) noexcept;
322+
constexpr bool operator>(LHS lhs, decimal128_t rhs) noexcept;
323+
constexpr bool operator>(decimal32_t lhs, RHS rhs) noexcept;
324+
constexpr bool operator>(decimal64_t lhs, RHS rhs) noexcept;
325+
constexpr bool operator>(decimal128_t lhs, RHS rhs) noexcept;
326+
constexpr bool operator>=(LHS lhs, decimal32_t rhs) noexcept;
327+
constexpr bool operator>=(LHS lhs, decimal64_t rhs) noexcept;
328+
constexpr bool operator>=(LHS lhs, decimal128_t rhs) noexcept;
329+
constexpr bool operator>=(decimal32_t lhs, RHS rhs) noexcept;
330+
constexpr bool operator>=(decimal64_t lhs, RHS rhs) noexcept;
331+
constexpr bool operator>=(decimal128_t lhs, RHS rhs) noexcept;
332+
----
333+
334+
Returns the result of the comparison subject to:
335+
336+
. If `lhs` or `rhs` returns `false`
337+
.. This includes the case where both `lhs` and `rhs` are `NAN`

0 commit comments

Comments
 (0)