Opened 9 years ago
Closed 9 years ago
#9419 closed Bugs (fixed)
boost::chrono::floor()/round() and negative durations is wrong
Reported by: | Owned by: | viboes | |
---|---|---|---|
Milestone: | Boost 1.56.0 | Component: | chrono |
Version: | Boost 1.54.0 | Severity: | Problem |
Keywords: | Cc: |
Description
The assert in the following program fails:
#include <boost/chrono/floor.hpp> #include <cassert> int main() { boost::chrono::nanoseconds const nsec( -1 ); boost::chrono::seconds const sec = boost::chrono::floor<boost::chrono::seconds>(nsec); assert( sec.count() == -1 ); }
Regards, Kris
Attachments (1)
Change History (5)
by , 9 years ago
Attachment: | chrono_rounding.cpp added |
---|
follow-up: 2 comment:1 by , 9 years ago
The attached unit test demonstrates the problem, as well as a problem with round<>, which I think doesn't follow the documented rule "tie towards even" for negative values.
There are also overflow tests, and they all pass ;-)
My output of this test is:
Running 4 test cases... ../chrono_rounding.cpp(28): error in "floor_": check seconds(-2) == floor<seconds>( milliseconds(-1999) ) failed [-2 seconds != -1 second] ../chrono_rounding.cpp(29): error in "floor_": check seconds(-2) == floor<seconds>( milliseconds(-1001) ) failed [-2 seconds != -1 second] ../chrono_rounding.cpp(31): error in "floor_": check seconds(-1) == floor<seconds>( milliseconds(-999) ) failed [-1 second != 0 seconds] ../chrono_rounding.cpp(32): error in "floor_": check seconds(-1) == floor<seconds>( milliseconds(-1) ) failed [-1 second != 0 seconds] ../chrono_rounding.cpp(63): error in "round_": check seconds(-2) == round<seconds>( milliseconds(-1500) ) failed [-2 seconds != -1 second] *** 5 failures detected in test suite "Master Test Suite"
HTH, Kris
comment:2 by , 9 years ago
Status: | new → assigned |
---|---|
Summary: | boost::chrono::floor() and negative durations is wrong → boost::chrono::floor()/round() and negative durations is wrong |
Replying to 1czajnik@…:
The attached unit test demonstrates the problem, as well as a problem with round<>, which I think doesn't follow the documented rule "tie towards even" for negative values.
There are also overflow tests, and they all pass ;-)
My output of this test is:
Running 4 test cases... ../chrono_rounding.cpp(28): error in "floor_": check seconds(-2) == floor<seconds>( milliseconds(-1999) ) failed [-2 seconds != -1 second] ../chrono_rounding.cpp(29): error in "floor_": check seconds(-2) == floor<seconds>( milliseconds(-1001) ) failed [-2 seconds != -1 second] ../chrono_rounding.cpp(31): error in "floor_": check seconds(-1) == floor<seconds>( milliseconds(-999) ) failed [-1 second != 0 seconds] ../chrono_rounding.cpp(32): error in "floor_": check seconds(-1) == floor<seconds>( milliseconds(-1) ) failed [-1 second != 0 seconds] ../chrono_rounding.cpp(63): error in "round_": check seconds(-2) == round<seconds>( milliseconds(-1500) ) failed [-2 seconds != -1 second] *** 5 failures detected in test suite "Master Test Suite"HTH, Kris
Thanks Kris for the report.
I would take care of it. Clearly we missed the negative numbers :(
Best, Vicente
comment:3 by , 9 years ago
Milestone: | To Be Determined → Boost 1.56.0 |
---|
comment:4 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
unit test demonstrating the problem