[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / time / time.duration / time.duration.alg / abs.pass.cpp
blobf95d42b52638e45b94d3fbd524ac75f01dc3d084
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
11 // <chrono>
13 // abs
15 // template <class Rep, class Period>
16 // constexpr duration<Rep, Period> abs(duration<Rep, Period> d)
18 #include <chrono>
19 #include <cassert>
20 #include <ratio>
21 #include <type_traits>
23 #include "test_macros.h"
25 template <class Duration>
26 void
27 test(const Duration& f, const Duration& d)
30 typedef decltype(std::chrono::abs(f)) R;
31 static_assert((std::is_same<R, Duration>::value), "");
32 assert(std::chrono::abs(f) == d);
36 int main(int, char**)
38 // 7290000ms is 2 hours, 1 minute, and 30 seconds
39 test(std::chrono::milliseconds( 7290000), std::chrono::milliseconds( 7290000));
40 test(std::chrono::milliseconds(-7290000), std::chrono::milliseconds( 7290000));
41 test(std::chrono::minutes( 122), std::chrono::minutes( 122));
42 test(std::chrono::minutes(-122), std::chrono::minutes( 122));
43 test(std::chrono::hours(0), std::chrono::hours(0));
46 // 9000000ms is 2 hours and 30 minutes
47 constexpr std::chrono::hours h1 = std::chrono::abs(std::chrono::hours(-3));
48 static_assert(h1.count() == 3, "");
49 constexpr std::chrono::hours h2 = std::chrono::abs(std::chrono::hours(3));
50 static_assert(h2.count() == 3, "");
54 // Make sure it works for durations that are not LCD'ed - example from LWG3091
55 constexpr auto d = std::chrono::abs(std::chrono::duration<int, std::ratio<60, 100>>{2});
56 static_assert(d.count() == 2, "");
59 return 0;