Skip to content

Commit 0abe29a

Browse files
authored
Merge pull request #1245 from cppalliance/docsdocs
More doc and example fixes
2 parents e97c5c8 + a483e44 commit 0abe29a

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

doc/modules/ROOT/pages/cmath.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ constexpr bool issignaling(Decimal x) noexcept;
543543
----
544544

545545
Effects: If x is an sNaN returns true, otherwise returns false.
546+
This function does not signal even if x is an sNaN per IEEE 754 section 5.7.2.
546547

547548
=== `read_payload`
548549

@@ -661,6 +662,7 @@ constexpr auto frexp10(Decimal num, int* expptr) noexcept;
661662

662663
This function is very similar to https://en.cppreference.com/w/cpp/numeric/math/frexp[frexp], but returns the significand and an integral power of 10 since the `FLT_RADIX` of this type is 10.
663664
The significand is normalized to the number of digits of precision the type has (e.g. for decimal32_t it is [1'000'000, 9'999'999]).
665+
For further discussion on normalized form see the page on xref:cohorts.adoc[cohorts].
664666

665667
=== `normalize`
666668

doc/modules/ROOT/pages/cohorts.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ That means all the following are valid ways to represent the number 300 using th
2424
. 3000000e-4
2525

2626
These values can be useful in certain applications, like preserving the precision of results.
27+
A value is said to be *normalized* when the effects of these cohorts is removed.
28+
This is done by appending zeros to the significand and reducing the exponent until the significand has the same number of significant digits as the type can represent.
29+
For example 1 - 6 above would all be represented the same as value 7.
2730
By default, most methods *DO NOT* observe cohorts.
2831
Below is an example of how cohorts can be preserved if one so wishes.
2932

doc/modules/ROOT/pages/examples.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ decimal32_t value (a): 5.2
4949
decimal64_t value (b): 3.9
5050
a is greater than b
5151
5.2 is less than 1e+385
52-
1e+385 is now less than inf
52+
1e+385 is less than inf
5353
The result of a + b is a decimal64_t: 9.1
54+
The result of 2*c is a decimal64_t: 18.2
55+
18.2 is greater than 5
5456
....
5557
====
5658

examples/promotion.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,20 @@ int main()
5757
static_assert(std::is_same<c_type, decimal64_t>::value, "decimal32_t + decimal64_t is supposed to yield decimal64_t");
5858
std::cout << "The result of a + b is a decimal64_t: " << c << '\n';
5959

60-
return 0;
60+
// Now we can look at similar promotion that occurs when an operation is performed between
61+
// a decimal type and an integer
62+
//
63+
// Similar to the above when we have mixed operations like +, -, *, / we always promote to the decimal type
64+
// Example: decimal64_t * int -> decimal64_t
65+
66+
const auto d {2 * c};
67+
using d_type = std::remove_cv_t<decltype(d)>;
68+
static_assert(std::is_same<d_type, decimal64_t>::value, "decimal64_t * integer is supposed to yield decimal64_t");
69+
std::cout << "The result of 2 * c is a decimal64_t: " << d << '\n';
70+
71+
// The full suite of comparison operators between decimal types and integers
72+
if (d > 5)
73+
{
74+
std::cout << d << " is greater than 5" << '\n';
75+
}
6176
}

0 commit comments

Comments
 (0)