Skip to content

Casting

qm.qua.lib.Cast

mul_fixed_by_int staticmethod

mul_fixed_by_int(
    x: Scalar[float], y: Scalar[int]
) -> QuaLibFunctionOutput[float]

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

PARAMETER DESCRIPTION
x

a QUA fixed

TYPE: Scalar[float]

y

a QUA int

TYPE: Scalar[int]

RETURNS DESCRIPTION
QuaLibFunctionOutput[float]

a QUA fixed which equals x*y

mul_int_by_fixed staticmethod

mul_int_by_fixed(
    x: Scalar[int], y: Scalar[float]
) -> QuaLibFunctionOutput[int]

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

PARAMETER DESCRIPTION
x

a QUA integer

TYPE: Scalar[int]

y

a QUA fixed

TYPE: Scalar[float]

RETURNS DESCRIPTION
QuaLibFunctionOutput[int]

a QUA int which equals x*y

to_bool staticmethod

to_bool(x: Scalar[NumberT]) -> QuaLibFunctionOutput[bool]

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

PARAMETER DESCRIPTION
x

a QUA variable

TYPE: Scalar[NumberT]

RETURNS DESCRIPTION
QuaLibFunctionOutput[bool]

a QUA bool

to_fixed staticmethod

to_fixed(x: Scalar[NumberT]) -> QuaLibFunctionOutput[float]

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

PARAMETER DESCRIPTION
x

a QUA variable

TYPE: Scalar[NumberT]

RETURNS DESCRIPTION
QuaLibFunctionOutput[float]

a QUA fixed

to_int staticmethod

to_int(x: Scalar[NumberT]) -> QuaLibFunctionOutput[int]

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

PARAMETER DESCRIPTION
x

a QUA variable

TYPE: Scalar[NumberT]

RETURNS DESCRIPTION
QuaLibFunctionOutput[int]

a QUA int

unsafe_cast_bool staticmethod

unsafe_cast_bool(
    x: Scalar[NumberT],
) -> QuaLibFunctionOutput[bool]

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

TYPE: Scalar[NumberT]

RETURNS DESCRIPTION
QuaLibFunctionOutput[bool]

a QUA bool

unsafe_cast_fixed staticmethod

unsafe_cast_fixed(
    x: Scalar[NumberT],
) -> QuaLibFunctionOutput[float]

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

TYPE: Scalar[NumberT]

RETURNS DESCRIPTION
QuaLibFunctionOutput[float]

a QUA fixed

unsafe_cast_int staticmethod

unsafe_cast_int(
    x: Scalar[NumberT],
) -> QuaLibFunctionOutput[int]

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

TYPE: Scalar[NumberT]

RETURNS DESCRIPTION
QuaLibFunctionOutput[int]

a QUA int