FixedPointsArduino icon indicating copy to clipboard operation
FixedPointsArduino copied to clipboard

Replace use of LargerType in constructors with ShiftType

Open Pharap opened this issue 4 years ago • 1 comments

This change would have two potential benefits:

  • The undefined behaviour eminating from << with a negative left hand value would be replaced with the well-defined behaviour of an unsigned type.
  • Theoretically this should generate less code because the code would no longer be using unnecessary excess bytes during the shift operation. Whether this is true in practice would have to be tested - the compiler may already be optimising this.

The code should be functionally equivalent, hence this should be a 'patch' change.

Pharap avatar Mar 25 '21 18:03 Pharap

As a reminder: static_cast<InternalType>(static_cast<ShiftType>(value) << FractionSize)

Pharap avatar Mar 25 '21 18:03 Pharap