def myAtoi(str):
    s = str.strip()
    if not s:
        return 0

    if s[0] in '-+':
        sign = {'-':-1,'+':1}[s[0]]
        s = s[1:]
    else:
        sign = 1

    n = sign * digits2int_b(iter_digit(s))
    return overflow32(n)
Esempio n. 2
0
def atoi(str):
    s = str.strip()
    if not s:
        return 0

    if s[0] in '-+':
        sign = {'-': -1, '+': 1}[s[0]]
        s = s[1:]
    else:
        sign = 1

    n = sign * digits2int_b(iter_digit(s))
    return overflow32(n)
Esempio n. 3
0
def divide(dividend, divisor):
    s = sign(dividend) * sign(divisor)
    q, r = divide_step(abs(dividend), abs(divisor), 1)
    return overflow32(s * q)
def divide(dividend, divisor):
    s = sign(dividend) * sign(divisor)
    q, r = divide_step(abs(dividend), abs(divisor), 1)
    return overflow32(s*q)
def reverse(x):
    n = sign(x) * digits2int_b(int2digits(abs(x)))
    return overflow32(n, 0, 0)