Skip to content

Casting

qm.qua.lib.Cast

mul_fixed_by_int staticmethod

Multiplies a fixed x by an int y, returning a fixed

PARAMETER DESCRIPTION
x

a QUA fixed

y

a QUA int

RETURNS DESCRIPTION

a QUA fixed which equals x*y

mul_int_by_fixed staticmethod

Multiplies an int x by a fixed y, returning an int

PARAMETER DESCRIPTION
x

a QUA integer

y

a QUA fixed

RETURNS DESCRIPTION

a QUA int which equals x*y

to_bool staticmethod

Casts a variable to bool. Supports int, fixed or bool

PARAMETER DESCRIPTION
x

a QUA variable

RETURNS DESCRIPTION

a QUA bool

to_fixed staticmethod

Casts a variable to fixed. Supports int, fixed or bool

PARAMETER DESCRIPTION
x

a QUA variable

RETURNS DESCRIPTION

a QUA fixed

to_int staticmethod

Casts a variable to int. Supports int, fixed or bool

PARAMETER DESCRIPTION
x

a QUA variable

RETURNS DESCRIPTION

a QUA int

unsafe_cast_bool staticmethod

Treats the given input variable, bitwise, as a boolean. A boolean is determined by the right-most bit, so for a given integer, this is equivalent to a parity check.

Supports int, fixed or bool.

Warning

Saving a boolean number which was unsafely cast from an integer/fixed will give the wrong value in python.

PARAMETER DESCRIPTION
x

a QUA variable

RETURNS DESCRIPTION

a QUA bool

unsafe_cast_fixed staticmethod

Treats the given input variable, bitwise, as a fixed point number. For a given integer, this is equivalent to multiplying by \(2^{-28}\)

Supports int, fixed or bool.

PARAMETER DESCRIPTION
x

a QUA variable

RETURNS DESCRIPTION

a QUA fixed

unsafe_cast_int staticmethod

Treats the given input variable, bitwise, as an integer. For a given fixed point number, this is equivalent to multiplying by \(2^{28}\)

Supports int, fixed or bool.

PARAMETER DESCRIPTION
x

a QUA variable

RETURNS DESCRIPTION

a QUA int