所需的工作之一是在计算器上实现“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) 结果=-0.304811
但实际上我在 Windows 中使用计算器,结果是 0.8860254
我不知道我的代码有什么问题