Drastic Simplification of MPFunction subclass implementations
This commit is contained in:
40
MathPad/MPPowerFunction.m
Normal file
40
MathPad/MPPowerFunction.m
Normal 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
|
||||
Reference in New Issue
Block a user