### Install fpbinary from GitHub repository Source: https://github.com/smlgit/fpbinary/blob/master/doc/intro.md Install the latest source code directly from the GitHub repository using pip or by cloning and running setup. ```bash pip install git+https://github.com/smlgit/fpbinary.git ``` ```bash git clone https://github.com/smlgit/fpbinary.git cd fpbinary python setup install ``` -------------------------------- ### Install fpbinary Locally Source: https://github.com/smlgit/fpbinary/blob/master/release/building_and_releasing.rst Use this command to install fpbinary locally. Setuptools will automatically handle compiler and linker tool selection for your machine. ```bash python setup.py install ``` -------------------------------- ### Install python3-dev on Linux Source: https://github.com/smlgit/fpbinary/blob/master/doc/intro.md If a Python.h header file is missing during installation, install the python3-dev package. ```bash sudo apt-get update sudo apt-get install python3-dev ``` -------------------------------- ### Install fpbinary on Linux Source: https://github.com/smlgit/fpbinary/blob/master/doc/intro.md Install the fpbinary package using pip. Ensure a C99 compliant compiler is available. ```bash pip install fpbinary ``` -------------------------------- ### Get help for fpbinary objects Source: https://github.com/smlgit/fpbinary/blob/master/doc/intro.md Access help documentation for FpBinary, FpBinaryComplex, and FpBinarySwitchable objects to understand their usage. ```python from fpbinary import FpBinary, FpBinarySwitchable help(FpBinary) help(FpBinaryComplex) help(FpBinarySwitchable) ``` -------------------------------- ### Set Package Version in setup.py Source: https://github.com/smlgit/fpbinary/blob/master/release/building_and_releasing.rst This shows how the package version is set within the setup function in setup.py. The 'version' variable is dynamically determined. ```python setup(name='fpbinary', version=version, ...) ``` -------------------------------- ### Run Release Build with TestPyPI Installation Source: https://github.com/smlgit/fpbinary/blob/master/release/building_and_releasing.rst Perform a release build, installing packages from test.pypi.org. This is done after successful non-release builds. Replace with the target branch. ```bash python release/run_build.py --install-from-testpypi --release ``` -------------------------------- ### Build HTML Documentation Locally Source: https://github.com/smlgit/fpbinary/blob/master/release/building_and_releasing.rst Generate HTML documentation locally using Sphinx. Ensure Sphinx and its extensions (napoleon, autodoc) are installed. Run this command from the 'doc' directory. ```bash make html ``` -------------------------------- ### Run Non-Release Build with TestPyPI Installation Source: https://github.com/smlgit/fpbinary/blob/master/release/building_and_releasing.rst Execute a non-release build and install packages from test.pypi.org to test functionality across all platforms. Replace with the target branch. ```bash python release/run_build.py --install-from-testpypi ``` -------------------------------- ### Execute Release Script Source: https://github.com/smlgit/fpbinary/blob/master/release/building_and_releasing.rst Run the main release script after successful builds. This script uploads packages to PyPI, runs installation tests, and creates a GitHub release tag. Replace with the appropriate build name. ```bash python release/release.py ``` -------------------------------- ### FpBinarySwitchable Value Property Source: https://github.com/smlgit/fpbinary/blob/master/doc/objects.md Sets or gets the underlying value. Can accept FpBinary or FpBinarySwitchable types in fixed-point mode, or any float-castable object in floating-point mode. Tracks min/max values when in floating-point mode. ```python value ``` -------------------------------- ### Basic FpBinary object usage Source: https://github.com/smlgit/fpbinary/blob/master/doc/intro.md Create and manipulate an FpBinary object, demonstrating initialization with integer and fractional bits, value assignment, and resizing. ```python fp_num = FpBinary(int_bits=4, frac_bits=4, signed=True, value=2.5) fp_num fp_num.format fp_num * 2.0 fp_num.resize((1,4)) ``` -------------------------------- ### DSP Simulation with FpBinarySwitchable Source: https://github.com/smlgit/fpbinary/blob/master/doc/intro.md Demonstrates how to use FpBinarySwitchable to switch between fixed and floating-point math operations within a DSP simulation. The `fp_mode` constructor argument controls the behavior. ```python def dsp_sim(fp_mode): num1 = FpBinarySwitchable(fp_mode=fp_mode, fp_value=FpBinary(8, 8, value=6.7), float_value=6.7) num2 = FpBinary(16, 16, value=0.005) num3 = (num1 * num2).resize((8, 8), overflow_mode=OverflowEnum.wrap, rounding_mode=RoundingEnum.direct_neg_inf) # Do other stuff... return num3 ``` -------------------------------- ### Tracking Min/Max Values with FpBinarySwitchable Source: https://github.com/smlgit/fpbinary/blob/master/doc/intro.md Illustrates the use of FpBinarySwitchable's `value` property to track minimum and maximum values during simulation. This helps in determining the required fixed-point format for data points. ```python inp = FpBinarySwitchable(fp_mode=fp_mode, fp_value=FpBinary(8, 8, value=0.0), float_value=0.0) scaled = FpBinarySwitchable(fp_mode=fp_mode, fp_value=FpBinary(16, 16, value=0.0), float_value=0.0) def some_dsp_next_sample(sample): inp.value = sample.resize(format_inst=inp) scaled.value = inp * scale_factor # .... return val def run(fp_mode): # call some_dsp_next_sample a whole heap return inp.min_value, inp.max_value, scaled.min_value, scaled.max_value ``` -------------------------------- ### FpBinary Class Constructor Source: https://github.com/smlgit/fpbinary/blob/master/doc/objects.md Initializes an FpBinary object representing a real number using fixed-point math and structure. It allows configuration of integer and fractional bits, signedness, and initial value. ```APIDOC ## FpBinary Constructor ### Description Initializes an FpBinary object with specified integer and fractional bits, signedness, and an initial value or bit field representation. ### Parameters * **int_bits** (int) - The number of bits for the integer part. Can be negative to adjust fractional bits. * **frac_bits** (int) - The number of bits for the fractional part. Can be negative to adjust integer bits. * **signed** (bool) - Whether the representation is signed (True) or unsigned (False). * **value** (float) - The initial floating-point value. Rounded and saturated if precision is insufficient. * **bit_field** (int) - A 2's complement representation of the value, overriding `value`. * **format_inst** (FpBinary) - An existing FpBinary instance to copy format settings from. ``` -------------------------------- ### FpBinaryComplex Constructor Source: https://github.com/smlgit/fpbinary/blob/master/doc/objects.md Initializes a complex number using fixed point math and structure. ```APIDOC ## FpBinaryComplex(int_bits=1, frac_bits=0, value=0j, real_fp_binary=None, imag_fp_binary=None, real_bit_field=None, imag_bit_field=None, format_inst=None) ### Description Represents a complex number using fixed point math and structure. ### Parameters * **int_bits** (*int*) – The number of bits to use to represent the integer part. This value may be negative - this simply removes that number of bits from the fractional bits. The frac_bits param still specifies the position of the least significant fractional bit but the total bits are int_bits + fract_bits. For example, a format of (-3, 6) would produce an instance with 3 fractional bits with a maximum value (assuming unsigned) of 2.0\*\*-4 + 2.0\*\*-5 + 2.0\*\*-6. * **frac_bits** (*int*) – The number of bits to use to represent the fractional part. This value may be negative - this simply removes that number of bits from the int bits. The int_bits param still specifies the position of the most significant integer bit but the total bits are int_bits + fract_bits. For example, a format of (6, -3) would produce an instance with 3 integer bits with a maximum value (assuming unsigned) of 2.0\**5 + 2.0\**4 + 2.0\**3. (Note that integer powers start at 0). * **value** (*float/complex*) – The value to initialise the fixed point object to. If int_bits and frac_bits do not provide enough precision to represent value fully, rounding will be done using RoundingEnum.near_pos_inf and overflow will be handled using OverflowEnum.sat. * **real_fp_binary** ([*FpBinary*](#fpbinary.FpBinary)) – The real part of the FpBinaryComplex instance can be set to the value of an FpBinary instance. The format will also be used if it isn’t specified explicitly. * **imag_fp_binary** ([*FpBinary*](#fpbinary.FpBinary)) – The imag part of the FpBinaryComplex instance can be set to the value of an FpBinary instance. The format will also be used if it isn’t specified explicitly. * **real_bit_field** (*int*) – If the precision of the desired initialise value is too great for the native float type, real_bit_field can be set to a 2’s complement representation of the desired real value * 2**frac_bits. Note that real_bit_field overrides the value parameter. * **imag_bit_field** (*int*) – If the precision of the desired initialise value is too great for the native float type, real_bit_field can be set to a 2’s complement representation of the desired imaginary value * 2**frac_bits. Note that imag_bit_field overrides the value parameter. * **format_inst** ([*FpBinary*](#fpbinary.FpBinary)) – If set, the int_bits and frac_bits values will be taken from the format of format_inst. ``` -------------------------------- ### FpBinarySwitchable Initialization Source: https://github.com/smlgit/fpbinary/blob/master/doc/objects.md Initializes an FpBinarySwitchable object, which can represent either fixed-point or floating-point values based on fp_mode. Requires an FpBinary instance if in fixed-point mode. ```python FpBinarySwitchable(fp_mode, fp_value=None, float_value=0.0) ``` -------------------------------- ### Security File Structure for Release Scripts Source: https://github.com/smlgit/fpbinary/blob/master/release/building_and_releasing.rst This JSON structure is required for the release/build scripts to access online services. Ensure all tokens are correctly populated. ```json { "APPVEYOR": {"token": , "account": "smlgit"}, "TESTPYPI": {"token": }, "PYPI": {"token": }, "GITHUB": {"token": } } ``` -------------------------------- ### FpBinary str_ex() Method Source: https://github.com/smlgit/fpbinary/blob/master/doc/objects.md Returns a string representation of the fixed-point object without scientific notation, useful for values exceeding native float precision. ```python str_ex() ``` -------------------------------- ### FpBinary Resize Method Source: https://github.com/smlgit/fpbinary/blob/master/doc/objects.md Resizes the fixed-point object in place to a new format. Overflow and rounding modes can be specified. ```python resize(overflow_mode=0, round_mode=2) ``` -------------------------------- ### format Property Source: https://github.com/smlgit/fpbinary/blob/master/doc/objects.md Provides read-only access to the fixed-point format of the FpBinary object as a tuple of (int_bits, frac_bits). ```APIDOC ## format ### Description Read-only property that returns a tuple representing the fixed-point format (integer bits, fractional bits). ### Type tuple ``` -------------------------------- ### FpBinary.str_ex Source: https://github.com/smlgit/fpbinary/blob/master/doc/objects.md Returns a string representation of the fixed point object's full precision value, avoiding scientific notation. ```APIDOC ## str_ex() ### Description Returns a str displaying the full precision value of the fixed point object. This is useful when the fixed point value has more bits than native floating point types can handle. Note that scientific notation is not used. ### Parameters **None** ### Returns Non-scientific notation string representation of the instance value. ### Return type str or unicode ``` -------------------------------- ### FpBinary.resize Source: https://github.com/smlgit/fpbinary/blob/master/doc/objects.md Resizes the fixed point object in place to a new format. Allows control over overflow and rounding. ```APIDOC ## resize(overflow_mode=0, round_mode=2) ### Description Resizes the fixed point object IN PLACE to the format described by format. ### Parameters * **format** (*length 2 tuple* *or* *instance* *of* *this object.*) – If tuple, will be resized to format[0] int bits and format[1] frac bits. If instance of this type, the format will be taken from format. * **overflow_mode** ([*fpbinary.OverflowEnum*](#fpbinary.OverflowEnum) *,* *optional*) – Specifies how to deal with overflows when int bits are reduced. Default is wrap. * **round_mode** ([*fpbinary.RoundingEnum*](#fpbinary.RoundingEnum) *,* *optional*) – Specifies how to deal with rounding when frac bits are reduced. Default is direct_neg_inf. ### Returns self ### Return type FpBinary/FpBinaryComplex ``` -------------------------------- ### is_signed Property Source: https://github.com/smlgit/fpbinary/blob/master/doc/objects.md Indicates whether the FpBinary object represents a signed or unsigned number. Read-only. ```APIDOC ## is_signed ### Description Read-only property that is True if the fixed-point object is signed, False otherwise. ### Type bool ``` -------------------------------- ### FpBinarySwitchable.resize Source: https://github.com/smlgit/fpbinary/blob/master/doc/objects.md Resizes the FpBinarySwitchable object if it is in fixed-point mode. If in floating-point mode, this operation does nothing. ```APIDOC ## resize(overflow_mode=0, round_mode=2) ### Description If fp_mode is True, this method does what FpBinary.resize() does. If fp_mode is False, nothing is done. ### Parameters **FpBinary.resize****(****)** (*See*) ### Returns self ### Return type [FpBinarySwitchable](#fpbinary.FpBinarySwitchable) ``` -------------------------------- ### bits_to_signed() Source: https://github.com/smlgit/fpbinary/blob/master/doc/objects.md Interprets the bits of the FpBinary object as a 2's complement signed integer and returns it. Handles unsigned objects by considering the MSB as a sign bit. ```APIDOC ## bits_to_signed() ### Description Interprets the internal bits of the FpBinary object as a signed integer using 2's complement representation. ### Parameters None ### Returns The object's bits interpreted as a signed integer. ### Return type int ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.