mirror of
https://github.com/HowardHinnant/date.git
synced 2025-01-14 01:37:57 +08:00
Small negative floating point values should trunc and round to -0. instead of 0.
This commit is contained in:
parent
bf5fbe26ff
commit
e988efad90
7
date.h
7
date.h
@ -855,8 +855,13 @@ trunc(T t) NOEXCEPT
|
||||
static_assert(digits < numeric_limits<I>::digits, "");
|
||||
CONSTDATA auto max = I{1} << (digits-1);
|
||||
CONSTDATA auto min = -max;
|
||||
const auto negative = t < T{0};
|
||||
if (min <= t && t <= max && t != 0 && t == t)
|
||||
{
|
||||
t = static_cast<T>(static_cast<I>(t));
|
||||
if (t == 0 && negative)
|
||||
t = -t;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
@ -894,6 +899,8 @@ round(const std::chrono::duration<Rep, Period>& d)
|
||||
{
|
||||
auto t0 = floor<To>(d);
|
||||
auto t1 = t0 + To{1};
|
||||
if (t1 == To{0} && t0 < To{0})
|
||||
t1 = -t1;
|
||||
auto diff0 = d - t0;
|
||||
auto diff1 = t1 - d;
|
||||
if (diff0 == diff1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user