FixedPoint

class FixedPoint(value, fractional_bits=28, bit_width=32)[source][source]

Bases: object

Fixed-point numeric type for QUA-compatible saturated arithmetic.

Values are stored as signed integers scaled by 2**fractional_bits within a configurable bit width.

Create a fixed-point value from a float or integer scale.

Parameters:
  • value – Initial value (float interpreted in fixed-point units).

  • fractional_bits – Number of fractional bits in the representation.

  • bit_width – Total signed bit width including the sign bit.

to_int() int[source][source]

Return the value rounded toward zero as a Python integer.

to_unsafe_int() int[source][source]

Return the raw scaled integer without fractional-bit shifting.

to_float() float[source][source]

Return the value as a Python float.

classmethod from_int(int_value, fractional_bits=28, bit_width=32)[source][source]

Construct a FixedPoint from an integer fixed-point representation.

Parameters:
  • int_value – Scaled integer value (already in fixed-point units).

  • fractional_bits – Number of fractional bits.

  • bit_width – Total signed bit width.

Returns:

New FixedPoint instance.