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/MPSumTerm.m
Kim Wittenburg 8f1f730358 Reorganized File Structure
Added Documentation
2014-12-12 00:39:30 +01:00

43 lines
946 B
Objective-C

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