import math from Custom import CustomBase import API class logX (CustomBase): stack = None def __init__(self, stack): self.stack = stack # __init__ def help(self): msg = "logX\n" msg += "----\n\n" msg += "Takes r0 and r1 from the stack\n\n" msg += "Calculates the logarithm of r1 to the base r0\n\n" msg += "Pushes the result to r0" API.showPopup('Custom function', msg, font=('Courier',API.helpFontSize)) # If you want to implement translated texts, you can use the API.t(textKey) function: # API.showPopup('Custom function', API.t(API.programName+'.CustomFunctions.logX.btnHLP')) # help def calculate(self): if self.stack.inputMode != 'DEC': API.toast('This operation is only supported in DEC mode') # If you want to implement translated texts, you can use the API.t(textKey) function: # API.toast(API.t(API.programName+'.CustomFunctions.logX.onlySupportedinDEC')) return if self.stack.finishEntry() == -1: return # abort here because data in input line is invalid if self.stack.size() < 2: API.toast('This operation needs 2 argument') return x = self.stack.getRegister(1) _base = self.stack.getRegister(0) self.stack.pop(2) self.stack.push(math.log(x,_base)) # calculate # log