Simplify both versions of roundFixed (#12)

These simplifications slightly reduce the size of the generated code.
pull/14/head
Pharap 6 years ago committed by GitHub
parent bd84a2c69b
commit 4f8fe99153
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      src/FixedPoints/Utils.h

@ -127,21 +127,17 @@ template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction> roundFixed(const UFixed<Integer, Fraction> & value)
{
using OutputType = UFixed<Integer, Fraction>;
return (value.getInternal() & OutputType::MidpointMask) != 0 ? ceilFixed(value) : floorFixed(value);
return ((value.getFraction() >= OutputType(0.5).getFraction()) != 0) ? ceilFixed(value) : floorFixed(value);
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction> roundFixed(const SFixed<Integer, Fraction> & value)
{
using OutputType = SFixed<Integer, Fraction>;
return
(
((value.getInternal() & OutputType::MidpointMask) != 0) &&
(!signbitFixed(value) ||
((value.getInternal() & OutputType::LesserMidpointMask) != 0))
)
? ceilFixed(value)
: floorFixed(value);
return
signbitFixed(value)
? ((value.getFraction() <= OutputType(0.5).getFraction()) != 0) ? floorFixed(value) : ceilFixed(value)
: ((value.getFraction() >= OutputType(0.5).getFraction()) != 0) ? ceilFixed(value) : floorFixed(value);
}
template< unsigned Integer, unsigned Fraction >

Loading…
Cancel
Save