Archived
1

Drastic Simplification of MPFunction subclass implementations

This commit is contained in:
Kim Wittenburg
2014-09-30 22:17:42 +02:00
parent 0972e158f1
commit 7d48d85dfb
6 changed files with 106 additions and 185 deletions

40
MathPad/MPPowerFunction.m Normal file
View File

@@ -0,0 +1,40 @@
//
// MPPowerFunction.m
// MathPad
//
// Created by Kim Wittenburg on 30.09.14.
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
//
#import "MPPowerFunction.h"
#import "MPExpressionEvaluator.h"
@implementation MPPowerFunction
MPFunctionAccessorImplementation(ExponentExpression, _exponentExpression)
- (NSArray *)childrenAccessors
{
return @[@"exponentExpression"];
}
- (MPTerm *)parseWithError:(MPParseError *__autoreleasing *)error
{
MPTerm *exponentTerm = [self.exponentExpression.evaluator parseExpectingVariable:NO
error:error];
if (exponentTerm == nil) {
return nil;
}
return [[MPTerm alloc] initWithBlock:^NSDecimalNumber *{
double power = pow([self.baseTerm evaluate].doubleValue, [exponentTerm evaluate].doubleValue);
return [[NSDecimalNumber alloc] initWithDouble:power];
}];
}
- (NSString *)description
{
return [NSString stringWithFormat:@"^%@", self.exponentExpression.description];
}
@end