peng/functions.py
def round_mantissa(arg, decimals=0):
    """
    Round floating point number(s) mantissa to given number of digits.

    Integers are not altered. The mantissa used is that of the floating point
    number(s) when expressed in `normalized scientific notation
    <https://en.wikipedia.org/wiki/Scientific_notation#Normalized_notation>`_

    :param arg: Input data
    :type  arg: integer, float, Numpy vector of integers or floats, or None

    :param decimals: Number of digits to round the fractional part of the
                     mantissa to.
    :type  decimals: integer

    :rtype: same as **arg**

    For example::

        >>> import peng
        >>> peng.round_mantissa(012345678E-6, 3)
        12.35
        >>> peng.round_mantissa(5, 3)
        5
    """
    if arg is None:
        return arg
    if isinstance(arg, np.ndarray):
        foi = [isinstance(item, int) for item in arg]
        return np.array(
            [
                item if isint else float(to_scientific_string(item, decimals))
                for isint, item in zip(foi, arg)
            ]
        )
    if isinstance(arg, int):
        return arg
    return float(to_scientific_string(arg, decimals))
def round_mantissa(arg, decimals=0):
    """
    Round floating point number(s) mantissa to given number of digits.

    Integers are not altered. The mantissa used is that of the floating point
    number(s) when expressed in `normalized scientific notation
    <https://en.wikipedia.org/wiki/Scientific_notation#Normalized_notation>`_

    :param arg: Input data
    :type  arg: integer, float, Numpy vector of integers or floats, or None

    :param decimals: Number of digits to round the fractional part of the
                     mantissa to.
    :type  decimals: integer

    :rtype: same as **arg**

    For example::

        >>> import peng
        >>> peng.round_mantissa(012345678E-6, 3)
        12.35
        >>> peng.round_mantissa(5, 3)
        5
    """
    if arg is None:
        return arg
    if isinstance(arg, np.ndarray):
        foi = [isinstance(item, int) for item in arg]
        return np.array(
            [
                item if isint else float(to_scientific_string(item, decimals))
                for isint, item in zip(foi, arg)
            ]
        )
    if isinstance(arg, int):
        return arg
    return float(to_scientific_string(arg, decimals))
def round_mantissa ( arg , decimals = 0 ) : if arg is None : return arg if isinstance ( arg , np . ndarray ) : foi = [ isinstance ( item , int ) for item in arg ] return np . array ( [ item if isint else float ( to_scientific_string ( item , decimals ) ) for isint , item in zip ( foi , arg ) ] ) if isinstance ( arg , int ) : return arg return float ( to_scientific_string ( arg , decimals ) )
Round floating point number(s) mantissa to given number of digits.

    Integers are not altered. The mantissa used is that of the floating point
    number(s) when expressed in `normalized scientific notation
    <https://en.wikipedia.org/wiki/Scientific_notation#Normalized_notation>`_

    :param arg: Input data
    :type  arg: integer, float, Numpy vector of integers or floats, or None

    :param decimals: Number of digits to round the fractional part of the
                     mantissa to.
    :type  decimals: integer

    :rtype: same as **arg**

    For example::

        >>> import peng
        >>> peng.round_mantissa(012345678E-6, 3)
        12.35
        >>> peng.round_mantissa(5, 3)
        5
Round floating point number ( s ) mantissa to given number of digits .