def round_out(fp: "FixedPoint", nfrac: int, /) -> "FixedPoint": """Round half away from zero.""" from fixedpoint.fixedpoint import FixedPoint ret: "FixedPoint" = FixedPoint._FixedPoint__new( # type: ignore fp.bits, fp.signed, fp.m, fp._n, fp.overflow, fp.rounding, fp.str_base, fp.overflow_alert, fp.implicit_cast_alert, fp.mismatch_alert) ret.round_out(nfrac) return ret
def round_down(fp: "FixedPoint", nfrac: int, /) -> "FixedPoint": """Round towards negative infinity.""" from fixedpoint.fixedpoint import FixedPoint ret: "FixedPoint" = FixedPoint._FixedPoint__new( # type: ignore fp.bits, fp.signed, fp.m, fp._n, fp.overflow, fp.rounding, fp.str_base, fp.overflow_alert, fp.implicit_cast_alert, fp.mismatch_alert) ret.round_down(nfrac) return ret
def round_nearest(fp: "FixedPoint", nfrac: int, /) -> "FixedPoint": """Round half up.""" from fixedpoint.fixedpoint import FixedPoint ret = FixedPoint(fp) ret.round_nearest(nfrac) return ret
m: int, n: int, /, rounding: str = None, overflow: str = None, alert: str = None) -> "FixedPoint": """Resize integer and fractional bit widths. Overflow handling, sign-extension, and rounding are employed. Override rounding, overflow, and overflow_alert settings for the scope of this function by specifying the appropriate arguments. """ from fixedpoint.fixedpoint import FixedPoint ret: "FixedPoint" = FixedPoint._FixedPoint__new( # type: ignore fp.bits, fp.signed, fp.m, fp._n, fp.overflow, fp.rounding, fp.str_base, fp.overflow_alert, fp.implicit_cast_alert, fp.mismatch_alert) ret.resize(m, n, rounding, overflow, alert) return ret def trim(fp: "FixedPoint", /, ints: bool = None, fracs: bool = None) -> "FixedPoint": """Trims off insignificant bits. This includes trailing 0s, leading 0s, and leading 1s as appropriate. Trim only integer bits or fractional bits by setting `fracs` or `ints` to True. By default, both integer and fractional bits are trimmed.
def decode(self, s: str, *args: Any, **kwargs: Any) -> "FixedPoint": """Decode a JSON document string s into a FixedPoint object.""" largs = self.decode_attributes(s, *args) from fixedpoint import FixedPoint return FixedPoint(hex(largs.pop()), *largs.pop(), **largs.pop())