Model Redesign: Added Reference Frames
Added Inverse Functions UI Redesign Cleaned Code
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
#import "MPTerm.h"
|
||||
#import "MPEvaluationContext.h"
|
||||
#import "MPMathRules.h"
|
||||
|
||||
@interface MPTerm ()
|
||||
|
||||
@@ -66,7 +67,6 @@
|
||||
{
|
||||
return [self initWithBlock:^NSDecimalNumber *{
|
||||
NSDecimalNumber *termValue = [term evaluate];
|
||||
NSLog(@"Factorial of %@ = %f", termValue, tgamma(termValue.doubleValue + 1));
|
||||
return [[NSDecimalNumber alloc] initWithDouble:tgamma(termValue.doubleValue + 1)];
|
||||
}];
|
||||
}
|
||||
@@ -75,6 +75,9 @@
|
||||
{
|
||||
return [self initWithBlock:^NSDecimalNumber *{
|
||||
NSDecimalNumber *termValue = [term evaluate];
|
||||
if ([MPMathRules sharedRules].isUsingDegrees) {
|
||||
termValue = [[termValue decimalNumberByMultiplyingBy:[[NSDecimalNumber alloc] initWithDouble:M_PI]] decimalNumberByDividingBy:[[NSDecimalNumber alloc] initWithInteger:180]];
|
||||
}
|
||||
return [[NSDecimalNumber alloc] initWithDouble:sin(termValue.doubleValue)];
|
||||
}];
|
||||
}
|
||||
@@ -83,6 +86,8 @@
|
||||
{
|
||||
return [self initWithBlock:^NSDecimalNumber *{
|
||||
NSDecimalNumber *termValue = [term evaluate];
|
||||
if ([MPMathRules sharedRules].isUsingDegrees) {
|
||||
termValue = [[termValue decimalNumberByMultiplyingBy:[[NSDecimalNumber alloc] initWithDouble:M_PI]] decimalNumberByDividingBy:[[NSDecimalNumber alloc] initWithInteger:180]]; }
|
||||
return [[NSDecimalNumber alloc] initWithDouble:cos(termValue.doubleValue)];
|
||||
}];
|
||||
}
|
||||
@@ -91,13 +96,54 @@
|
||||
{
|
||||
return [self initWithBlock:^NSDecimalNumber *{
|
||||
NSDecimalNumber *termValue = [term evaluate];
|
||||
if ([MPMathRules sharedRules].isUsingDegrees) {
|
||||
termValue = [[termValue decimalNumberByMultiplyingBy:[[NSDecimalNumber alloc] initWithDouble:M_PI]] decimalNumberByDividingBy:[[NSDecimalNumber alloc] initWithInteger:180]]; }
|
||||
return [[NSDecimalNumber alloc] initWithDouble:tan(termValue.doubleValue)];
|
||||
}];
|
||||
}
|
||||
|
||||
- (instancetype)initWithInverseSinOfTerm:(MPTerm *)term
|
||||
{
|
||||
return [self initWithBlock:^NSDecimalNumber *{
|
||||
NSDecimalNumber *termValue = [term evaluate];
|
||||
NSDecimalNumber *result = [[NSDecimalNumber alloc] initWithDouble:asin(termValue.doubleValue)];
|
||||
if ([MPMathRules sharedRules].isUsingDegrees) {
|
||||
result = [[result decimalNumberByMultiplyingBy:[[NSDecimalNumber alloc] initWithInteger:180]] decimalNumberByDividingBy:[[NSDecimalNumber alloc] initWithDouble:M_PI]];
|
||||
}
|
||||
return result;
|
||||
}];
|
||||
}
|
||||
|
||||
- (instancetype)initWithInverseCosOfTerm:(MPTerm *)term
|
||||
{
|
||||
return [self initWithBlock:^NSDecimalNumber *{
|
||||
NSDecimalNumber *termValue = [term evaluate];
|
||||
NSDecimalNumber *result = [[NSDecimalNumber alloc] initWithDouble:acos(termValue.doubleValue)];
|
||||
if ([MPMathRules sharedRules].isUsingDegrees) {
|
||||
result = [[result decimalNumberByMultiplyingBy:[[NSDecimalNumber alloc] initWithInteger:180]] decimalNumberByDividingBy:[[NSDecimalNumber alloc] initWithDouble:M_PI]];
|
||||
}
|
||||
return result; }];
|
||||
}
|
||||
|
||||
- (instancetype)initWithInverseTanOfTerm:(MPTerm *)term
|
||||
{
|
||||
return [self initWithBlock:^NSDecimalNumber *{
|
||||
NSDecimalNumber *termValue = [term evaluate];
|
||||
NSDecimalNumber *result = [[NSDecimalNumber alloc] initWithDouble:atan(termValue.doubleValue)];
|
||||
if ([MPMathRules sharedRules].isUsingDegrees) {
|
||||
result = [[result decimalNumberByMultiplyingBy:[[NSDecimalNumber alloc] initWithInteger:180]] decimalNumberByDividingBy:[[NSDecimalNumber alloc] initWithDouble:M_PI]];
|
||||
}
|
||||
return result; }];
|
||||
}
|
||||
|
||||
- (NSDecimalNumber *)evaluate
|
||||
{
|
||||
return self.block();
|
||||
@try {
|
||||
return self.block();
|
||||
}
|
||||
@catch (NSException *exception) {
|
||||
return [NSDecimalNumber notANumber];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user