Archived
1
This repository has been archived on 2022-08-08. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
mathpad/MathPad/MPPowerFunction.m

41 lines
1.0 KiB
Objective-C

//
// 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