rwskit.numeric ============== .. py:module:: rwskit.numeric .. autoapi-nested-parse:: Utilities for numeric operations. Attributes ---------- .. autoapisummary:: rwskit.numeric.int_8_max rwskit.numeric.int_16_max rwskit.numeric.int_32_max rwskit.numeric.int_64_max Functions --------- .. autoapisummary:: rwskit.numeric.int_ rwskit.numeric.float_ rwskit.numeric.to_signed Module Contents --------------- .. py:data:: int_8_max :value: 255 .. py:data:: int_16_max :value: 65535 .. py:data:: int_32_max :value: 4294967295 .. py:data:: int_64_max :value: 18446744073709551615 .. py:function:: int_(s: Optional[str], falsy_as_none: bool = True) -> Optional[int] Convert a string `s` to an integer. If `s` is `None` return `None` instead of raising an exception. :param s: The string to convert. :type s: str, optional :param falsy_as_none: If `True` all falsy values of `s` (other than ``0``) will return `None`, otherwise only `None` values will be passed through and an exception will be raised. :type falsy_as_none: bool, default=True :returns: `None` if `s` is `None`, otherwise an integer if `s` is not `None` and is parseable. :rtype: int, optional :raises ValueError: If the string cannot be parsed. .. py:function:: float_(s: Optional[str], falsy_as_none: bool = True) -> Optional[float] Convert a string `s` to a float. If `s` is `None` return `None` instead of raising an exception. :param s: The string to convert. :type s: str, optional :param falsy_as_none: If `True` all falsy values of `s` will return `None` (other than ``0``), otherwise only `None` values will be passed through and an exception will be raised.. :type falsy_as_none: bool, default=True :returns: `None` if `s` is `None`, otherwise a float if `s` is not `None` and is parseable. :rtype: float, optional :raises ValueError: If the string cannot be parsed. .. py:function:: to_signed(value: int) -> int If the value is positive, this will return a signed version of the number that fits in the same size integer type. For example, ``129`` is a valid 8-bit signed integer, but a 16-bit unsigned integer. This method will convert the number to the corresponding signed integer that still fits in 8-bits. In this case ``127``. :param value: The value to convert. :type value: int :returns: The signed version. :rtype: int :raises ValueError: If the ``value`` is more than 64-bits.