必要な作業の 1 つは、電卓に「sin」ボタンを実装することです。次の 4 つの操作ボタンを追加します。 • sin : スタックの一番上のオペランドの正弦を計算します。
ここに私のコードがあります
- (double)performOperation:(NSString *)operation
{
double result = 0;
if ([operation isEqualToString:@"+"]) {
result = [self popOperand] + [self popOperand];
}else if ([@"*" isEqualToString:operation]) {
result = [self popOperand] * [self popOperand];
}else if ([operation isEqualToString:@"-"]) {
double subtrahend = [self popOperand];
result = [self popOperand] - subtrahend;
}else if ([operation isEqualToString:@"/"]) {
double divisor = [self popOperand];
if(divisor) result = [self popOperand] / divisor;
}else if([operation isEqualToString:@"sin"]){
double operd = [self popOperand];
NSLog(@"operd=%g",operd);
if(operd) result = sin(operd);
}
[self pushOperand:result];
return result;
}
sin(60) を入力してみると、result=-0.304811
しかし、実際にはWindowsで電卓を使用しており、結果は0.8860254です
コードの何が問題なのかわかりません