Archived
1

Implemented Expression Evaluation/Parsing with Proper Error Handling

This commit is contained in:
Kim Wittenburg
2014-09-11 22:17:29 +02:00
parent f791213127
commit 245468a559
16 changed files with 670 additions and 330 deletions

51
MathPad/MPParsedProduct.m Normal file
View File

@@ -0,0 +1,51 @@
//
// MPParsedSummand.m
// MathPad
//
// Created by Kim Wittenburg on 10.09.14.
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
//
#import "MPParsedProduct.h"
@implementation MPParsedProduct {
NSMutableArray *_factors;
}
- (instancetype)init
{
self = [super init];
if (self) {
_factors = [[NSMutableArray alloc] init];
}
return self;
}
- (NSArray *)factors
{
return _factors;
}
- (void)addFactor:(MPParsedFactor *)factor
{
[_factors addObject:factor];
}
- (NSDecimalNumber *)value
{
if (_factors.count == 0) {
return [NSDecimalNumber zero];
}
NSDecimalNumber *value = [NSDecimalNumber one];
for (MPParsedFactor *factor in _factors) {
value = [value decimalNumberByMultiplyingBy:factor.value];
}
return value;
}
- (NSString *)description
{
return [NSString stringWithFormat:@"MPParsedProduct<%@>", [_factors componentsJoinedByString:@"*"]];
}
@end