//
//  MPFractionTerm.m
//  MathKit
//
//  Created by Kim Wittenburg on 15.11.14.
//  Copyright (c) 2014 Kim Wittenburg. All rights reserved.
//

#import "MPFractionTerm.h"

#import "MPParsedExpression.h"



@implementation MPFractionTerm

- (NSDecimalNumber *)doEvaluation:(NSError *__autoreleasing *)error
{
    MPEvaluateExpression(numerator, 0);
    MPEvaluateExpression(denominator, 1);
    if ([denominator isEqualToNumber:@0]) {
        if (error) {
            *error = [NSError errorWithDomain:MPMathKitErrorDomain
                                         code:100
                                     userInfo:@{NSLocalizedDescriptionKey: NSLocalizedString(@"Division by zero.", nil)}];
        }
        return nil;
    } else {
        return [numerator decimalNumberByDividingBy:denominator];
    }
}

@end
