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.
Test if two
APyCFloat
objects are identical.Constructor¶
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¶