Archived
1

Cleaned Code by Removing Location Tracking for Errors

This commit is contained in:
Kim Wittenburg
2014-11-07 19:50:28 +01:00
parent 91e7dbe9f2
commit 139a75f816
59 changed files with 355 additions and 532 deletions

43
MathPad/MPRootFunction.m Normal file
View 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