FixedInt - round instead of truncate on construction

This could have caused issues where e.g. Fixed100(59.94) differed from
Fixed100::fromString("59.94") due to precision compilation flags
(the former could, and did on Devel builds, end up with Raw == 5993, which
differs from the value constructed from the string at the ini file,
and then it would be incorrectly identified as a custom rate).

Rounding seems the more likely intention when effectively decreasing the
precision of a value.

Unlikely that we have code which depends on truncating behavior, though not
impossible.
This commit is contained in:
Avi Halachmi (:avih) 2015-09-17 00:30:08 +03:00
parent 2d97f6dd53
commit d10bbb73f7
1 changed files with 2 additions and 2 deletions

View File

@ -33,13 +33,13 @@ FixedInt<Precision>::FixedInt( int signedval )
template< int Precision >
FixedInt<Precision>::FixedInt( double doubval )
{
Raw = (int)(doubval * (double)Precision);
Raw = lround(doubval * (double)Precision);
}
template< int Precision >
FixedInt<Precision>::FixedInt( float floval )
{
Raw = (int)(floval * (float)Precision);
Raw = lroundf(floval * (float)Precision);
}
template< int Precision >