def calculateSaleReturn(_supply, _reserveBalance, _reserveRatio, _sellAmount): # validate input assert(_supply != 0 and _reserveBalance != 0 and _reserveRatio > 0 and _reserveRatio <= 100 and _sellAmount <= _supply) # special case for 0 sell amount if (_sellAmount == 0): return 0 baseN = safeSub(_supply, _sellAmount) # special case if the CRR = 100 if (_reserveRatio == 100): temp1 = safeMul(_reserveBalance, _supply) temp2 = safeMul(_reserveBalance, baseN) return safeSub(temp1, temp2) / _supply # special case for selling the entire supply if (_sellAmount == _supply): return _reserveBalance resN = power(_supply, baseN, 100, _reserveRatio) temp1 = safeMul(_reserveBalance, resN) temp2 = safeMul(_reserveBalance, FIXED_ONE) return safeSub(temp1, temp2) / resN
def calculateSaleReturn(_supply, _reserveBalance, _reserveRatio, _sellAmount): # validate input assert (_supply != 0 and _reserveBalance != 0 and _reserveRatio > 0 and _reserveRatio <= 100 and _sellAmount <= _supply) # special case for 0 sell amount if (_sellAmount == 0): return 0 baseN = safeSub(_supply, _sellAmount) # special case if the CRR = 100 if (_reserveRatio == 100): temp1 = safeMul(_reserveBalance, _supply) temp2 = safeMul(_reserveBalance, baseN) return safeSub(temp1, temp2) / _supply # special case for selling the entire supply if (_sellAmount == _supply): return _reserveBalance resN = power(_supply, baseN, 100, _reserveRatio) temp1 = safeMul(_reserveBalance, resN) temp2 = safeMul(_reserveBalance, FIXED_ONE) result = safeSub(temp1, temp2) / resN #From the result, we deduct the minimal increment, which is a # function of R and precision. return safeSub(result, _reserveBalance / 0x100000000)
def calculatePurchaseReturn(_supply, _reserveBalance, _reserveRatio, _depositAmount): # validate input assert (_supply != 0 and _reserveBalance != 0 and _reserveRatio > 0 and _reserveRatio <= 100) # special case for 0 deposit amount if (_depositAmount == 0): return 0 baseN = safeAdd(_depositAmount, _reserveBalance) # special case if the CRR = 100 if (_reserveRatio == 100): temp = safeMul(_supply, baseN) / _reserveBalance return safeSub(temp, _supply) resN = power(baseN, _reserveBalance, _reserveRatio, 100) temp = safeMul(_supply, resN) / FIXED_ONE result = safeSub(temp, _supply) #From the result, we deduct the minimal increment, which is a # function of S and precision. return safeSub(result, _supply / 0x100000000)
def powerTest(_baseN, _baseD, _expN, _expD): fixed = power(_baseN, _baseD, _expN, _expD) >> PRECISION real = (Decimal(_baseN)/Decimal(_baseD))**(Decimal(_expN)/Decimal(_expD)) if fixed > real: error = [] error.append('error occurred on {}^{}:'.format(Decimal(_baseN)/Decimal(_baseD),Decimal(_expN)/Decimal(_expD))) error.append('fixed result = {}'.format(fixed)) error.append('real result = {}'.format(real)) raise BaseException('\n'.join(error)) return float(fixed / real)
def powerTest(baseN,baseD,expN,expD): precision = calculateBestPrecision(baseN,baseD,expN,expD) fixed = Decimal(power(baseN,baseD,expN,expD,precision))/(1<<precision) real = (Decimal(baseN)/Decimal(baseD))**(Decimal(expN)/Decimal(expD)) if fixed > real: error = [] error.append('error occurred on:') error.append('baseN = {}'.format(baseN)) error.append('baseD = {}'.format(baseD)) error.append('expN = {}'.format(expN)) error.append('expD = {}'.format(expD)) error.append('fixed = {}'.format(fixed)) error.append('real = {}'.format(real)) raise BaseException('\n'.join(error)) return fixed/real
def calculatePurchaseReturn(_supply, _reserveBalance, _reserveRatio, _depositAmount): # validate input assert(_supply != 0 and _reserveBalance != 0 and _reserveRatio > 0 and _reserveRatio <= 100) # special case for 0 deposit amount if (_depositAmount == 0): return 0 baseN = safeAdd(_depositAmount, _reserveBalance) # special case if the CRR = 100 if (_reserveRatio == 100): temp = safeMul(_supply, baseN) / _reserveBalance return safeSub(temp, _supply) resN = power(baseN, _reserveBalance, _reserveRatio, 100) temp = safeMul(_supply, resN) / FIXED_ONE return safeSub(temp, _supply)
display.lcd_clear() time.sleep(3) display.lcd_display_string(" Program ", 1) display.lcd_display_string(" Starting...", 2) time.sleep(10) display.lcd_clear() time.sleep(1) password.checkstart() try: while True: main_kp = keypad() main_cm = camera() main_gps = gps() main_pw = power() display.lcd_display_string("A)Phone B)Camera", 1) display.lcd_display_string("C)Park D)Power", 2) key = None while key == None: key = main_kp.getKey() if (key == "A"): time.sleep(0.4) main_kp.getNumberPhone() elif (key == "B"): time.sleep(0.4) main_cm.camera_on() elif (key == "C"): time.sleep(0.4) main_gps.checkLatLng() elif (key == "D"):