Reorganized File Structure
Added Documentation
This commit is contained in:
42
MathKit/MPSumTerm.m
Normal file
42
MathKit/MPSumTerm.m
Normal 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
|
||||
Reference in New Issue
Block a user