Archived
1

Added Function Chooser as a Popover

Improved Evaluation
Added Parenthesis Function
This commit is contained in:
Kim Wittenburg
2014-09-28 23:52:29 +02:00
parent 1c8b7e3c12
commit 19a40c2907
16 changed files with 746 additions and 32 deletions

View File

@@ -0,0 +1,90 @@
//
// MPParenthesisFunction.m
// MathPad
//
// Created by Kim Wittenburg on 17.09.14.
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
//
#import "MPParenthesisFunction.h"
#import "MPExpressionEvaluator.h"
@implementation MPParenthesisFunction
+ (NSString *)localizedFunctionName
{
return NSLocalizedString(@"Parenthesis", @"Name of Parenthesis Function");
}
- (instancetype)init
{
self = [super init];
if (self) {
_expression = [[MPExpression alloc] init];
_expression.parent = self;
}
return self;
}
- (void)setExpression:(MPExpression *)expression
{
_expression.parent = nil;
_expression = expression;
_expression.parent = self;
}
- (NSUInteger)numberOfChildren
{
return 1;
}
- (MPExpression *)childAtIndex:(NSUInteger)index
{
return index == 0 ? self.expression : nil;
}
- (void)setChild:(MPExpression *)child
atIndex:(NSUInteger)index
{
if (index == 0) {
self.expression = child;
}
}
- (NSArray *)children
{
return @[self.expression];
}
- (MPTerm *)parseWithError:(MPParseError *__autoreleasing *)error
{
MPExpressionEvaluator *evaluator = self.expression.evaluator;
return [evaluator parseExpectingVariable:NO
error:error];
}
- (NSDecimalNumber *)evaluateWithError:(MPParseError *__autoreleasing *)error
{
return [self.expression evaluateWithError:error];
}
- (NSString *)description
{
return [NSString stringWithFormat:@"(%@)", self.expression.description];
}
- (NSUInteger)hash
{
#warning Unimplemented Method
return [super hash] * self.expression.hash;
}
- (id)copyWithZone:(NSZone *)zone
{
MPParenthesisFunction *copy = [[MPParenthesisFunction allocWithZone:zone] init];
copy.expression = self.expression.copy;
return copy;
}
@end