APyCFloat
¶
- class apytypes.APyCFloat(*args, **kwargs)¶
Class for configurable complex-valued scalar floating-point formats.
Added in version 0.4.
Note
For real-valued floating-point formats, see
APyFloat
andAPyFloatArray
.- Attributes:
Methods
Change format of the complex-valued floating-point number.
copy
Create a copy of the object.
Test if two
APyCFloat
objects are identical.Constructor¶
- __init__(self, sign: bool | int, exp: int, man: int, exp_bits: int, man_bits: int, bias: int | None = None) None ¶
- __init__(self, sign: tuple[bool | int, bool | int], exp: tuple[int, int], man: tuple[int, int], exp_bits: int, man_bits: int, bias: int | None = None) None
Overloaded function.
__init__(self, sign: bool | int, exp: int, man: int, exp_bits: int, man_bits: int, bias: int | None = None) -> None
__init__(self, sign: tuple[bool | int, bool | int], exp: tuple[int, int], man: tuple[int, int], exp_bits: int, man_bits: int, bias: int | None = None) -> None
Create an
APyCFloat
object and initialize both real and imaginary parts.
- Parameters:
- sign
tuple
ofint
orbool
Sign of real/imaginary parts. True/non-zero equals negative.
- exp
tuple
ofint
Exponent of real/imaginary parts as stored, i.e., actual value + bias.
- man
tuple
ofint
Mantissa of the real/imaginary parts as stored, i.e., without a hidden one.
- exp_bits
int
Number of exponent bits.
- man_bits
int
Number of mantissa bits.
- bias
int
, optional Exponent bias. If not provided, bias is
2**exp_bits - 1
.
- sign
- Returns:
Creation from other types¶
- from_complex(value: object, exp_bits: int, man_bits: int, bias: int | None = None) APyCFloat ¶
Create an
APyCFloat
object from anint
,float
, orcomplex
.The initialize floating-point value is the one closest to value. Ties are rounded using
QuantizationMode.TIES_EVEN
.- Parameters:
- Returns:
See also
Examples
>>> import apytypes as apy >>> a = apy.APyCFloat.from_complex(1.375, exp_bits=10, man_bits=15) >>> a APyCFloat(sign=(0, 0), exp=(511, 0), man=(12288, 0), exp_bits=10, man_bits=15) >>> str(a) '(1.375+0j)'
- from_float(value: object, exp_bits: int, man_bits: int, bias: int | None = None) APyCFloat ¶
Create an
APyCFloat
object from anint
,float
, orcomplex
.The initialize floating-point value is the one closest to value. Ties are rounded using
QuantizationMode.TIES_EVEN
.- Parameters:
- valueint, float, complex
Value to initialize from.
- exp_bitsint
Number of exponent bits.
- man_bitsint
Number of mantissa bits.
- biasint, optional
Exponent bias. If not provided, bias is
2**exp_bits - 1
.
- Returns:
See also
Examples
>>> import apytypes as apy >>> a = apy.APyCFloat.from_float(1.25, exp_bits=10, man_bits=15) >>> a APyCFloat(sign=(0, 0), exp=(511, 0), man=(8192, 0), exp_bits=10, man_bits=15) >>> str(a) '(1.25+0j)'
Change word length¶
- cast(self, exp_bits: int | None = None, man_bits: int | None = None, bias: int | None = None, quantization: QuantizationMode | None = None) APyCFloat ¶
Change format of the complex-valued floating-point number.
This is the primary method for performing quantization when dealing with APyTypes floating-point numbers.
- Parameters:
- exp_bits
int
, optional Number of exponent bits in the result.
- man_bits
int
, optional Number of mantissa bits in the result.
- bias
int
, optional Exponent bias. If not provided, bias is
2**exp_bits - 1
.- quantization
QuantizationMode
, optional. Quantization mode to use in this cast. If None, use the global quantization mode.
- exp_bits
- Returns:
Comparison¶
Properties¶
Word length¶