(s, allow_nonnum=True)
return is_double, -mantissa if neg else mantissa, exp10
Return Float value for Python string.
Return Float value for Python string.
Return Float value for Python string .
def str_to_decimal(s, allow_nonnum=True):
    """Return Float value for Python string."""
    found_sign, found_point, found_exp = False, False, False
    found_exp_sign, exp_neg, neg = False, False, False
    exp10, exponent, mantissa, digits, zeros = 0, 0, 0, 0, 0
    is_double, is_single = False, False
    for c in iterchar(s):
        # ignore whitespace throughout (x = 1   234  56  .5  means x=123456.5 in gw!)
        if c in BLANKS:
            continue
        if c in SEPARATORS:
            # ASCII separator chars invariably lead to zero result
            return False, 0, 0
        # determine sign
        if (not found_sign):
            found_sign = True
            # number has started; if no sign encountered here, sign must be pos.
            if c in b'+-':
                neg = (c == b'-')
                continue
        # parse numbers and decimal points, until 'E' or 'D' is found
        if (not found_exp):
            if b'0' <= c <= b'9':
                mantissa *= 10
                mantissa += ord(c) - ord(b'0')
                if found_point:
                    exp10 -= 1
                # keep track of precision digits
                if mantissa != 0:
                    digits += 1
                    if found_point and c == b'0':
                        zeros += 1
                    else:
                        zeros = 0
                continue
            elif c == b'.':
                found_point = True
                continue
            elif c.upper() in b'DE':
                found_exp = True
                is_double = (c.upper() == b'D')
                continue
            elif c == b'!':
                # makes it a single, even if more than eight digits specified
                is_single = True
                break
            elif c == b'#':
                is_double = True
                break
            else:
                if allow_nonnum:
                    break
                raise ValueError('Non-numerical character in string')
        # parse exponent
        elif (not found_exp_sign):
            # exponent has started; if no sign given, it must be pos.
            found_exp_sign = True
            if c in b'+-':
                exp_neg = (c == b'-')
                continue
        if (b'0' <= c <= b'9'):
            exponent *= 10
            exponent += ord(c) - ord(b'0')
            continue
        else:
            if allow_nonnum:
                break
            raise ValueError('Non-numerical character in string')
    if exp_neg:
        exp10 -= exponent
    else:
        exp10 += exponent
    # eight or more digits means double, unless single override
    if digits - zeros > 7 and not is_single:
        is_double = True
    return is_double, -mantissa if neg else mantissa, exp10
def str_to_decimal ( s , allow_nonnum = True ) : found_sign , found_point , found_exp = False , False , False found_exp_sign , exp_neg , neg = False , False , False exp10 , exponent , mantissa , digits , zeros = 0 , 0 , 0 , 0 , 0 is_double , is_single = False , False for c in iterchar ( s ) : # ignore whitespace throughout (x = 1   234  56  .5  means x=123456.5 in gw!) if c in BLANKS : continue if c in SEPARATORS : # ASCII separator chars invariably lead to zero result return False , 0 , 0 # determine sign if ( not found_sign ) : found_sign = True # number has started; if no sign encountered here, sign must be pos. if c in b'+-' : neg = ( c == b'-' ) continue # parse numbers and decimal points, until 'E' or 'D' is found if ( not found_exp ) : if b'0' <= c <= b'9' : mantissa *= 10 mantissa += ord ( c ) - ord ( b'0' ) if found_point : exp10 -= 1 # keep track of precision digits if mantissa != 0 : digits += 1 if found_point and c == b'0' : zeros += 1 else : zeros = 0 continue elif c == b'.' : found_point = True continue elif c . upper ( ) in b'DE' : found_exp = True is_double = ( c . upper ( ) == b'D' ) continue elif c == b'!' : # makes it a single, even if more than eight digits specified is_single = True break elif c == b'#' : is_double = True break else : if allow_nonnum : break raise ValueError ( 'Non-numerical character in string' ) # parse exponent elif ( not found_exp_sign ) : # exponent has started; if no sign given, it must be pos. found_exp_sign = True if c in b'+-' : exp_neg = ( c == b'-' ) continue if ( b'0' <= c <= b'9' ) : exponent *= 10 exponent += ord ( c ) - ord ( b'0' ) continue else : if allow_nonnum : break raise ValueError ( 'Non-numerical character in string' ) if exp_neg : exp10 -= exponent else : exp10 += exponent # eight or more digits means double, unless single override if digits - zeros > 7 and not is_single : is_double = True return is_double , - mantissa if neg else mantissa , exp10