示例#1
0
def round(x, *dig):  # in parsefuncs.function_handler.used_optlist
    if len(dig) == 0:
        return _round(x)
    else:
        if not _is_pointZero(dig[0]):
            raise MathError('<font color=red>round( )</font> ' +\
                            translate('MathErrors', _errors['oivDig']))
        else:
            return _round(x, int(dig[0]))
示例#2
0
def round(x, *dig):     # in parsefuncs.function_handler.used_optlist
    if len(dig) == 0:
        return _round(x)
    else:
        if not _is_pointZero(dig[0]):
            raise MathError('<font color=red>round( )</font> ' +\
                            translate('MathErrors', _errors['oivDig']))
        else:
            return _round(x, int(dig[0]))
示例#3
0
文件: mathutils.py 项目: zewt/pymel
def round(value, ndigits=0):
    """
    round(number[, ndigits]) -> float
    Round a number to a given precision in decimal digits (default 0 digits).
    This always returns a floating point number.  Precision may be negative.
    This builtin function was overloaded in mathutils to work on complex numbers,
    in that case rel and imaginary values are rounded separately

    """
    ndigits = int(ndigits)
    if isinstance(value, complex):
        return complex(_round(value.real, ndigits), _round(value.imag, ndigits))
    else:
        return _round(value, ndigits)
示例#4
0
def m_ftin(m):
    _foot = int(_abs(m_ft(m)))
    _inch = _round(ft_in(_abs(m_ft(m)) - _foot), 2)
    if _inch == int(_inch):
        _inch = int(_inch)
    return '{s}ftin_m({0}, {1})'.format(_foot, _inch,
                                        s='-' if m < 0 else '')
示例#5
0
def dd(degrees):
    _deg = int(_abs(degrees))
    _min = int((_abs(degrees) - _deg) * 60)
    _sec = _round((_abs(degrees) - _deg - _min / 60) * 3600)
    return '{s}dms({0}, {1}, {2})'.format(_deg,
                                          _min,
                                          _sec,
                                          s='-' if degrees < 0 else '')
示例#6
0
def rd(res):
    '''
    If there is a base2 incorrect transforms like 1.000000000000001
    or trigonometry calculaion like 0.4999999999999994,
    rounds eval()'s result to 12th symbol after floating point.
    If result is decimal but equal to integer,
    turn to integer truncating [.0].
    '''

    if isinstance(res, str):
        return res
    elif isinstance(res, int):
        if common._scientific_on and len(str(res)) > 16:
            return eval('{:.15e}'.format(res))
        else:
            return res
    elif 'e' in str(res):
        if res == int(res):
            if common._scientific_on:
                return res
            else:
                return int(res)
        else:
            return res
    elif isinstance(res, float) and not isfinite(res):
        raise ValueError(mathdocs.errors['mde'])
    elif _is_pointZero(res):
        return int(res)
    else:
        f = _round(res, 12)
        if _is_pointZero(f):
            return int(f)
        elif f == _round(res, 10):
            return f
        else:
            return res
示例#7
0
def rd(res):
    '''
    If there is a base2 incorrect transforms like 1.000000000000001
    or trigonometry calculaion like 0.4999999999999994,
    rounds eval()'s result to 12th symbol after floating point.
    If result is decimal but equal to integer,
    turn to integer truncating [.0].
    '''

    if isinstance(res, str):
        return res
    elif isinstance(res, int):
        if common._scientific_on and len(str(res)) > 16:
            return eval('{:.15e}'.format(res))
        else:
            return res
    elif 'e' in str(res):
        if res == int(res):
            if common._scientific_on:
                return res
            else:
                return int(res)
        else:
            return res
    elif isinstance(res, float) and not isfinite(res):
        raise ValueError(mathdocs.errors['mde'])
    elif _is_pointZero(res):
        return int(res)
    else:
        f = _round(res, 12)
        if _is_pointZero(f):
            return int(f)
        elif f == _round(res, 10):
            return f
        else:
            return res
示例#8
0
def dd(degrees):
    _deg = int(_abs(degrees))
    _min = int((_abs(degrees) - _deg) * 60)
    _sec = _round((_abs(degrees) - _deg - _min/60) * 3600)
    return '{s}dms({0}, {1}, {2})'.format(_deg, _min, _sec,
                                          s='-' if degrees < 0 else '')
示例#9
0
def dperc(old, new):
    return _round((new - old) / old * 100, 2)
示例#10
0
def m_ftin(m):
    _foot = int(_abs(m_ft(m)))
    _inch = _round(ft_in(_abs(m_ft(m)) - _foot), 2)
    if _inch == int(_inch):
        _inch = int(_inch)
    return '{s}ftin_m({0}, {1})'.format(_foot, _inch, s='-' if m < 0 else '')
示例#11
0
def dperc(old, new):
    return _round((new - old) / old * 100, 2)