Skip to content

API Reference

qformatpy package.

MODULE DESCRIPTION
constants

Rounding method constants for use with Numba-optimized functions.

FUNCTION DESCRIPTION
qformat

Convert a numeric value to fixed-point representation using Q-format notation.

qformat

qformat(
    x: float | ndarray,
    qi: int,
    qf: int,
    signed: bool = True,
    rnd_method=TRUNC,
    ovf_method=WRAP,
) -> float | ndarray

Convert a numeric value to fixed-point representation using Q-format notation.

PARAMETER DESCRIPTION
x

The input value(s) to convert.

TYPE: (int, float or array - like)

qi

Number of integer bits (excluding sign bit if signed=True).

TYPE: int

qf

Number of fractional bits.

TYPE: int

signed

Whether the fixed-point format is signed (default is True).

TYPE: bool DEFAULT: True

rnd_method

Rounding method to apply (default is TRUNC (0)).

Supported methods:

  • TRUNC (0): Bit Truncation. Rounds towards negative infinity.
  • CEIL (1): Round toward positive infinity.
  • TO_ZERO (2): Round toward zero.
  • AWAY (3): Round away from zero.
  • HALF_UP (4): Round to nearest; ties round towards positive infinity.
  • HALF_DOWN (5): Round to nearest; ties round toward negative infinity.
  • HALF_EVEN (6): Round to nearest; ties round to even.
  • HALF_ZERO (7): Round to nearest; ties round toward zero.
  • HALF_AWAY (8): Round to nearest; ties round away from zero.

TYPE: int DEFAULT: TRUNC

ovf_method

Overflow handling method (default is WRAP (0)).

Supported methods:

  • WRAP (0): Wrap around on overflow (modulo behavior).
  • SAT (1): Saturate to maximum/minimum representable value.
  • ERROR (2): Raise an error if overflow occurs.

TYPE: int DEFAULT: WRAP

Returns:

float or ndarray Fixed-point representation of the input, as integer(s).

Notes:

Uses ARM-style Q-format notation where a Qm.n format has: - m integer bits (qi) - n fractional bits (qf) - Optional sign bit if signed is True