Replace non-constexpr decrement in std::chrono::floor
authorJonathan Wakely <jwakely@redhat.com>
Thu, 13 Oct 2016 14:42:09 +0000 (15:42 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Thu, 13 Oct 2016 14:42:09 +0000 (15:42 +0100)
* include/std/chrono (floor): Replace non-constexpr operation.
* testsuite/20_util/duration_cast/rounding.cc: Test conversion to
durations with floating pointer representations.

From-SVN: r241122

libstdc++-v3/ChangeLog
libstdc++-v3/include/std/chrono
libstdc++-v3/testsuite/20_util/duration_cast/rounding.cc

index 1dac9caa868deddd43b473016572727f582021d7..5a8153498f44b5b5f75842d1260cec0b5fa7fd5a 100644 (file)
@@ -1,5 +1,9 @@
 2016-10-13  Jonathan Wakely  <jwakely@redhat.com>
 
+       * include/std/chrono (floor): Replace non-constexpr operation.
+       * testsuite/20_util/duration_cast/rounding.cc: Test conversion to
+       durations with floating pointer representations.
+
        * src/c++11/compatibility-thread-c++0x.cc (_Bind_simple)
        (_Bind_simple_helper, __bind_simple): Restore for ABI compat symbols.
 
index cb8c87651833627cfa035ba5f3ea6cce69065d4f..ceae7f805c1ea16dc8df90c3d9a5b4f28a545f3b 100644 (file)
@@ -224,7 +224,7 @@ _GLIBCXX_END_NAMESPACE_VERSION
       {
        auto __to = chrono::duration_cast<_ToDur>(__d);
        if (__to > __d)
-         --__to;
+         return __to - _ToDur{1};
        return __to;
       }
 
index a753323027349b186154cfef8edca609be610c06..2a1df7478d44aaffe6421cc51a00d857791383d2 100644 (file)
@@ -27,6 +27,8 @@
 using namespace std::chrono_literals;
 using std::chrono::seconds;
 
+using fp_seconds = std::chrono::duration<float>;
+
 static_assert( std::chrono::floor<seconds>(1000ms) == 1s );
 static_assert( std::chrono::floor<seconds>(1001ms) == 1s );
 static_assert( std::chrono::floor<seconds>(1500ms) == 1s );
@@ -34,6 +36,7 @@ static_assert( std::chrono::floor<seconds>(1999ms) == 1s );
 static_assert( std::chrono::floor<seconds>(2000ms) == 2s );
 static_assert( std::chrono::floor<seconds>(2001ms) == 2s );
 static_assert( std::chrono::floor<seconds>(2500ms) == 2s );
+static_assert( std::chrono::floor<fp_seconds>(500ms) == fp_seconds{0.5f} );
 
 static_assert( std::chrono::ceil<seconds>(1000ms) == 1s );
 static_assert( std::chrono::ceil<seconds>(1001ms) == 2s );
@@ -42,6 +45,7 @@ static_assert( std::chrono::ceil<seconds>(1999ms) == 2s );
 static_assert( std::chrono::ceil<seconds>(2000ms) == 2s );
 static_assert( std::chrono::ceil<seconds>(2001ms) == 3s );
 static_assert( std::chrono::ceil<seconds>(2500ms) == 3s );
+static_assert( std::chrono::ceil<fp_seconds>(500ms) == fp_seconds{0.5f} );
 
 static_assert( std::chrono::round<seconds>(1000ms) == 1s );
 static_assert( std::chrono::round<seconds>(1001ms) == 1s );