Added the MPExpressionTree Classes
This commit is contained in:
36
MathPad/MPFractionFunction.m
Normal file
36
MathPad/MPFractionFunction.m
Normal file
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// MPFractionFunction.m
|
||||
// MathPad
|
||||
//
|
||||
// Created by Kim Wittenburg on 07.10.14.
|
||||
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPFractionFunction.h"
|
||||
|
||||
@implementation MPFractionFunction
|
||||
|
||||
MPFunctionAccessorImplementation(NominatorExpression, _nominatorExpression)
|
||||
MPFunctionAccessorImplementation(DenominatorExpression, _denominatorExpression)
|
||||
|
||||
- (NSArray *)childrenAccessors
|
||||
{
|
||||
return @[@"nominatorExpression", @"denominatorExpression"];
|
||||
}
|
||||
|
||||
- (BOOL)validate:(MPParseError *__autoreleasing *)error
|
||||
{
|
||||
return [[self.nominatorExpression parse] validate:error] && [[self.denominatorExpression parse] validate:error];
|
||||
}
|
||||
|
||||
- (NSDecimalNumber *)evaluate
|
||||
{
|
||||
return [[[self.nominatorExpression parse] evaluate] decimalNumberByDividingBy:[[self.denominatorExpression parse] evaluate]];
|
||||
}
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
return [NSString stringWithFormat:@"%@ / %@", self.nominatorExpression, self.denominatorExpression];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user