gpt4 book ai didi

iphone - 斯坦福iphone开发-CS193P Assignment 1 - "sin"操作

转载 作者:可可西里 更新时间:2023-11-01 05:31:31 25 4
gpt4 key购买 nike

<分区>

所需的工作之一是在计算器上实现“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

我不知道我的代码有什么问题

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com