fix¶
-
class
pyphix.fix.FixFmt(signed, int_bits, frac_bits)[source]¶ Fix format class
Parameters: -
mask¶ Return mask to limit number representation (bit_length*ones).
Ex:
>>> from pyphix import fix >>> fmt = fix.FixFmt(True, 2, 3) >>> bin(fmt.mask) '0b111111'
>>> fmt = fix.FixFmt(False, 1, 12) >>> bin(fmt.mask) '0b1111111111111'
-
bit_length¶ Return the number of bits required to represent a number with current fix format.
-
maxvalue(fmt='float')[source]¶ Return max representable value by current fix format objext.
Parameters: fmt (EFormat or str) – format the value is presented, either hex, int, bin, float. Returns: max representable value. Return type: float or int or str
-
fixrange¶ Return the range representable by fix format object as tuple (min, max).
-
tuplefmt¶ Return object as a tuple.
-
listfmt¶ Return object as a list.
-
-
class
pyphix.fix.FixNum(value, fmt, rnd='SymZero', over='Wrap')[source]¶ Fixed point number class
Round methods SymInfpositive numbers tend to +inf, negative numbers to -inf SymZeroround toward zero (DEFAULT) NonSymPosround toward +inf NonSymNeground toward -inf ConvEvenround to closest even ConvOddround to closest odd Floorround to largest previous Ceilround to smallest following Overflow methods Satsaturate Wrapwrap around – DEFAULT Parameters: -
change_fix(new_fmt, new_rnd=None, new_over=None)[source]¶ Change fix parameters of current object.
WARNING: this action may lead to information loss due to new format and round/overflow methods.
Parameters: Returns: new formatted fix-point object.
Return type:
-
binfmt¶ Represent fix-point object in binary format.
-
hexfmt¶ Represent fix-point object in hexadecimal format.
-
intfmt¶ Represent fix-point object in integer format.
-
fimath¶ Return fix math as tuple (round method, overflow mode).
-
add(*args, **kwargs)[source]¶ Addition method.
Usage: add(other, out_fmt=None, out_rnd=”SymZero”, out_over=”Wrap”)
It allows to decide the output format. If not indicated, full-precision format will be adopted.
Parameters: Returns: addition result.
Return type:
-
sub(*args, **kwargs)[source]¶ Subtraction method.
Usage: sub(other, out_fmt=None, out_rnd=”SymZero”, out_over=”Wrap”)
It allows to decide output format. If not indicated, full-precision format will be adopted.
Parameters: Returns: operation result.
Return type:
-