12.8 Operations on Fixed-Point Variables

Support for fixed-point types includes:

  • Prefix and postfix increment and decrement operators (++, --)
  • Unary arithmetic operators (+, -, !)
  • Binary arithmetic operators (+, -, *, /)
  • Binary shift operators (<<, >>)
  • Relational operators (<, <=, >=, >)
  • Assignment operators (+=, -=, *=, /=, <<=, >>=)
  • Conversions to and from integer, floating-point, or fixed-point types
The following example shows how fixed-point multiplication might be implemented for a PIC32M device.
#include <stdfix.h>
sat fract test (sat fract a, sat fract b)
{
    return (a * b);
}
# Illustrative generated assembly with optimizations
test:
    mulq_rs.ph   $2,$4,$5
    j            $31