Archived
1

Reorganized File Structure

Added Documentation
This commit is contained in:
Kim Wittenburg
2014-12-12 00:39:30 +01:00
parent c367b1dbe8
commit 8f1f730358
90 changed files with 1270 additions and 1216 deletions

31
MathKit/MPPowerTerm.m Normal file
View File

@@ -0,0 +1,31 @@
//
// MPPowerTerm.m
// MathPad
//
// Created by Kim Wittenburg on 15.11.14.
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
//
#import "MPPowerTerm.h"
#import "MPParsedExpression.h"
@implementation MPPowerTerm
- (NSDecimalNumber *)doEvaluation:(NSError *__autoreleasing *)error
{
MPEvaluateExpression(exponent, 0);
NSDecimalNumber *base = [self.baseTerm evaluate:error];
ReturnNilIfNil(base);
if ([base isEqualToNumber:@(0)] && [exponent isEqualToNumber:@(0)]) {
// The C pow function returns 1 for pow(0, 0). Mathematically this should be undefined.
if (error) {
*error = [NSError errorWithDomain:MPMathKitErrorDomain
code:101
userInfo:@{NSLocalizedDescriptionKey: NSLocalizedString(@"0 to the power of 0 is undefined.", nil)}];
}
return nil;
}
return [[NSDecimalNumber alloc] initWithDouble:pow(base.doubleValue, exponent.doubleValue)];
}
@end