<commit_before>import Foundation

class CalculatorBrain{
    
    private var opStack = [Op]()
    
    private var knownOps = [String:Op]()
    
    var variableValues = [String:Double]()
    
    var description:String? {
        return opStackToString(opStack)
    }

    init(){
        knownOps = CalculatorOperations().learnOperations()
    }
    
    func pushOperand(symbol:String)->Double?{
        opStack.append(Op.Variable(symbol, variableValues[symbol]))
        return evaluate()
    }
    
    func pushOperand(operand:Double)->Double?{
        opStack.append(Op.Operand(operand))
        return evaluate()
    }
    
    func pushOperation(symbol:String){
        if let operation = knownOps[symbol] {
            opStack.append(operation)
        }
    }
    
    func evaluate()->Double?{
        var result:Double?
        if let expression=opStackToString(filteredOpStack){
            TryCatch.try { () -> Void in
                var expn = NSExpression(format:expression)
                result=Double(expn.expressionValueWithObject(nil, context: nil) as! NSNumber)
            };
        }
        return result
    }
    
    func clearOpStack(){
        opStack = [Op]()<commit_msg>cast result directly to double<commit_after>import Foundation

class CalculatorBrain{
    
    private var opStack = [Op]()
    
    private var knownOps = [String:Op]()
    
    var variableValues = [String:Double]()
    
    var description:String? {
        return opStackToString(opStack)
    }

    init(){
        knownOps = CalculatorOperations().learnOperations()
    }
    
    func pushOperand(symbol:String)->Double?{
        opStack.append(Op.Variable(symbol, variableValues[symbol]))
        return evaluate()
    }
    
    func pushOperand(operand:Double)->Double?{
        opStack.append(Op.Operand(operand))
        return evaluate()
    }
    
    func pushOperation(symbol:String){
        if let operation = knownOps[symbol] {
            opStack.append(operation)
        }
    }
    
    func evaluate()->Double?{
        var result:Double?
        if let expression=opStackToString(filteredOpStack){
            TryCatch.try { () -> Void in
                var expn = NSExpression(format:expression)
                result=expn.expressionValueWithObject(nil, context: nil) as? Double
            };
        }
        return result
    }
    
    func clearOpStack(){
        opStack = [Op]()
{'fraction_non_alphanumeric': 0.10491532424617926, 'fraction_numerical': 0.0, 'mean_word_length': 2.1743119266055047, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4531326', 'n_tokens_mistral': 679, 'n_tokens_neox': 673, 'n_words': 131}