Cleaned Code by Removing Location Tracking for Errors
This commit is contained in:
43
MathPad/MPRootFunction.m
Normal file
43
MathPad/MPRootFunction.m
Normal file
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// MPRootFunction.m
|
||||
// MathPad
|
||||
//
|
||||
// Created by Kim Wittenburg on 22.10.14.
|
||||
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPRootFunction.h"
|
||||
|
||||
#import "MPExpressionTree.h"
|
||||
|
||||
@implementation MPRootFunction
|
||||
|
||||
MPFunctionAccessorImplementation(ExponentExpression, _exponentExpression)
|
||||
MPFunctionAccessorImplementation(RadicantExpression, _radicantExpression)
|
||||
|
||||
- (NSArray *)childrenAccessors
|
||||
{
|
||||
return @[@"exponentExpression", @"radicantExpression"];
|
||||
}
|
||||
|
||||
- (BOOL)validate:(NSError *__autoreleasing *)error
|
||||
{
|
||||
return [[self.exponentExpression parse] validate:error] && [[self.radicantExpression parse] validate:error];
|
||||
}
|
||||
|
||||
- (NSDecimalNumber *)evaluate
|
||||
{
|
||||
NSDecimalNumber *exponent = [[self.exponentExpression parse] evaluate];
|
||||
NSDecimalNumber *radicant = [[self.radicantExpression parse] evaluate];
|
||||
return [[NSDecimalNumber alloc] initWithDouble:pow(radicant.doubleValue, exponent.doubleValue)];
|
||||
}
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
if (self.exponentExpression == nil) {
|
||||
return [NSString stringWithFormat:@"√%@", self.radicantExpression.description];
|
||||
}
|
||||
return [NSString stringWithFormat:@"pow(%@; %@)", self.radicantExpression.description, self.exponentExpression];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user