Boost C++ Libraries: Ticket #9419: boost::chrono::floor()/round() and negative durations is wrong https://svn.boost.org/trac10/ticket/9419 <p> The assert in the following program fails: </p> <pre class="wiki">#include &lt;boost/chrono/floor.hpp&gt; #include &lt;cassert&gt; int main() { boost::chrono::nanoseconds const nsec( -1 ); boost::chrono::seconds const sec = boost::chrono::floor&lt;boost::chrono::seconds&gt;(nsec); assert( sec.count() == -1 ); } </pre><p> Regards, Kris </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9419 Trac 1.4.3 1czajnik@… Fri, 22 Nov 2013 11:22:41 GMT attachment set https://svn.boost.org/trac10/ticket/9419 https://svn.boost.org/trac10/ticket/9419 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">chrono_rounding.cpp</span> </li> </ul> <p> unit test demonstrating the problem </p> Ticket 1czajnik@… Fri, 22 Nov 2013 11:26:56 GMT <link>https://svn.boost.org/trac10/ticket/9419#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9419#comment:1</guid> <description> <p> The attached unit test demonstrates the problem, as well as a problem with round&lt;&gt;, which I think doesn't follow the documented rule "tie towards even" for negative values. </p> <p> There are also overflow tests, and they all pass ;-) </p> <p> My output of this test is: </p> <pre class="wiki">Running 4 test cases... ../chrono_rounding.cpp(28): error in "floor_": check seconds(-2) == floor&lt;seconds&gt;( milliseconds(-1999) ) failed [-2 seconds != -1 second] ../chrono_rounding.cpp(29): error in "floor_": check seconds(-2) == floor&lt;seconds&gt;( milliseconds(-1001) ) failed [-2 seconds != -1 second] ../chrono_rounding.cpp(31): error in "floor_": check seconds(-1) == floor&lt;seconds&gt;( milliseconds(-999) ) failed [-1 second != 0 seconds] ../chrono_rounding.cpp(32): error in "floor_": check seconds(-1) == floor&lt;seconds&gt;( milliseconds(-1) ) failed [-1 second != 0 seconds] ../chrono_rounding.cpp(63): error in "round_": check seconds(-2) == round&lt;seconds&gt;( milliseconds(-1500) ) failed [-2 seconds != -1 second] *** 5 failures detected in test suite "Master Test Suite" </pre><p> HTH, Kris </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Fri, 22 Nov 2013 17:10:02 GMT</pubDate> <title>status, summary changed https://svn.boost.org/trac10/ticket/9419#comment:2 https://svn.boost.org/trac10/ticket/9419#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> <li><strong>summary</strong> <span class="trac-field-old">boost::chrono::floor() and negative durations is wrong</span> → <span class="trac-field-new">boost::chrono::floor()/round() and negative durations is wrong</span> </li> </ul> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/9419#comment:1" title="Comment 1">1czajnik@…</a>: </p> <blockquote class="citation"> <p> The attached unit test demonstrates the problem, as well as a problem with round&lt;&gt;, which I think doesn't follow the documented rule "tie towards even" for negative values. </p> <p> There are also overflow tests, and they all pass ;-) </p> <p> My output of this test is: </p> <pre class="wiki">Running 4 test cases... ../chrono_rounding.cpp(28): error in "floor_": check seconds(-2) == floor&lt;seconds&gt;( milliseconds(-1999) ) failed [-2 seconds != -1 second] ../chrono_rounding.cpp(29): error in "floor_": check seconds(-2) == floor&lt;seconds&gt;( milliseconds(-1001) ) failed [-2 seconds != -1 second] ../chrono_rounding.cpp(31): error in "floor_": check seconds(-1) == floor&lt;seconds&gt;( milliseconds(-999) ) failed [-1 second != 0 seconds] ../chrono_rounding.cpp(32): error in "floor_": check seconds(-1) == floor&lt;seconds&gt;( milliseconds(-1) ) failed [-1 second != 0 seconds] ../chrono_rounding.cpp(63): error in "round_": check seconds(-2) == round&lt;seconds&gt;( milliseconds(-1500) ) failed [-2 seconds != -1 second] *** 5 failures detected in test suite "Master Test Suite" </pre><p> HTH, Kris </p> </blockquote> <p> Thanks Kris for the report. </p> <p> I would take care of it. Clearly we missed the negative numbers :( </p> <p> Best, Vicente </p> Ticket viboes Tue, 03 Dec 2013 22:49:56 GMT milestone changed https://svn.boost.org/trac10/ticket/9419#comment:3 https://svn.boost.org/trac10/ticket/9419#comment:3 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.56.0</span> </li> </ul> Ticket viboes Sun, 23 Feb 2014 13:41:50 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/9419#comment:4 https://svn.boost.org/trac10/ticket/9419#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Merged to master <a class="ext-link" href="https://github.com/boostorg/chrono/commit/143260daeb2703961448a0928d199747ca34dfca"><span class="icon">​</span>https://github.com/boostorg/chrono/commit/143260daeb2703961448a0928d199747ca34dfca</a> </p> Ticket