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/MathKit/MPPowerTerm.m
Kim Wittenburg 7438fd1f95 Added Lots of Documentation
Added some nice to haves
Improved and Unified General Code Layout
2015-01-04 02:54:27 +01:00

35 lines
1014 B
Objective-C

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