Package: pyPhix
pyPhix, the Python Fixed Point modulepyPhixis a python package for fixed point number representation.
It is intended to support the implementation of digital signal processing systems.
As such only fix-point addition, subtraction and multiplication operations are implemented.You can find more information about the module objects and functionalities atreadthedocsproject page.Featuresvirtually unlimited number length (depending on your RAM size)based on NumPycustomizable rounding method (SymInf,SymZero,NonSymPos,NonSymNeg,ConvEven,ConvOdd,Floor,Ceil)customizable wrapping method (Sat,Wrap)support various representation formats (bin,hex,int,float)perform single or array based operations with customizable output format (+,-,*)LicensepyPhixpyPhix is an open source python module released under the terms ofMozilla Public License Version 2.0.NumPyNumPyis the fundamental package needed for scientific computing with Python and it is released under theseterms.InstallThepyPhixpackage is available onpypi.org.
You can install it by running:$ pip install pyphix.Alternatively you can clone thepyPhixrepository and from the folder containing thesetup.pyfile run:$ python setup installThis package requires Python 3.6 to work.You can also directly download the tar.gz archive frompypi.org.
The archive can be easily verified by adding the gpg public key1E948096166391C0to your keyring.Usage ExamplesFix FormatThis object is used to indicate the number of bits the user wants to use for value reprensetation.Create fix-point format objets:>>> from pyphix import fix
>>> fmt_a=fix.FixFmt(True, 2, 10)
>>> fmt_b=fix.FixFmt(False, 0, 7)Print the maximum representable ranges and test if a value is included in the range:>>> fmt_a.fixrange
(-4.0, 3.9990234375)

>>> fmt_b.fixrange
(0.0, 0.9921875)

>>> -10 in fmt_a
False

>>> 0 in fmt_b
TrueDifferent representations are available:>>> fmt_a.tuplefmt
(True, 2, 10)

>>> fmt_b.listfmt
[False, 0, 7]

>>> print(fmt_b)
(False, 0, 7)Fix NumberThis object contain fix-point number represenation.Round methods comparison, assuming format(True, 4, 5):Round methodPos odd fractionPos even fractionNeg odd fractionNeg even fractionReal value7.2968752.325-1.078125-1.08125Mult by 2^5233.574.4-34.5-34.6SymInf7.31252.3125-1.09375-1.09375SymZero7.281252.3125-1.0625-1.09375NonSymPos7.31252.3125-1.0625-1.09375NonSymNeg7.281252.3125-1.09375-1.09375ConvEven7.31252.3125-1.0625-1.09375ConvOdd7.281252.3125-1.09375-1.09375Floor7.281252.3125-1.09375-1.09375Ceil7.31252.34375-1.0625-1.0625A small usage example:>>> from pyphix import fix
>>> from pyphix.fix import ERoundMethod, EOverMethod
>>> fmt = fix.FixFmt(True, 4, 5)
>>> fix_vec = fix.FixNum(
        [7.296875,  2.325   , -1.078125, -1.08125], fmt,
        rnd=ERoundMethod.CONV_ODD, over=EOverMethod.WRAP)
>>> fix_val = fix.FixNum(
        1.16, fmt,
        rnd=ERoundMethod.CONV_ODD, over=EOverMethod.WRAP)Perform a full resolution addition:>>> fix_vec + fix_val
[8.4375  3.46875 0.0625  0.0625 ]

  fmt: (True, 5, 5)
  rnd: ERoundMethod.CONV_ODD
  over: EOverMethod.WRAPPerform a multiplication and cast result to a small format:>>> fix_val.mult(
        fix_vec, out_fmt=fix.FixFmt(False, 3, 2),
        rnd=ERoundMethod.SYM_INF, over=EOverMethod.SAT)
[7.75 2.75 0.   0.  ]

  fmt: (False, 3, 2)
  rnd: ERoundMethod.SYM_INF
  over: EOverMethod.SAT