Added Lots of Documentation
Added some nice to haves Improved and Unified General Code Layout
This commit is contained in:
@@ -9,13 +9,10 @@
|
||||
#import "MPElementaryFunctionTerm.h"
|
||||
|
||||
#import "MPParsedExpression.h"
|
||||
#import "MPPowerFunction.h"
|
||||
#import "MPProductTerm.h"
|
||||
#import "MPToken.h"
|
||||
|
||||
#import "MPExpression.h"
|
||||
#import "MPMathRules.h"
|
||||
|
||||
|
||||
|
||||
@implementation MPElementaryFunctionTerm {
|
||||
NSDecimalNumber *(^_function)(NSDecimalNumber *);
|
||||
}
|
||||
@@ -53,16 +50,18 @@
|
||||
} else if ([function isEqualToString:@"ln"]) {
|
||||
func = &log;
|
||||
} else {
|
||||
NSAssert(true, @"function must be one of (sin, cos, tan, asin, acos, atan, lg, log, ln).");
|
||||
NSAssert(true, @"function must be one of (sin, cos, tan, asin, arcsin, acos, arccos, atan, arctan, lg, log, ln).");
|
||||
}
|
||||
[self setFunction:func
|
||||
takesArcValue:takesArc
|
||||
returnsArcValue:returnsArc];
|
||||
_term = term;
|
||||
_functionIdentifier = function.copy;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (void)setFunction:(double (*)(double))function
|
||||
takesArcValue:(BOOL)takesArc
|
||||
returnsArcValue:(BOOL)returnsArc
|
||||
@@ -80,6 +79,7 @@
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
- (NSDecimalNumber *)convertToRadiantsIfNecessary:(NSDecimalNumber *)degrees
|
||||
{
|
||||
if ([MPMathRules sharedRules].isUsingDegrees) {
|
||||
@@ -90,6 +90,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (NSDecimalNumber *)convertToDegreesIfNecessary:(NSDecimalNumber *)radiants
|
||||
{
|
||||
if ([MPMathRules sharedRules].isUsingDegrees) {
|
||||
@@ -100,13 +101,24 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (NSDecimalNumber *)doEvaluation:(NSError *__autoreleasing *)error
|
||||
{
|
||||
NSDecimalNumber *value = [self.term evaluate:error];
|
||||
if (!value) {
|
||||
return nil;
|
||||
}
|
||||
return _function(value);
|
||||
NSDecimalNumber *result = _function(value);
|
||||
if ([result isEqualToNumber:[NSDecimalNumber notANumber]]) {
|
||||
result = nil;
|
||||
if (error) {
|
||||
NSString *errorDescription = [NSString stringWithFormat:NSLocalizedString(@"%@ is not defined for the value %@.", nil), self.functionIdentifier, [value descriptionWithLocale:[NSLocale currentLocale]]];
|
||||
*error = [NSError errorWithDomain:MPMathKitErrorDomain
|
||||
code:102
|
||||
userInfo:@{NSLocalizedDescriptionKey: errorDescription}];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user