Skip to content

Commit 1cfdbb2

Browse files
committed
Add integral operations into example
1 parent 5d09658 commit 1cfdbb2

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

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)