OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #if defined(COMPILER_MSVC) && defined(ARCH_CPU_32_BITS) | 5 #if defined(COMPILER_MSVC) && defined(ARCH_CPU_32_BITS) |
6 #include <mmintrin.h> | 6 #include <mmintrin.h> |
7 #endif | 7 #endif |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <limits> | 10 #include <limits> |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 TEST_EXPECTED_VALUE(-1, (CheckedNumeric<Dst>() - 1)); | 232 TEST_EXPECTED_VALUE(-1, (CheckedNumeric<Dst>() - 1)); |
233 TEST_EXPECTED_VALUE(0, (CheckedNumeric<Dst>(1) - 1)); | 233 TEST_EXPECTED_VALUE(0, (CheckedNumeric<Dst>(1) - 1)); |
234 TEST_EXPECTED_VALUE(-2, (CheckedNumeric<Dst>(-1) - 1)); | 234 TEST_EXPECTED_VALUE(-2, (CheckedNumeric<Dst>(-1) - 1)); |
235 TEST_EXPECTED_VALIDITY(RANGE_VALID, | 235 TEST_EXPECTED_VALIDITY(RANGE_VALID, |
236 CheckedNumeric<Dst>(DstLimits::max()) - 1); | 236 CheckedNumeric<Dst>(DstLimits::max()) - 1); |
237 | 237 |
238 // Generic multiplication. | 238 // Generic multiplication. |
239 TEST_EXPECTED_VALUE(0, (CheckedNumeric<Dst>() * 1)); | 239 TEST_EXPECTED_VALUE(0, (CheckedNumeric<Dst>() * 1)); |
240 TEST_EXPECTED_VALUE(1, (CheckedNumeric<Dst>(1) * 1)); | 240 TEST_EXPECTED_VALUE(1, (CheckedNumeric<Dst>(1) * 1)); |
241 TEST_EXPECTED_VALUE(-2, (CheckedNumeric<Dst>(-1) * 2)); | 241 TEST_EXPECTED_VALUE(-2, (CheckedNumeric<Dst>(-1) * 2)); |
| 242 TEST_EXPECTED_VALUE(0, (CheckedNumeric<Dst>(0) * 0)); |
| 243 TEST_EXPECTED_VALUE(0, (CheckedNumeric<Dst>(-1) * 0)); |
| 244 TEST_EXPECTED_VALUE(0, (CheckedNumeric<Dst>(0) * -1)); |
242 TEST_EXPECTED_VALIDITY( | 245 TEST_EXPECTED_VALIDITY( |
243 RANGE_OVERFLOW, CheckedNumeric<Dst>(DstLimits::max()) * DstLimits::max()); | 246 RANGE_OVERFLOW, CheckedNumeric<Dst>(DstLimits::max()) * DstLimits::max()); |
244 | 247 |
245 // Generic division. | 248 // Generic division. |
246 TEST_EXPECTED_VALUE(0, CheckedNumeric<Dst>() / 1); | 249 TEST_EXPECTED_VALUE(0, CheckedNumeric<Dst>() / 1); |
247 TEST_EXPECTED_VALUE(1, CheckedNumeric<Dst>(1) / 1); | 250 TEST_EXPECTED_VALUE(1, CheckedNumeric<Dst>(1) / 1); |
248 TEST_EXPECTED_VALUE(DstLimits::min() / 2, | 251 TEST_EXPECTED_VALUE(DstLimits::min() / 2, |
249 CheckedNumeric<Dst>(DstLimits::min()) / 2); | 252 CheckedNumeric<Dst>(DstLimits::min()) / 2); |
250 TEST_EXPECTED_VALUE(DstLimits::max() / 2, | 253 TEST_EXPECTED_VALUE(DstLimits::max() / 2, |
251 CheckedNumeric<Dst>(DstLimits::max()) / 2); | 254 CheckedNumeric<Dst>(DstLimits::max()) / 2); |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 static_cast<int>(small_positive)); | 570 static_cast<int>(small_positive)); |
568 EXPECT_EQ(saturated_cast<unsigned>(small_negative), | 571 EXPECT_EQ(saturated_cast<unsigned>(small_negative), |
569 static_cast<unsigned>(0)); | 572 static_cast<unsigned>(0)); |
570 EXPECT_EQ(saturated_cast<int>(double_small), | 573 EXPECT_EQ(saturated_cast<int>(double_small), |
571 static_cast<int>(double_small)); | 574 static_cast<int>(double_small)); |
572 EXPECT_EQ(saturated_cast<int>(double_large), numeric_limits<int>::max()); | 575 EXPECT_EQ(saturated_cast<int>(double_large), numeric_limits<int>::max()); |
573 EXPECT_EQ(saturated_cast<float>(double_large), double_infinity); | 576 EXPECT_EQ(saturated_cast<float>(double_large), double_infinity); |
574 EXPECT_EQ(saturated_cast<float>(-double_large), -double_infinity); | 577 EXPECT_EQ(saturated_cast<float>(-double_large), -double_infinity); |
575 } | 578 } |
576 | 579 |
OLD | NEW |