-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
workaround to remove a UB from converting huge double->int8_t
- Loading branch information
1 parent
97cd146
commit ac53823
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
diff --git a/pstl/test/std/algorithms/alg.modifying.operations/transform_binary.pass.cpp b/pstl/test/std/algorithms/alg.modifying.operations/transform_binary.pass.cpp | ||
index 949e6f5..f32fb72 100644 | ||
--- a/pstl/test/std/algorithms/alg.modifying.operations/transform_binary.pass.cpp | ||
+++ b/pstl/test/std/algorithms/alg.modifying.operations/transform_binary.pass.cpp | ||
@@ -41,7 +41,7 @@ check_and_reset(InputIterator1 first1, InputIterator1 last1, InputIterator2 firs | ||
for (; first1 != last1; ++first1, ++first2, ++out_first, ++k) | ||
{ | ||
// check | ||
- Out expected = Out(1.5) + *first1 - *first2; | ||
+ Out expected = std::clamp<decltype(Out(1.5) + *first1 - *first2)>(Out(1.5) + *first1 - *first2, std::numeric_limits<Out>::lowest(), std::numeric_limits<Out>::max()); | ||
Out actual = *out_first; | ||
if (std::is_floating_point<Out>::value) | ||
{ | ||
@@ -113,7 +113,7 @@ main() | ||
test<int32_t, float32_t, float32_t>(non_const(TheOperation<int32_t, float32_t, float32_t>(1.5))); | ||
test<int64_t, float64_t, float32_t>(non_const(TheOperation<int64_t, float64_t, float32_t>(1.5))); | ||
//lambda | ||
- test<int8_t, float64_t, int8_t>([](const int8_t& x, const float64_t& y) { return int8_t(int8_t(1.5) + x - y); }); | ||
+ test<int8_t, float64_t, int8_t>([](const int8_t& x, const float64_t& y) { return int8_t(std::clamp<double>(int8_t(1.5) + x - y, std::numeric_limits<int8_t>::lowest(), std::numeric_limits<int8_t>::max())); }); | ||
|
||
test_algo_basic_double<int32_t>(run_for_rnd_fw<test_non_const<int32_t>>()); | ||
|