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

42
MathKit/MPSumTerm.m Normal file
View File

@@ -0,0 +1,42 @@
//
// MPSumTerm.m
// MathPad
//
// Created by Kim Wittenburg on 14.11.14.
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
//
#import "MPSumTerm.h"
#import "MPParsedExpression.h"
#import "MPProductTerm.h"
#import "MPToken.h"
@implementation MPSumTerm
- (instancetype)initWithSummands:(NSArray *)summands
{
self = [super init];
if (self) {
NSAssert(summands != nil, @"summands must not be nil.");
NSAssert(summands.count > 0, @"summands must not be empty.");
_summands = summands;
}
return self;
}
- (NSDecimalNumber *)doEvaluation:(NSError *__autoreleasing *)error
{
NSDecimalNumber *value = [NSDecimalNumber zero];
for (MPTerm *summand in self.summands) {
NSDecimalNumber *currentValue = [summand evaluate:error];
if (!currentValue) {
return nil;
}
value = [value decimalNumberByAdding:currentValue];
}
return value;
}
@end