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
Kim Wittenburg 82259f87e2 Model Redesign: Added Reference Frames
Added Inverse Functions
UI Redesign
Cleaned Code
2014-10-07 20:25:54 +02:00

42 lines
1.1 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
{
MPExpressionEvaluator *exponent = [[MPExpressionEvaluator alloc] initWithExpression:self.exponentExpression];
MPTerm *exponentTerm = [exponent 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